コード例 #1
0
ファイル: AltitudeAngelService.cs プロジェクト: stonsha/MP
        public void ProcessFeatures(IMap map, IEnumerable <Feature> features)
        {
            IOverlay airOverlay    = map.GetOverlay("AAMapData.Air", true);
            IOverlay groundOverlay = map.GetOverlay("AAMapData.Ground", true);

            groundOverlay.IsVisible = GroundDataDisplay;
            airOverlay.IsVisible    = AirDataDisplay;

            foreach (Feature feature in features)
            {
                IOverlay overlay = string.Equals((string)feature.Properties.Get("category"), "airspace")
                    ? airOverlay
                    : groundOverlay;

                var altitude = ((JObject)feature.Properties.Get("altitudeFloor"))?.ToObject <Altitude>();

                if (altitude == null || altitude.Meters <= 152)
                {
                    if (!GroundDataDisplay)
                    {
                        if (overlay.PolygonExists(feature.Id))
                        {
                            continue;
                        }
                    }
                }
                else
                {
                    if (!AirDataDisplay)
                    {
                        continue;
                    }
                }

                switch (feature.Geometry.Type)
                {
                case GeoJSONObjectType.Point:
                {
                    if (!overlay.PolygonExists(feature.Id))
                    {
                        var pnt = (Point)feature.Geometry;

                        List <PointLatLng> coordinates = new List <PointLatLng>();

                        if (feature.Properties.ContainsKey("radius"))
                        {
                            var rad = double.Parse(feature.Properties["radius"].ToString());

                            for (int i = 0; i <= 360; i += 10)
                            {
                                coordinates.Add(
                                    newpos(new PointLatLng(((GeographicPosition)pnt.Coordinates).Latitude,
                                                           ((GeographicPosition)pnt.Coordinates).Longitude), i, rad));
                            }
                        }

                        ColorInfo colorInfo = feature.ToColorInfo();
                        colorInfo.StrokeColor = 0xFFFF0000;
                        overlay.AddPolygon(feature.Id, coordinates, colorInfo, feature);
                    }
                }
                break;

                case GeoJSONObjectType.MultiPoint:
                    break;

                case GeoJSONObjectType.LineString:
                {
                    if (!overlay.LineExists(feature.Id))
                    {
                        var line = (LineString)feature.Geometry;
                        List <PointLatLng> coordinates = line.Coordinates.OfType <GeographicPosition>()
                                                         .Select(c => new PointLatLng(c.Latitude, c.Longitude))
                                                         .ToList();
                        overlay.AddLine(feature.Id, coordinates, new ColorInfo {
                                StrokeColor = 0xFFFF0000
                            }, feature);
                    }
                }
                break;

                case GeoJSONObjectType.MultiLineString:
                    break;

                case GeoJSONObjectType.Polygon:
                {
                    if (!overlay.PolygonExists(feature.Id))
                    {
                        var poly = (Polygon)feature.Geometry;
                        List <PointLatLng> coordinates =
                            poly.Coordinates[0].Coordinates.OfType <GeographicPosition>()
                            .Select(c => new PointLatLng(c.Latitude, c.Longitude))
                            .ToList();

                        ColorInfo colorInfo = feature.ToColorInfo();
                        colorInfo.StrokeColor = 0xFFFF0000;
                        overlay.AddPolygon(feature.Id, coordinates, colorInfo, feature);
                    }
                }
                break;

                case GeoJSONObjectType.MultiPolygon:
                    if (!overlay.PolygonExists(feature.Id))
                    {
                        foreach (var poly in ((MultiPolygon)feature.Geometry).Coordinates)
                        {
                            List <PointLatLng> coordinates =
                                poly.Coordinates[0].Coordinates.OfType <GeographicPosition>()
                                .Select(c => new PointLatLng(c.Latitude, c.Longitude))
                                .ToList();

                            ColorInfo colorInfo = feature.ToColorInfo();
                            colorInfo.StrokeColor = 0xFFFF0000;
                            overlay.AddPolygon(feature.Id, coordinates, colorInfo, feature);
                        }
                    }
                    break;

                case GeoJSONObjectType.GeometryCollection:
                    break;

                case GeoJSONObjectType.Feature:
                    break;

                case GeoJSONObjectType.FeatureCollection:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///     Updates a map with the latest ground / air data
        /// </summary>
        /// <param name="map">The map to update</param>
        /// <returns></returns>
        public async Task UpdateMapData(IMap map)
        {
            if (!IsSignedIn)
            {
                return;
            }

            RectLatLng area = map.GetViewArea();
            await _messagesService.AddMessageAsync($"Map area {area.Top}, {area.Bottom}, {area.Left}, {area.Right}");

            AAFeatureCollection mapData = await _aaClient.GetMapData(area);

            await _messagesService.AddMessageAsync($"Map area Loaded {area.Top}, {area.Bottom}, {area.Left}, {area.Right}");

            IOverlay airOverlay    = map.GetOverlay("AAMapData.Air", true);
            IOverlay groundOverlay = map.GetOverlay("AAMapData.Ground", true);

            bool groundDataExcluded = mapData.ExcludedData.Any(i => i.SelectToken("detail.name")?.Value <string>() == "Ground Hazards");

            groundOverlay.IsVisible = GroundDataDisplay;
            airOverlay.IsVisible    = AirDataDisplay;

            // Only get the features that have no lower alt or start below 152m. Ignoring datum for now...
            IEnumerable <Feature> features = mapData.Features.Where(feature => feature.IsEnabledByDefault()).ToList();

            foreach (Feature feature in features)
            {
                IOverlay overlay = string.Equals((string)feature.Properties.Get("category"), "airspace")
                    ? airOverlay
                    : groundOverlay;

                var altitude = ((JObject)feature.Properties.Get("altitudeFloor"))?.ToObject <Altitude>();

                if (altitude == null || altitude.Meters <= 152)
                {
                    if (!GroundDataDisplay)
                    {
                        if (overlay.PolygonExists(feature.Id))
                        {
                            continue;
                        }
                    }
                }
                else
                {
                    if (!AirDataDisplay)
                    {
                        continue;
                    }
                }

                switch (feature.Geometry.Type)
                {
                case GeoJSONObjectType.Point:
                    break;

                case GeoJSONObjectType.MultiPoint:
                    break;

                case GeoJSONObjectType.LineString:
                {
                    if (!overlay.LineExists(feature.Id))
                    {
                        var line = (LineString)feature.Geometry;
                        List <PointLatLng> coordinates = line.Coordinates.OfType <GeographicPosition>()
                                                         .Select(c => new PointLatLng(c.Latitude, c.Longitude))
                                                         .ToList();
                        overlay.AddLine(feature.Id, coordinates, new ColorInfo {
                                StrokeColor = 0xFFFF0000
                            }, feature);
                    }
                }
                break;

                case GeoJSONObjectType.MultiLineString:
                    break;

                case GeoJSONObjectType.Polygon:
                {
                    if (!overlay.PolygonExists(feature.Id))
                    {
                        var poly = (Polygon)feature.Geometry;
                        List <PointLatLng> coordinates =
                            poly.Coordinates[0].Coordinates.OfType <GeographicPosition>()
                            .Select(c => new PointLatLng(c.Latitude, c.Longitude))
                            .ToList();

                        ColorInfo colorInfo = feature.ToColorInfo();
                        colorInfo.StrokeColor = 0xFFFF0000;
                        overlay.AddPolygon(feature.Id, coordinates, colorInfo, feature);
                    }
                }
                break;

                case GeoJSONObjectType.MultiPolygon:
                    break;

                case GeoJSONObjectType.GeometryCollection:
                    break;

                case GeoJSONObjectType.Feature:
                    break;

                case GeoJSONObjectType.FeatureCollection:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }