${REST_MeasureParameters_Tile}

${REST_MeasureParameters_Description}

        private Dictionary<string, string> GetParameters(MeasureParameters parameters)
        {
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            Point2DCollection ps = new Point2DCollection();
            ObservableCollection<Point2DCollection> og = new ObservableCollection<Point2DCollection>();
            if (parameters.Geometry is GeoLine)
            {
                og = (parameters.Geometry as GeoLine).Parts;
            }
            else if (parameters.Geometry is GeoRegion)
            {
                og = (parameters.Geometry as GeoRegion).Parts;
            }
            else
            {
                dictionary.Add("point2Ds", "[]");
                dictionary.Add("unit", parameters.Unit.ToString().ToUpper());
                return dictionary;
            }

            foreach (Point2DCollection g in og)
            {
                for (int i = 0; i < g.Count; i++)
                {
                    ps.Add(g[i]);
                }
            }
            dictionary.Add("point2Ds", JsonHelper.FromPoint2DCollection(ps));
            dictionary.Add("unit", parameters.Unit.ToString().ToUpper());
            return dictionary;
        }
        /// <summary>${REST_MeasureService_method_ProcessAsync_D}</summary>
        /// <param name="parameters">${REST_MeasureService_method_ProcessAsync_param_parameters}</param>
        /// <param name="state">${REST_MeasureService_method_processAsync_param_state}</param>
        public async Task<MeasureResult> ProcessAsync(MeasureParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(ExceptionStrings.ArgumentIsNull);
            }
            if (string.IsNullOrEmpty(this.Url))
            {
                throw new InvalidOperationException(ExceptionStrings.InvalidUrl);
            }

            if (!this.Url.EndsWith("/"))
            {
                this.Url += '/';
            }

            //将错误抛给服务器,让其返回错误结果,出发我们的Failed事件;
            if (parameters.Geometry is GeoLine)
            {
                this.Url += "distance.json?debug=true&_method=GET&";
            }
            else if (parameters.Geometry is GeoRegion)
            {
                this.Url += "area.json?debug=true&_method=GET&";
            }
            else
            {
                this.Url += "distance.json?debug=true&_method=GET&";
            }
            
            var result = await base.SubmitRequest(base.Url, GetParameters(parameters),  true);
            JsonObject jsonObject = JsonObject.Parse(result);
            return MeasureResult.FromJson(jsonObject);
        }
        private async void Measure(SuperMap.WinRT.Core.Geometry geo)
        {
            MeasureParameters parameters = new MeasureParameters { Geometry = geo, Unit = Unit.Kilometer };

            try
            {
                MeasureService measureService = new MeasureService(url);
                var result = await measureService.ProcessAsync(parameters);
                if (result.Distance == -1)
                {
                    await MessageBox.Show(result.Area.ToString() + "平方千米");
                }
                else if (result.Area == -1)
                {
                    await MessageBox.Show(result.Distance.ToString() + "千米");
                }
                else
                {
                    await MessageBox.Show("量算没有结果!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }