/// <summary> /// Adds a GeoJson file to the layer. /// </summary> /// <param name="file"></param> public void AddFile(GeoJsonFile file) { if (file.Features is null) { throw new Exception( $"The {nameof(GeoJsonFile.Features)} property is required to build a {nameof(CoreMap<TDrawingContext>)} instance. " + $"Ensure the property is not null."); } foreach (var feature in file.Features) { if (feature.Geometry is null || feature.Geometry.Coordinates is null) { continue; } var name = (feature.Properties?["name"] ?? "?").ToLowerInvariant(); var shortName = (feature.Properties?["shortName"] ?? "?").ToLowerInvariant(); var setOf = (feature.Properties?["setOf"] ?? "?").ToLowerInvariant(); var definition = new LandDefinition(shortName, name, setOf); var dataCollection = new List <LandData>(); foreach (var geometry in feature.Geometry.Coordinates) { foreach (var segment in geometry) { var data = new LandData(segment); if (data.MaxBounds[0] > definition.MaxBounds[0]) { definition.MaxBounds[0] = data.MaxBounds[0]; } if (data.MinBounds[0] < definition.MinBounds[0]) { definition.MinBounds[0] = data.MinBounds[0]; } if (data.MaxBounds[1] > definition.MaxBounds[1]) { definition.MaxBounds[1] = data.MaxBounds[1]; } if (data.MinBounds[1] < definition.MinBounds[1]) { definition.MinBounds[1] = data.MinBounds[1]; } dataCollection.Add(data); } } definition.Data = dataCollection.OrderByDescending(x => x.BoundsHypotenuse).ToArray(); Lands.Add(shortName, definition); } }
/// <summary> /// Initializes a new instance of <see cref="MapContext{TDrawingContext}"/> class. /// </summary> public MapContext( GeoMap <TDrawingContext> core, IGeoMapView <TDrawingContext> view, GeoJsonFile map, MapProjector projector) { CoreMap = core; MapFile = map; Projector = projector; View = view; }