Beispiel #1
0
        private static MapInitJson GetMapInitJsonWithProjects(FocusArea focusArea, out bool hasSpatialData, Person currentPerson)
        {
            hasSpatialData = false;

            var layers = new List <LayerGeoJson>();

            if (focusArea.FocusAreaLocation != null)
            {
                hasSpatialData = true;
                layers.Add(new LayerGeoJson($"{FieldDefinition.FocusArea.GetFieldDefinitionLabel()} Location",
                                            focusArea.FocusAreaLocationToFeatureCollection(), "blue", 1,
                                            LayerInitialVisibility.Show));
            }

            var allActiveProjectsAndProposals = focusArea.GetAllActiveProjects(currentPerson).Where(x => x.ProjectStage.ShouldShowOnMap()).ToList();

            var projectsAsSimpleLocations = allActiveProjectsAndProposals.Where(x => x.ProjectLocationSimpleType != ProjectLocationSimpleType.None).ToList();
            var projectSimpleLocationsFeatureCollection = new FeatureCollection();

            var allProjectGrantAllocationExpenditures =
                HttpRequestStorage.DatabaseEntities.ProjectGrantAllocationExpenditures.ToList();
            var projectGrantAllocationExpenditureDict = allProjectGrantAllocationExpenditures.GroupBy(x => x.ProjectID).ToDictionary(x => x.Key, y => y.ToList());

            projectSimpleLocationsFeatureCollection.Features.AddRange(projectsAsSimpleLocations.Select(x =>
            {
                var feature = x.MakePointFeatureWithRelevantProperties(x.ProjectLocationPoint, true, true, FieldDefinition.Organization.GetFieldDefinitionLabel(), FieldDefinition.Organization.GetFieldDefinitionLabelPluralized(), projectGrantAllocationExpenditureDict);
                feature.Properties["FeatureColor"] = "#99b3ff";
                return(feature);
            }).ToList());

            if (projectSimpleLocationsFeatureCollection.Features.Any())
            {
                hasSpatialData = true;
                layers.Add(new LayerGeoJson("Projects", projectSimpleLocationsFeatureCollection, "yellow", 1, LayerInitialVisibility.Show));
            }

            var boundingBox = BoundingBox.MakeBoundingBoxFromLayerGeoJsonList(layers);

            return(new MapInitJson($"focusArea_{focusArea.FocusAreaID}_Map", 10, layers, boundingBox));
        }