/// <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); // build the filter list mapData.GetFilters(); // this ensures the user sees the results before its saved _missionPlanner.SaveSetting("AAWings.Filters", JsonConvert.SerializeObject(FilteredOut)); await _messagesService.AddMessageAsync($"Map area Loaded {area.Top}, {area.Bottom}, {area.Left}, {area.Right}"); // add all items to cache mapData.Features.ForEach(feature => cache[feature.Id] = feature); // Only get the features that are enabled by default, and have not been filtered out IEnumerable <Feature> features = mapData.Features.Where(feature => feature.IsEnabledByDefault() && feature.IsFilterOutItem(FilteredOut)).ToList(); ProcessFeatures(map, features); }
public static IEnumerable <string> GetFilters(this AAFeatureCollection mapData) { var availableFilters = mapData.Features.SelectMany(x => GetFiltersForFeature(x)).Where(x => x != null).Distinct(); FiltersSeen.AddRange(availableFilters); FiltersSeen = FiltersSeen.Distinct().ToList(); return(availableFilters); }
/// <summary> /// Updates a map with the latest ground / air data /// </summary> /// <param name="map">The map to update</param> /// <returns></returns> private async Task UpdateMapData(IMap map) { if (!IsSignedIn) { return; } try { RectLatLng area = map.GetViewArea(); await _messagesService.AddMessageAsync($"Map area {area.Top}, {area.Bottom}, {area.Left}, {area.Right}"); AAFeatureCollection mapData = await _client.GetMapData(area); // build the filter list mapData.GetFilters(); // this ensures the user sees the results before its saved _settings.MapFilters = FilteredOut; await _messagesService.AddMessageAsync($"Map area Loaded {area.Top}, {area.Bottom}, {area.Left}, {area.Right}"); // add all items to cache MapFeatureCache.Clear(); mapData.Features.ForEach(feature => MapFeatureCache[feature.Id] = feature); // Only get the features that are enabled by default, and have not been filtered out IEnumerable <Feature> features = mapData.Features.Where(feature => feature.IsEnabledByDefault() && feature.IsFilterOutItem(FilteredOut)).ToList(); ProcessFeatures(map, features); } catch (Exception ex) { Console.WriteLine(ex); } }
/// <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(); } } }