/// <summary> /// Method to render the Point to the <see cref="Graphics"/> object. /// </summary> /// <param name="map">The map object</param> /// <param name="points">Location where to render the Symbol</param> /// <param name="g">The graphics object to use.</param> public void Render(IMapViewPort map, IPuntal points, Graphics g) { foreach (var pointSymbolizer in Items) { pointSymbolizer.Render(map, points, g); } }
private void CalcMapDecorationMetrics(Graphics g, IMapViewPort map) { _cachedSize = InternalSize(g, map); var rect = new Rectangle(Point.Add(GetLocation(map), BorderMargin), _cachedSize); _boundingRectangle = Rectangle.Inflate(rect, 2 * BorderMargin.Width, 2 * BorderMargin.Height); }
/// <summary> /// Method to perform actual rendering /// </summary> /// <param name="map">The map</param> /// <param name="polygon">The polygon to render</param> /// <param name="g">The graphics object to use</param> protected override void OnRenderInternal(IMapViewPort map, IPolygon polygon, Graphics g) { // convert points var pts = /*LimitValues(*/ polygon.TransformToImage(map) /*)*/; // clip if (UseClipping) { pts = VectorRenderer.ClipPolygon(pts, map.Size.Width, map.Size.Height); } // fill the polygon if (Fill != null) { g.FillPolygon(Fill, pts); } // outline the polygon if (Outline != null) { Outline.Render(map, polygon.ExteriorRing, g); foreach (var ls in polygon.InteriorRings) { Outline.Render(map, ls, g); } } }
/// <summary> /// Function to render the actual map decoration /// </summary> /// <param name="g"></param> /// <param name="map"></param> protected override void OnRender(Graphics g, IMapViewPort map) { // Render the rosetta base.OnRender(g, map); var clip = g.ClipBounds; var oldTransform = g.Transform; var newTransform = new Matrix(1f, 0f, 0f, 1f, clip.Left + Size.Width * 0.5f, clip.Top + Size.Height * 0.5f); g.Transform = newTransform; var width = Size.Width; var height = Size.Height; var pts = new[] { new PointF(0f, -0.35f * height), new PointF(0.125f * width, 0.35f * height), new PointF(0f, 0.275f * height), new PointF(-0.125f * width, 0.35f * height), new PointF(0f, -0.35f * height), }; // need to outline the needle if (NeedleOutlineWidth > 0) { g.DrawPolygon(new Pen(OpacityColor(NeedleOutlineColor), NeedleOutlineWidth), pts); } // need to outline the needle g.FillPolygon(new SolidBrush(OpacityColor(NeedleFillColor)), pts); g.Transform = oldTransform; }
void ILayer.Render(Graphics g, IMapViewPort map) { if (_baseLayer is ITileAsyncLayer) { Logger.Warn("ITileAsyncLayer is not a valid layer for GdiImageLayerProxy<T>. -> Skipping"); _baseLayer.Render(g, map); return; } var s = map.Size; using (var img = new Bitmap(s.Width, s.Height, PixelFormat.Format32bppArgb)) { using (var gg = Graphics.FromImage(img)) { _baseLayer.Render(gg, map); } using (var ia = CreateImageAttributes()) { g.DrawImage(img, new Rectangle(0, 0, s.Width, s.Height), 0, 0, s.Width, s.Height, GraphicsUnit.Pixel, ia); } } }
/// <summary> /// Function to transform a linestring to a graphics path for further processing /// </summary> /// <param name="lineString">The Linestring</param> /// <param name="map">The map</param> /// <!--<param name="useClipping">A value indicating whether clipping should be applied or not</param>--> /// <returns>A GraphicsPath</returns> public static GraphicsPath LineStringToPath(ILineString lineString, IMapViewPort map) { var gp = new GraphicsPath(FillMode.Alternate); gp.AddLines(lineString.TransformToImage(map)); return(gp); }
/// <summary> /// Returns the left-top location of the Map decoration /// </summary> /// <param name="map"></param> /// <returns></returns> private Point GetLocation(IMapViewPort map) { var clipRect = map.Size; var objectSize = Size; var offsetX = Location.X; var offsetY = Location.Y; var anchors = (MapDecorationAnchorFlags)Anchor; switch (anchors & MapDecorationAnchorFlags.Horizontal) { case MapDecorationAnchorFlags.Right: offsetX = clipRect.Width - (Location.X + objectSize.Width); break; case MapDecorationAnchorFlags.HorizontalCenter: offsetX = (clipRect.Width - (Location.X + objectSize.Width)) / 2; break; } switch (anchors & MapDecorationAnchorFlags.Vertical) { case MapDecorationAnchorFlags.Bottom: offsetY = clipRect.Height - (Location.Y + objectSize.Height); break; case MapDecorationAnchorFlags.HorizontalCenter: offsetY = (clipRect.Height - (Location.Y + objectSize.Height)) / 2; break; } return(new Point(offsetX, offsetY)); }
/// <summary> /// Method called to initialize the rendering process /// </summary> /// <param name="graphics">The graphics object to render upon</param> /// <param name="map">The map</param> protected virtual void OnRender(Graphics graphics, IMapViewPort map) { // Get query envelope var envelope = ToSource(map.Envelope); lock (_dataSource) { var wasOpen = _dataSource.IsOpen; if (!_dataSource.IsOpen) { _dataSource.Open(); } _geometries = DataSource.GetGeometriesInView(envelope); if (logger.IsDebugEnabled) { logger.DebugFormat("Layer {0}, NumGeometries {1}", LayerName, _geometries.Count); } if (!wasOpen) { _dataSource.Close(); } } //Setting up the Symbolizer Symbolizer.Begin(graphics, map, 0); }
/// <summary> /// Aplly style /// </summary> /// <param name="g"></param> /// <param name="map"></param> /// <param name="style"></param> /// <param name="action"></param> protected static void ApplyStyle(Graphics g, IMapViewPort map, IStyle style, Action <Graphics, IMapViewPort, VectorStyle> action) { if (style == null) { return; } if (!style.Enabled) { return; } var scale = map.MapScale; var zoom = map.Zoom; var compare = style.VisibilityUnits == VisibilityUnits.ZoomLevel ? zoom : scale; if (style.MinVisible > compare || compare > style.MaxVisible) { return; } var groupStyle = style as GroupStyle; var vectorStyle = style as VectorStyle; if (groupStyle != null) { for (var i = 0; i < groupStyle.Count; i++) { ApplyStyle(g, map, style, action); } } else if (vectorStyle != null) { action(g, map, vectorStyle); } }
//private static void WarpedLabel(MultiLineString line, ref BaseLabel baseLabel, Map map) //{ // var path = MultiLineStringToPath(line, map, true); // var pathLabel = new PathLabel(baseLabel.Text, path, 0f, baseLabel.Priority, new LabelBox(path.GetBounds()), baseLabel.Style); // baseLabel = pathLabel; //} //private static void WarpedLabel(LineString line, ref BaseLabel baseLabel, Map map) //{ // var path = LineStringToPath(line, map, false); // var pathLabel = new PathLabel(baseLabel.Text, path, 0f, baseLabel.Priority, new LabelBox(path.GetBounds()), baseLabel.Style); // baseLabel = pathLabel; //} /// <summary> /// Function to transform a linestring to a graphics path for further processing /// </summary> /// <param name="lineString">The Linestring</param> /// <param name="map">The map</param> /// <!--<param name="useClipping">A value indicating whether clipping should be applied or not</param>--> /// <returns>A GraphicsPath</returns> public static GraphicsPath LineStringToPath(ILineString lineString, IMapViewPort map /*, bool useClipping*/) { var gp = new GraphicsPath(FillMode.Alternate); //if (!useClipping) gp.AddLines(lineString.TransformToImage(map)); //else //{ // var bb = map.Envelope; // var cohenSutherlandLineClipping = new CohenSutherlandLineClipping(bb.Left, bb.Bottom, bb.Right, bb.Top); // var clippedLineStrings = cohenSutherlandLineClipping.ClipLineString(lineString); // foreach (var clippedLineString in clippedLineStrings.LineStrings) // { // var s = clippedLineString.StartPoint; // var e = clippedLineString.EndPoint; // var dx = e.X - s.X; // //var dy = e.Y - s.Y; // LineString revcls = null; // if (dx < 0) // revcls = ReverseLineString(clippedLineString); // gp.StartFigure(); // gp.AddLines(revcls == null ? clippedLineString.TransformToImage(map) : revcls.TransformToImage(map)); // } //} return(gp); }
/// <summary> /// Renders the layer to a graphics object /// </summary> /// <param name="g">Graphics object reference</param> /// <param name="map">Map which is rendered</param> /// public override void Render(Graphics g, IMapViewPort map) { if (map.Center == null) { throw (new ApplicationException("Cannot render map. View center not specified")); } var oldSmoothingMode = g.SmoothingMode; g.SmoothingMode = SmoothingMode; var envelope = ToSource(map.Envelope); //View to render if (DataSource == null) { throw (new ApplicationException("DataSource property not set on layer '" + LayerName + "'")); } //If thematics is enabled, we use a slighty different rendering approach if (Theme != null) { RenderInternal(g, map, envelope, Theme); } else { RenderInternal(g, map, envelope); } g.SmoothingMode = oldSmoothingMode; base.Render(g, map); }
public override void Render(Graphics g, IMapViewPort map) { // Map setup correctly if (map.Center == null) { throw (new ApplicationException("Cannot render map. View center not specified")); } //Data source set? if (DataSource == null) { throw (new ApplicationException("DataSource property not set on layer '" + LayerName + "'")); } // Symbolizer set if (Symbolizer == null) { throw new ApplicationException("Symbolizer property not set on layer '" + LayerName + "'"); } // Initialize Rendering OnRender(g, map); // Render OnRendering(g, map); // Terminate Rendering OnRendered(g, map); }
/// <summary> /// Function to render the symbol /// </summary> /// <param name="map">The map</param> /// <param name="point">The point to symbolize</param> /// <param name="g">The graphics object</param> protected void RenderPoint(IMapViewPort map, Coordinate point, Graphics g) { if (point == null) { return; } PointF pp = Transform.WorldtoMap(point, map); pp = PointF.Add(pp, GetOffset()); if (Rotation != 0f && !Single.IsNaN(Rotation)) { Matrix startingTransform = g.Transform.Clone(); Matrix transform = g.Transform; PointF rotationCenter = pp; transform.RotateAt(Rotation, rotationCenter); g.Transform = transform; OnRenderInternal(pp, g); g.Transform = startingTransform; } else { OnRenderInternal(pp, g); } }
/// <summary> /// Function to render the geometry /// </summary> /// <param name="map">The map object, mainly needed for transformation purposes.</param> /// <param name="geometry">The geometry to symbolize.</param> /// <param name="graphics">The graphics object to use.</param> public void Render(IMapViewPort map, IGeometry geometry, Graphics graphics) { switch (geometry.OgcGeometryType) { case OgcGeometryType.Point: case OgcGeometryType.MultiPoint: _pointSymbolizer.Render(map, (IPuntal)geometry, graphics); return; case OgcGeometryType.LineString: case OgcGeometryType.MultiLineString: _lineSymbolizer.Render(map, (ILineal)geometry, graphics); return; case OgcGeometryType.Polygon: case OgcGeometryType.MultiPolygon: _polygonSymbolizer.Render(map, (IPolygonal)geometry, graphics); return; case OgcGeometryType.GeometryCollection: foreach (var g in ((IGeometryCollection)geometry)) { Render(map, g, graphics); } return; } throw new Exception("Unknown geometry type"); }
/// <summary> /// Method to indicate that the symbolizers work is done and it can clean up. /// </summary> public override void End(Graphics g, IMapViewPort map) { if (_graphicsPaths.Count > 0) { _graphicsPaths.Clear(); } base.End(g, map); }
/// <summary> /// Loads the datas depending of the view. /// </summary> /// <param name="view"></param> public override void LoadDatas(IMapViewPort view) { foreach (var layer in Layers.OfType <Layer>().Where(l => l.IsLayerVisible(view))) { layer.LoadDatas(view); } //base.LoadDatas(map); }
private int _marginRight = DefaultMarginX; //right margin for the scale bar #region MapDecoration overrides /// <summary> /// Function to compute the required size for rendering the map decoration object /// <para>This is just the size of the decoration object, border settings are excluded</para> /// </summary> /// <param name="g">The graphics object</param> /// <param name="map">The map</param> /// <returns>The size of the map decoration</returns> protected override Size InternalSize(Graphics g, IMapViewPort map) { CalcScale((int)g.DpiX); double width = MarginLeft + MarginRight + DefaultWidth; double height = 2 * BarWidth + 2 * _font.Height; return(new Size((int)width, (int)height)); }
/// <summary> /// Method to perform preparatory work for symbilizing. /// </summary> /// <param name="g">The graphics object to symbolize upon</param> /// <param name="map">The map</param> /// <param name="aproximateNumberOfGeometries">An approximate number of geometries to symbolize</param> public virtual void Begin(Graphics g, IMapViewPort map, int aproximateNumberOfGeometries) { _oldSmootingMode = g.SmoothingMode; _oldPixelOffsetMode = g.PixelOffsetMode; g.SmoothingMode = SmoothingMode; g.PixelOffsetMode = PixelOffsetMode; }
/// <summary> /// Renders the layer /// </summary> /// <param name="g">Graphics object reference</param> /// <param name="map">Map which is rendered</param> public override void Render(Graphics g, IMapViewPort map) { if (map.Center == null) { throw (new ApplicationException("Cannot render map. View center not specified")); } if (_image == null) { throw new Exception("Image not set"); } // View to render var mapView = map.Envelope; // Layer view var lyrView = _envelope; // Get the view intersection var vi = mapView.Intersection(lyrView); if (!vi.IsNull) { // Image part // ReSharper disable InconsistentNaming var imgLT = Clip(_worldFile.ToRaster(new Coordinate(vi.MinX, vi.MaxY))); var imgRB = Clip(_worldFile.ToRaster(new Coordinate(vi.MaxX, vi.MinY))); var imgRect = new Rectangle(imgLT, PointDiff(imgLT, imgRB, 1)); // Map Part var mapLT = Point.Truncate(map.WorldToImage(new Coordinate(vi.MinX, vi.MaxY))); var mapRB = Point.Ceiling(map.WorldToImage(new Coordinate(vi.MaxX, vi.MinY))); var mapRect = new Rectangle(mapLT, PointDiff(mapLT, mapRB, 1)); // ReSharper restore InconsistentNaming // Set the interpolation mode var tmpInterpolationMode = g.InterpolationMode; g.InterpolationMode = InterpolationMode; // Render the image using (var ia = new ImageAttributes()) { ia.SetColorMatrix(new ColorMatrix { Matrix44 = 1 - Transparency }, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); g.DrawImage(_image, mapRect, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height, GraphicsUnit.Pixel, ia); } // reset the interpolation mode g.InterpolationMode = tmpInterpolationMode; } base.Render(g, map); }
/// <summary> /// Renders the layer /// </summary> /// <param name="g">Graphics object reference</param> /// <param name="map">Map which is rendered</param> public override void Render(Graphics g, IMapViewPort map) { var layers = Layers.ToArray(); foreach (var layer in Layers.Where(l => l.IsLayerVisible(map))) { LayerCollectionRenderer.RenderLayer(layer, g, map); } }
/// <summary> /// Transforms an array of <see cref="Coordinate"/>s to an array of <see cref="PointF"/>s. /// </summary> /// <param name="vertices">The array of coordinates</param> /// <param name="map">The map that defines the affine coordinate transformation</param> /// <returns>The array of <see cref="PointF"/>s</returns> private static PointF[] TransformToImage(Coordinate[] vertices, IMapViewPort map) { var v = new PointF[vertices.Length]; for (var i = 0; i < vertices.Length; i++) { v[i] = Transform.WorldtoMap(vertices[i], map); } return(v); }
/// <summary> /// Transforms from image coordinates to world coordinate system (WCS). /// NOTE: This method DOES NOT take the MapTransform property into account (use <see cref="Map.ImageToWorld(System.Drawing.PointF,bool)"/> instead) /// </summary> /// <param name="p">Point in image coordinate system</param> /// <param name="map">Map reference</param> /// <returns>Point in WCS</returns> public static Coordinate MapToWorld(PointF p, IMapViewPort map) { if (map.Center.IsEmpty() || double.IsNaN(map.MapHeight)) { return(new Coordinate(0, 0)); } var ul = new Coordinate(map.Center.X - map.Zoom * .5, map.Center.Y + map.MapHeight * .5); return(new Coordinate(ul.X + p.X * map.PixelWidth, ul.Y - p.Y * map.PixelHeight)); }
/// <summary> /// Renders the map. /// </summary> /// <param name="context">The rendering context.</param> /// <param name="map"></param> public override void Render(object context, IMapViewPort map) { var g = context as Graphics; if (g == null) { throw new ArgumentNullException(nameof(g), "Cannot render map with null graphics object!"); } if (Map == null) { throw new InvalidOperationException("Map cannot be null."); } OnMapRendering(); if (!map.Size.IsEmpty) { g.Transform = Map.MapTransform; g.PageUnit = GraphicsUnit.Pixel; g.Clear(Map.BackColor); //BackgroundLayer if (Map.BackgroundLayer != null) { Render(context, map, Map.BackgroundLayer); } //Masque if (Map.BackgroundMaskBrush != null) { g.FillRectangle(Map.BackgroundMaskBrush, g.ClipBounds); } //Layers if (Map.Layers != null) { Render(context, map, Map.Layers); } //Décorations if (Map.Decorations != null) { // Render all map decorations foreach (var mapDecoration in Map.Decorations) { mapDecoration.Render(g, map); } } } OnMapRendered(); }
/// <summary> /// Method called to render the layer /// </summary> /// <param name="graphics">The graphics object to render upon</param> /// <param name="map">The map</param> protected virtual void OnRendering(Graphics graphics, IMapViewPort map) { foreach (var geometry in _geometries) { if (geometry != null) { var tmpGeometry = ToTarget(geometry); Symbolizer.Render(map, tmpGeometry as TGeometry, graphics); } } Symbolizer.Symbolize(graphics, map); }
/// <summary> /// Method to render this layer to the map, applying <paramref name="theme"/>. /// </summary> /// <param name="g">The graphics object</param> /// <param name="map">The map object</param> /// <param name="envelope">The envelope to render</param> /// <param name="theme">The theme to apply</param> protected virtual void RenderInternal(Graphics g, IMapViewPort map, Envelope envelope, ITheme theme) { var useCache = _dataCache != null; var ds = _dataCache; if (ds == null || ds.Tables.Count == 0) { base.Render(g, map); return; } foreach (var features in ds.Tables) { //Linestring outlines is drawn by drawing the layer once with a thicker line //before drawing the "inline" on top. if (Style.EnableOutline) { for (var i = 0; i < features.Count; i++) { var feature = features[i]; using (var outlineStyle = theme.GetStyle(feature) as VectorStyle) { ApplyStyle(g, map, outlineStyle, (graphics, map1, style) => { //Draw background of all line-outlines first var lineString = feature.Geometry as ILineString; if (lineString != null) { VectorRenderer.DrawLineString(g, lineString, style.Outline, map, style.LineOffset); } else if (feature.Geometry is IMultiLineString) { VectorRenderer.DrawMultiLineString(g, (IMultiLineString)feature.Geometry, style.Outline, map, style.LineOffset); } } ); } } } for (var i = 0; i < features.Count; i++) { var feature = features[i]; var style = theme.GetStyle(feature); ApplyStyle(g, map, style, (graphics, map1, vstyle) => RenderGeometry(g, map, feature.Geometry, vstyle)); } } }
/// <summary> /// Load datas. /// </summary> /// <param name="view"></param> public override void LoadDatas(IMapViewPort view) { NewEnvelope = view.Envelope; if (IsFetching) { NeedsUpdate = true; return; } StartFetchTimer?.Dispose(); StartFetchTimer = new Timer(StartFetchTimerElapsed, null, FetchingPostponedInMilliseconds, int.MaxValue); }
/// <summary> /// Loads the datas. /// </summary> /// <param name="view"></param> public override void LoadDatas(IMapViewPort view) { //AbortFetch(); if (view.Size.IsEmpty || view.Size.Width <= 0 || view.Size.Height <= 0) { return; } var bbox = view.Envelope; var extent = new Extent(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY); _tileFetcher.ViewChanged(extent, view.PixelSize); }
private void Symbolize(Graphics graphics, IMapViewPort map, List <GraphicsPath> paths) { if (_lineSymbolizeHandlers.Count == 0) { _fallback.SymbolizePaths(graphics, paths); } else { foreach (var lineSymbolizeHandler in _lineSymbolizeHandlers) { lineSymbolizeHandler.SymbolizePaths(graphics, paths); } } }
/// <summary> /// Function to render the geometry /// </summary> /// <param name="map">The map object, mainly needed for transformation purposes.</param> /// <param name="geometry">The geometry to symbolize.</param> /// <param name="graphics">The graphics object to use.</param> public void Render(IMapViewPort map, IPuntal geometry, Graphics graphics) { var mp = geometry as IMultiPoint; if (mp != null) { foreach (var point in mp.Coordinates) { RenderPoint(map, point, graphics); } return; } RenderPoint(map, ((IPoint)geometry).Coordinate, graphics); }
/// <summary> /// Function to render the geometry /// </summary> /// <param name="map">The map object, mainly needed for transformation purposes.</param> /// <param name="geometry">The geometry to symbolize.</param> /// <param name="graphics">The graphics object to use.</param> public void Render(IMapViewPort map, IPolygonal geometry, Graphics graphics) { var mp = geometry as IMultiPolygon; if (mp != null) { for (var i = 0; i < mp.NumGeometries; i++) { var poly = (IPolygon)mp[0]; OnRenderInternal(map, poly, graphics); } return; } OnRenderInternal(map, (IPolygon)geometry, graphics); }