/// <summary> /// Returns a geoJson map into a heat map. /// </summary> /// <param name="geoJson">The geoJson.</param> /// <param name="values">The values.</param> /// <param name="heatMap">The heat map.</param> /// <param name="heatStops">The heat stops.</param> /// <param name="stroke">The stroke.</param> /// <param name="fill">The fill.</param> /// <param name="thickness">The thickness.</param> /// <param name="projector">The projector.</param> /// <returns></returns> public static IEnumerable<PathShape> AsHeatMapShapes( this GeoJsonFile geoJson, Dictionary<string, double> values, LvcColor[] heatMap, List<Tuple<double, LvcColor>> heatStops, LvcColor stroke, LvcColor fill, float thickness, MapProjector projector) { var paths = new List<PathShape>(); var weightBounds = new Bounds(); foreach (var value in values) { weightBounds.AppendValue(value.Value); } var d = new double[0][][][]; foreach (var feature in geoJson.Features ?? new GeoJsonFeature[0]) { var name = feature.Properties is not null ? feature.Properties["shortName"] : ""; LvcColor? baseColor = values.TryGetValue(name, out var weight) ? HeatFunctions.InterpolateColor((float)weight, weightBounds, heatMap, heatStops) : null; foreach (var geometry in feature.Geometry?.Coordinates ?? d) { foreach (var segment in geometry) { var path = new PathShape { StrokeColor = stroke, FillColor = baseColor ?? fill, StrokeThickness = thickness, IsClosed = true }; var isFirst = true; foreach (var point in segment) { var p = projector.ToMap(point); if (isFirst) { isFirst = false; path.AddCommand(new MoveToPathCommand { X = p[0], Y = p[1] }); continue; } path.AddCommand(new LineSegment { X = p[0], Y = p[1] }); } paths.Add(path); } } } return paths; }
/// <summary> /// Initializes a new instance of <see cref="MapContext{TDrawingContext}"/> class. /// </summary> public MapContext( GeoMap <TDrawingContext> core, IGeoMapView <TDrawingContext> view, CoreMap <TDrawingContext> map, MapProjector projector) { CoreMap = core; MapFile = map; Projector = projector; View = view; }