private void TryRenderText(Symbolizer symbolizer, Feature feature, float emSize, string str, PointF center, SizeF offset, SizeF size, float angle) { var pen = PenCache[symbolizer]; var brush = BrushCache[symbolizer]; var poly = GetCollisionBox(center, offset, size, angle); if (LabelOverlapPreventer.CanPlaceLabel(Config, new LabelDetails(poly, feature))) { //Graphics.DrawLines(Pens.Green, poly.Coordinates.Select(c => new PointF((float)(c.X - xPlus), (float)(c.Y - yPlus))).ToArray()); using (var path = new GraphicsPath()) { path.AddString(str, FontFamily.GenericSansSerif, (int)FontStyle.Bold, emSize, new PointF(-size.Width * 0.5f, -size.Height * 0.5f), new StringFormat()); //path.Transform Graphics.TranslateTransform(center.X, center.Y); Graphics.RotateTransform(angle); Graphics.TranslateTransform(offset.Width, offset.Height); { Graphics.DrawPath(pen, path); Graphics.FillPath(brush, path); } Graphics.ResetTransform(); } } }
/// <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, MapViewport 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); }
public Rule(Symbolizer symbolizer, int?minZoom = null, int?maxZoom = null, FeatureFilter filter = null) { Symbolizer = symbolizer; MinZoom = minZoom; MaxZoom = maxZoom; Filter = filter; }
/// <summary> /// This does not have to be used to work, but provides a default implementation for writing bitmap, /// and will be used by the MapRasterLayer class during file creation. /// </summary> /// <param name="progressHandler"></param> protected void DefaultWriteBitmap(IProgressHandler progressHandler) { if (DataSet.NumRowsInFile * DataSet.NumColumnsInFile > 8000 * 8000) { // For huge images, assume that GDAL or something was needed anyway, // and we would rather avoid having to re-create the pyramids if there is any chance // that the old values will work ok. string pyrFile = Path.ChangeExtension(DataSet.Filename, ".mwi"); BitmapGetter = CreatePyramidImage(pyrFile, progressHandler); OnItemChanged(this); return; } Bitmap bmp = new Bitmap(DataSet.NumColumns, DataSet.NumRows, PixelFormat.Format32bppArgb); if (_symbolizer.DrapeVectorLayers == false) { // Generate the colorscheme, modified by hillshading if that hillshading is used all in one pass DataSet.DrawToBitmap(Symbolizer, bmp, progressHandler); } else { // work backwards. when we get to this layer do the colorscheme. // First, use this raster and its colorscheme to drop the background DataSet.PaintColorSchemeToBitmap(Symbolizer, bmp, progressHandler); // Set up a graphics object with a transformation pre-set so drawing a geographic coordinate // will draw to the correct location on the bitmap Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = SmoothingMode.AntiAlias; Extent extents = DataSet.Extent; Rectangle target = new Rectangle(0, 0, bmp.Width, bmp.Height); ImageProjection ip = new ImageProjection(extents, target); // Cycle through each layer, and as long as it is not this layer, draw the bmp foreach (ILegendItem layer in GetParentItem().LegendItems) { // Temporarily I am only interested in doing this for vector datasets IFeatureLayer fl = layer as IFeatureLayer; if (fl == null) { continue; } fl.DrawSnapShot(g, ip); } if (Symbolizer.ShadedRelief.IsUsed) { // After we have drawn the underlying texture, apply a hillshade if it is requested Symbolizer.PaintShadingToBitmap(bmp, progressHandler); } } InRamImage image = new InRamImage(bmp); image.Bounds = DataSet.Bounds.Copy(); BitmapGetter = image; Symbolizer.Validate(); OnInvalidate(this, new EventArgs()); OnItemChanged(); }
/// <summary> /// Given a size, this will return the native symbolizer that has been adjusted to the specified size. /// </summary> /// <param name="size">The size of the symbol</param> /// <param name="color">The color of the symbol</param> /// <returns>The adjusted symbolizer.</returns> public IFeatureSymbolizer GetSymbolizer(double size, Color color) { IFeatureSymbolizer copy = Symbolizer.Copy(); // preserve aspect ratio, larger dimension specified IPointSymbolizer ps = copy as IPointSymbolizer; if (ps != null) { Size2D s = ps.GetSize(); double ratio = size / Math.Max(s.Width, s.Height); s.Width *= ratio; s.Height *= ratio; ps.SetSize(s); ps.SetFillColor(color); } ILineSymbolizer ls = copy as ILineSymbolizer; if (ls != null) { ls.SetWidth(size); ls.SetFillColor(color); } return(copy); }
public override void Render(Symbolizer symbolizer, Feature feature) { var pen = PenCache[symbolizer]; var points = Project(feature.Geometry.Coordinates); Graphics.DrawLines(pen, points); }
/// <summary> /// Sets the Color of the top symbol in the symbols. /// </summary> /// <param name="color">The color to set the point.</param> public override void SetColor(Color color) { if (Symbolizer == null) { return; } Symbolizer.SetFillColor(color); }
private void paintRule(Graphics g, RenderRule rule, float cur_y) { Symbolizer geosym = rule.geometrysymbolizer; //switch (geosym.sign) //{ // case SymbolizerType.POINT: // pointsymbolizer pointsymbolizer = (pointsymbolizer)geosym; // Brush brush = new SolidBrush(pointsymbolizer.color); // Pen pen = new Pen(brush); // PointF screenPointF = new PointF(position.X, cur_y); // switch (pointsymbolizer.pointstyle) // { // case PointStyle.CIRCLE_FILL: // PointStylePainter.PaintFillCircle(g, brush, screenPointF, pointsymbolizer.size); // break; // case PointStyle.CIRCLE_HOLLOW: // PointStylePainter.PaintHollowCircle(g, pen, screenPointF, pointsymbolizer.size); // break; // case PointStyle.CIRCLE_POINT: // PointStylePainter.PaintCircle_Point(g, pen, brush, screenPointF, pointsymbolizer.size); // break; // case PointStyle.CIRCLE_RECT: // PointStylePainter.PaintCircle_Rect(g, pen, screenPointF, pointsymbolizer.size); // break; // case PointStyle.RECT_FILL: // PointStylePainter.PaintFillRect(g, brush, screenPointF, pointsymbolizer.size); // break; // case PointStyle.RECT_HOLLOW: // PointStylePainter.PaintHollowRect(g, pen, screenPointF, pointsymbolizer.size); // break; // case PointStyle.TRIANGLE: // PointStylePainter.PaintFillTriangle(g, brush, screenPointF, pointsymbolizer.size); // break; // } // brush.Dispose(); // pen.Dispose(); // if(rule.filter!=null) g.DrawString(rule.filter.GetDescription(), SystemFonts.DefaultFont, Brushes.Black, new PointF(position.X + 2 * pointsymbolizer.size * 2 + 10, cur_y)); // cur_y += (2 * pointsymbolizer.size + 5); // break; // case SymbolizerType.LINE: // linesymbolizer lsymbolizer = (linesymbolizer)geosym; // Pen lpen = new Pen(lsymbolizer.color, lsymbolizer.width); // lpen.DashStyle = lsymbolizer.linestyle; // g.DrawLine(lpen, position.X, cur_y, position.X + 30, cur_y); // if (rule.filter != null) g.DrawString(rule.filter.GetDescription(), SystemFonts.DefaultFont, Brushes.Black, new PointF(position.X + 35, cur_y)); // cur_y += (20); // break; // case SymbolizerType.POLYGON: // polygonsymbolizer symbolizer = (polygonsymbolizer)geosym; // Pen ppen = new Pen(symbolizer.strokecolor, symbolizer.strokewidth); // Brush pbrush = new SolidBrush(symbolizer.fillcolor); // g.DrawRectangle(ppen, position.X, cur_y, 30, 15); // g.FillRectangle(pbrush, position.X, cur_y, 30, 15); // if (rule.filter != null) g.DrawString(rule.filter.GetDescription(), SystemFonts.DefaultFont, Brushes.Black, new PointF(position.X + 35, cur_y)); // cur_y += (20); // break; //} }
public override void PreCache(Symbolizer symbolizer) { var pointSymbolizer = (PointSymbolizer)symbolizer; if (!BrushCache.ContainsKey(symbolizer)) { Brush brush = new SolidBrush(pointSymbolizer.Color); BrushCache.Add(symbolizer, brush); } }
/// <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, Map map) { foreach (var geometry in _geometries) { if (geometry != null) { Symbolizer.Render(map, geometry as TGeometry, graphics); } } Symbolizer.Symbolize(graphics, map); }
/// <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, MapViewport 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> /// Returns a random geometry symbolizer /// </summary> public static ISymbolizer CreateRandomSymbolizer() { Symbolizer symbolizer = new Symbolizer(); symbolizer.Fill.Color = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)); symbolizer.Fill.Opacity = rnd.NextDouble(); symbolizer.Stroke.Color = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)); symbolizer.Stroke.Opacity = 1; symbolizer.Stroke.Width = rnd.Next(1, 5); return(symbolizer); }
private void Render(Symbolizer symbolizer, Feature feature) { var type = symbolizer.GetType(); #if DEBUG if (!_renderers.ContainsKey(type)) { throw new Exception("Don't know how to render symbolizer " + type); } #endif _renderers[type].Render(symbolizer, feature); }
/// <summary> /// Returns a shallow copy of this category with the exception of /// the TextSymbolizer, which is duplicated. This uses memberwise /// clone, so sublcasses using this method will return an appropriate /// version. /// </summary> /// <returns>A shallow copy of this object.</returns> public virtual LabelCategory Copy() { var result = MemberwiseClone() as LabelCategory; if (result == null) { return(null); } result.Symbolizer = Symbolizer.Copy(); result.SelectionSymbolizer = SelectionSymbolizer.Copy(); return(result); }
public override void Render(Symbolizer symbolizer, Feature feature) { var pointSymbolizer = (PointSymbolizer)symbolizer; Brush brush = BrushCache[symbolizer]; var p = Project(feature.Geometry.Coordinates)[0]; var diameter = (float)pointSymbolizer.Diameter; var radius = diameter * 0.5f; switch (pointSymbolizer.Shape) { case PointShape.Circle: Graphics.FillEllipse(brush, p.X - radius, p.Y - radius, diameter, diameter); break; case PointShape.Square: Graphics.FillRectangle(brush, p.X - radius, p.Y - radius, diameter, diameter); break; case PointShape.Triangle: Graphics.FillPolygon(brush, new [] { new PointF(p.X - radius, p.Y + diameter / 3), new PointF(p.X, p.Y - radius), new PointF(p.X + radius, p.Y + diameter / 3) }); break; case PointShape.Star: Graphics.FillPolygon(brush, new [] { new PointF(p.X, p.Y - radius), //Out top middle //Right new PointF(p.X + diameter * 0.15f, p.Y - diameter * 0.15f), //in top new PointF(p.X + radius, p.Y - diameter * 0.12f), // out top new PointF(p.X + diameter * 0.25f, p.Y + diameter * 0.13f), //in mid new PointF(p.X + diameter * 0.33f, p.Y + radius), //out bottom new PointF(p.X, p.Y + diameter * 0.3f), //in bottom mid //Left new PointF(p.X - diameter * 0.33f, p.Y + radius), //out bottom new PointF(p.X - diameter * 0.25f, p.Y + diameter * 0.13f), //in mid new PointF(p.X - radius, p.Y - diameter * 0.12f), // out top new PointF(p.X - diameter * 0.15f, p.Y - diameter * 0.15f), //in top }); break; } }
/// <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, Map map) { // Get query envelope var envelope = map.Envelope; // Convert bounding box to datasource's coordinate system if (CoordinateTransformation != null) { #if !DotSpatialProjections if (ReverseCoordinateTransformation != null) { envelope = GeometryTransform.TransformBox(envelope, ReverseCoordinateTransformation.MathTransform); } else { CoordinateTransformation.MathTransform.Invert(); envelope = GeometryTransform.TransformBox(envelope, CoordinateTransformation.MathTransform); CoordinateTransformation.MathTransform.Invert(); } #else envelope = GeometryTransform.TransformBox(envelope, CoordinateTransformation.Target, CoordinateTransformation.Source); #endif } 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); }
public override void PreCache(Symbolizer symbolizer) { var lineSymbolizer = (LineSymbolizer)symbolizer; Pen pen; if (!PenCache.TryGetValue(symbolizer, out pen)) { pen = new Pen(lineSymbolizer.Color, lineSymbolizer.Thickness); if (lineSymbolizer.DashPattern != null) { pen.DashPattern = lineSymbolizer.DashPattern; } PenCache.Add(symbolizer, pen); } }
/// <summary> /// Method called to initialize the rendering process /// </summary> /// <param name="graphics"></param> /// <param name="map"></param> protected virtual void OnRender(Graphics graphics, Map map) { // Get query envelope BoundingBox envelope = map.Envelope; // Convert bounding box to datasource's coordinate system if (CoordinateTransformation != null) { #if !DotSpatialProjections if (ReverseCoordinateTransformation != null) { envelope = GeometryTransform.TransformBox(envelope, ReverseCoordinateTransformation.MathTransform); } else { CoordinateTransformation.MathTransform.Invert(); envelope = GeometryTransform.TransformBox(envelope, CoordinateTransformation.MathTransform); CoordinateTransformation.MathTransform.Invert(); } #else envelope = GeometryTransform.TransformBox(envelope, CoordinateTransformation.Target, CoordinateTransformation.Source); #endif } lock (_dataSource) { bool wasOpen = _dataSource.IsOpen; if (!_dataSource.IsOpen) { _dataSource.Open(); } _geometries = DataSource.GetGeometriesInView(envelope); Console.Out.WriteLine(string.Format("Layer {0}, NumGeometries {1}", LayerName, _geometries.Count)); if (!wasOpen) { _dataSource.Close(); } } _oldSmoothingMode = graphics.SmoothingMode; graphics.SmoothingMode = SmoothingMode; //Setting up the Symbolizer Symbolizer.Begin(graphics, map, 0); }
public override void Render(Symbolizer symbolizer, Feature feature) { var textSymbolizer = (TextSymbolizer)symbolizer; switch (textSymbolizer.Placement) { case TextSymbolizer.PlacementType.Line: RenderLineLabel(textSymbolizer, feature); break; case TextSymbolizer.PlacementType.Point: RenderPointLabel(textSymbolizer, feature); break; default: throw new Exception("Don't know how to render text for " + textSymbolizer.Placement); } }
protected virtual void OnRendering(Graphics graphics, Map map) { //lock (Symbolizer) //{ // Action<Map, TGeometry, Graphics> a = Symbolizer.Render; // Parallel.ForEach(_geometrys, a) //} //Parallel.ForEach() //while (true) //{ // AttributedGeometry<TGeometry> ag = _geometrys.Dequeue(); // Symbolizer.Render(map, ag.Geometry, graphics); //} foreach (Geometry geometry in _geometries) { Symbolizer.Render(map, geometry as TGeometry, graphics); } Symbolizer.Symbolize(graphics, map); }
public override void PreCache(Symbolizer symbolizer) { var polygonSymbolizer = (PolygonSymbolizer)symbolizer; if (!BrushCache.ContainsKey(symbolizer)) { var brush = new SolidBrush(polygonSymbolizer.FillColor); BrushCache.Add(symbolizer, brush); } if (!PenCache.ContainsKey(symbolizer)) { Pen pen = null; if (polygonSymbolizer.LineColor.HasValue && polygonSymbolizer.LineWidth.HasValue) { pen = new Pen(polygonSymbolizer.LineColor.Value, polygonSymbolizer.LineWidth.Value); } PenCache.Add(symbolizer, pen); } }
public override void Render(Symbolizer symbolizer, Feature feature) { var brush = BrushCache[symbolizer]; var pen = PenCache[symbolizer]; var polygon = (IPolygon)feature.Geometry; //TODO: Do we need two version of the code here, or can we just always use a graphics path? if (polygon.Holes.Length > 0) { using (var gp = new GraphicsPath()) { gp.AddPolygon(Project(polygon.ExteriorRing.Coordinates)); for (var i = 0; i < polygon.Holes.Length; i++) { gp.AddPolygon(Project(polygon.Holes[i].Coordinates)); } Graphics.FillPath(brush, gp); if (pen != null) { Graphics.DrawPath(pen, gp); } } } else { var points = Project(polygon.Coordinates); Graphics.FillPolygon(brush, points); if (pen != null) { Graphics.DrawLines(pen, points); } } }
public override void PreCache(Symbolizer symbolizer) { var textSymbolizer = (TextSymbolizer)symbolizer; if (!FontCache.ContainsKey(symbolizer)) { Font font = new Font(FontFamily.GenericSansSerif, textSymbolizer.FontSize, FontStyle.Bold); FontCache.Add(symbolizer, font); } if (!PenCache.ContainsKey(symbolizer)) { var pen = new Pen(textSymbolizer.TextHaloColor, 3); pen.LineJoin = LineJoin.Round; PenCache.Add(symbolizer, pen); } if (!BrushCache.ContainsKey(symbolizer)) { var brush = new SolidBrush(textSymbolizer.TextColor); BrushCache.Add(symbolizer, brush); } }
/// <summary> /// A string representation of this category. /// </summary> /// <returns>String</returns> public override string ToString() { return("Filter: " + FilterExpression + " Color: " + Symbolizer.GetFillColor()); }
public internalSymbolizer(Symbolizer Symbolizer = default) { this.Symbolizer = Symbolizer; }
public error Symbolize(@string mode, MappingSources srcs, ptr <profile.Profile> prof) => s_SymbolizeByRef?.Invoke(ref this, mode, srcs, prof) ?? s_SymbolizeByVal?.Invoke(this, mode, srcs, prof) ?? Symbolizer?.Symbolize(mode, srcs, prof) ?? throw new PanicException(RuntimeErrorPanic.NilPointerDereference);
/// <summary> /// Method called to signal that the layer has been rendered /// </summary> /// <param name="graphics">The graphics object to render upon</param> /// <param name="map">The map</param> protected virtual void OnRendered(Graphics graphics, Map map) { Symbolizer.End(graphics, map); }
/// <summary> /// Method called to signal that the layer has been rendered /// </summary> /// <param name="graphics">The graphics object to render upon</param> /// <param name="map">The map</param> protected virtual void OnRendered(Graphics graphics, MapViewport map) { Symbolizer.End(graphics, map); _geometries = null; }
private void AddProperty(Symbolizer sym, string key, string value) { Dictionary<string, string> props = (Dictionary<string, string>)sym.Tag; if (props == null) props = new Dictionary<string, string>(); if (!props.ContainsKey(key)) props.Add(key, value); sym.Tag = props; }
/// <summary> /// Gets the legend symbol size of the symbolizer for this category. /// </summary> public override Size GetLegendSymbolSize() { return(Symbolizer.GetLegendSymbolSize()); }
protected virtual void OnRendered(Graphics graphics, Map map) { Symbolizer.End(graphics, map); graphics.SmoothingMode = _oldSmoothingMode; }