Exemplo n.º 1
0
        public async Task <Response <List <MapFeatureVm> > > GetById(
            string id,
            CancellationToken cts = default)
        {
            try
            {
                var proxy = _proxyFactory.GetAppContextDataProxy <GeoFeatureGroup>();

                var group = await proxy.GetAsync(id, cancellationToken : cts);

                if (group == null)
                {
                    throw ExceptionBuilder.GetInstance(BlazorNinjaStatusCode.NotFound, "item");
                }

                var features = new List <MapFeatureVm>();

                if (group.HasLand)
                {
                    var vm = new MapFeatureVm
                    {
                        Id      = group.LandFeature.Id,
                        GroupId = group.Id,
                        Type    = FeatureTypes.Land,
                        Polygon = group.LandFeature.Polygon
                    };
                    features.Add(vm);
                }

                foreach (var feature in group.Features)
                {
                    var vm = new MapFeatureVm
                    {
                        Id      = feature.Id,
                        GroupId = group.Id,
                        Type    = FeatureTypes.Building,
                        Polygon = feature.Polygon
                    };
                    features.Add(vm);
                }


                return(new Response <List <MapFeatureVm> >(features));
            }
            catch (Exception ex)
            {
                return(new Response <List <MapFeatureVm> >
                {
                    Outcome = Outcomes.Failure,
                    Message = ex.Message
                });
            }
        }
Exemplo n.º 2
0
        public async Task <Response <List <MapFeatureVm> > > Get(
            [FromQuery(Name = "polygon")] string json,
            CancellationToken cts = default)
        {
            try
            {
                var proxy = _proxyFactory.GetAppContextDataProxy <GeoFeatureGroup>();

                var polygon = JsonConvert.DeserializeObject <GeoPolygon>(json);

                var filter = Builders <GeoFeatureGroup> .Filter.GeoIntersects("QueryPolygon", polygon.Coordinates);

                var page = await proxy.GetPageAsync(filter, 0, int.MaxValue, cancellationToken : cts);

                var features = new List <MapFeatureVm>();
                foreach (var group in page.Items)
                {
                    if (group.HasLand)
                    {
                        var vm = new MapFeatureVm
                        {
                            Id      = group.LandFeature.Id,
                            GroupId = group.Id,
                            Type    = FeatureTypes.Land,
                            Polygon = group.LandFeature.Polygon
                        };
                        features.Add(vm);
                    }

                    foreach (var feature in group.Features)
                    {
                        var vm = new MapFeatureVm
                        {
                            Id      = feature.Id,
                            GroupId = group.Id,
                            Type    = FeatureTypes.Building,
                            Polygon = feature.Polygon
                        };
                        features.Add(vm);
                    }
                }

                return(new Response <List <MapFeatureVm> >(features));
            }
            catch (Exception ex)
            {
                return(new Response <List <MapFeatureVm> >
                {
                    Outcome = Outcomes.Failure,
                    Message = ex.Message
                });
            }
        }