Beispiel #1
0
        public override async Task <SearchResult> Execute()
        {
            if (string.IsNullOrEmpty(Geometry))
            {
                return(null);
            }

            var identify = new Identify.RequestContract {
                GeometryType = GeometryType.esriGeometryPoint
            };
            var point = CommandExecutor.ExecuteCommand(new DecodeInputGeomertryCommand(Geometry));

            if (point is null && !string.IsNullOrEmpty(Geometry))
            {
                ErrorMessage = "GEOMETRY COORDINATES APPEAR TO BE INVALID.";
                return(null);
            }

            if (point.SpatialReference is not null)
            {
                Wkid = point.SpatialReference.Wkid;
            }

            HttpResponseMessage httpResponse;

            if (!LocalProjection.Contains(Wkid))
            {
                var coordinates = Enumerable.Empty <double>();
                if (point is null)
                {
                    return(null);
                }

                coordinates = new[] { point.X, point.Y };

                var projectResponse = CommandExecutor.ExecuteCommand(
                    new ReprojectPointsCommand(
                        new ReprojectPointsCommand.PointProjectQueryArgs(Wkid, 3857, coordinates.ToList())));

                if (!projectResponse.IsSuccessful)
                {
                    return(null);
                }

                identify.Geometry = string.Join("&", projectResponse.Geometries.Select(geo => $"{geo.X},{geo.Y}"));
            }
            else
            {
                identify.Geometry = $"{point.X},{point.Y}";
            }

            var requestUri = $"{BaseUrl}{identify}";

            try
            {
                httpResponse = await App.HttpClient.GetAsync(requestUri);
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;

                return(null);
            }

            Identify.ResponseContract response = null;
            try
            {
                response = await httpResponse.Content.ReadAsAsync <Identify.ResponseContract>();
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }

            var attributes = new Dictionary <string, object>();
            var values     = ReturnValues.Split(',').Select(x => x.ToLowerInvariant());

            if (values.Contains("feet"))
            {
                attributes["feet"] = response.Feet;
            }

            if (values.Contains("value"))
            {
                attributes["value"] = response.Value;
            }

            if (values.Contains("meters"))
            {
                attributes["meters"] = response.Value;
            }

            return(new SearchResult
            {
                Attributes = attributes
            });
        }