/// <summary> /// Create a <see cref="Map"/> representing this map object. /// </summary> /// <param name="map">A map to be exported/rendered.</param> public static Map ToSharpMap(this MapTag map) { Map result = InitMap(); GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326); List <IGeometry> locations = map.Markers.Select(c => gf.CreatePoint(new Coordinate(c.Longitude, c.Latitude))).ToList <IGeometry>(); VectorLayer markerLayer = new VectorLayer("Markers"); markerLayer.Style.Symbol = APSIM.Shared.Documentation.Image.LoadFromResource("Marker.png"); markerLayer.Style.SymbolOffset = new PointF(0, -16); // Offset so the point is marked by the tip of the symbol, not its center markerLayer.DataSource = new GeometryProvider(locations); markerLayer.CoordinateTransformation = latLonToMetres; result.Layers.Add(markerLayer); // Compat check for old zoom units. Should really have used a converter... double zoom = map.Zoom - 1; if (zoom >= 60) { zoom = 0; } result.Zoom = result.MaximumZoom / Math.Pow(zoomStepFactor, zoom); Coordinate location = latLonToMetres.MathTransform.Transform(new Coordinate(map.Center.Longitude, map.Center.Latitude)); result.Center = location; return(result); }
/// <summary> /// Render the map as a <see cref="System.Drawing.Image"/> of the specified size. /// </summary> /// <param name="map">Map tag to be rendered.</param> /// <param name="width">Width of the map in px.</param> /// <param name="renderer">PDF renderer to use for rendering the tag.</param> public static Image ToImage(this MapTag map, int width) { Map exported = map.ToSharpMap(); exported.Size = new Size(width, width); return(exported.GetMap()); }
/// <summary> /// Render the map as a <see cref="System.Drawing.Image"/>. /// </summary> /// <param name="map">Map tag to be rendered.</param> /// <param name="renderer">PDF renderer to use for rendering the tag.</param> public static Image ToImage(this MapTag map) { return(map.ToSharpMap().GetMap()); }