/// <summary> /// Initializes a new VectorStyle with default values. /// </summary> /// <remarks> /// Default style values when initialized:<br/> /// <list type="table"> /// <item> /// <term>AreFeaturesSelectable</term> /// <description>True</description> /// </item> /// <item> /// <term>LineStyle</term> /// <description>1px solid black</description> /// </item> /// <item> /// <term>FillStyle</term> /// <description>Solid black</description> /// </item> /// <item> /// <term>Outline</term> /// <description>No Outline</description> /// </item> /// <item> /// <term>Symbol</term> /// <description>Null reference (uses the geometry renderer default)</description> /// </item> /// </list> /// </remarks> public GeometryStyle() { Outline = new StylePen(StyleColor.Black, 1); Line = new StylePen(StyleColor.Black, 1); Fill = new SolidStyleBrush(StyleColor.Black); EnableOutline = false; }
public override IEnumerable <GdiRenderObject> RenderPaths( IEnumerable <Path2D> paths, StylePen outline, StylePen highlightOutline, StylePen selectOutline, RenderState renderState) { SolidStyleBrush transparentBrush = new SolidStyleBrush(StyleColor.Transparent); return(RenderPaths(paths, transparentBrush, transparentBrush, transparentBrush, outline, highlightOutline, selectOutline, renderState)); }
private static void SetColour(Context context, StyleBrush brush) { SolidStyleBrush solid = brush as SolidStyleBrush; if (solid != null) { SetColour(context, brush.Color); } LinearGradientStyleBrush grad = brush as LinearGradientStyleBrush; if (grad != null) { throw new NotImplementedException(); } }
protected override void OnPaint(PaintEventArgs e) { _stopwatch.Reset(); _stopwatch.Start(); SizeF textSize; String text = String.Empty; System.Drawing.Graphics gx = vectorRenderer.Graphics = e.Graphics; // Graphics.FromImage(backBuffer); //e.Graphics; gx.Clear(Color.White); this.dpiX = gx.DpiX; this.dpiY = gx.DpiY; double scale = mainControler.LayerManager.Scale; int layerCount = mainControler.LayerManager.LayerCount; LayerManager lm = mainControler.LayerManager; // TransportLayer // TODO: [9] Ist TransportShapes malen mit QuadTree schneller oder wenn man alles malt? (ab wann ist das wichtig?) lm.generateCurrentVisibleIShapes(d, drawingArea.Width, drawingArea.Height, absoluteZoom); // now draw the image previously created in the given order // ! We assume that there are no gaps (e.g. "1, 2, 4") in the mapping-list Layer layer; RenderProperties rp = new RenderProperties(gx, e.ClipRectangle, d.x, d.y, absoluteZoom, screenChanged, this.drawingArea, scale, mHighlight); for (int i = layerCount - 1; i >= 0; i--) { layer = lm.getLayerFromMapping(i); if (layer.Visible) { if (!(layer.Render(rp))) { this.Invalidate(); return; } } } //IntPtr hBackBuffert = MapPanelBindings.GetRotatedBitmapNT(backBuffer.HBitmap, 0.0f, MakeCOLORREF(255, 255, 255)); //Image newBackImage = Image.FromHbitmap(hBackBuffert); //gx = Graphics.FromImage(newBackImage); //rotateImage(backBuffer, 0); if (screenChanged) { mZoom = false; screenChanged = false; } StringFormat format = new StringFormat(StringFormatFlags.NoWrap); StylePen blackPen = new StylePen(StyleColor.Black, 1.0f); SolidStyleBrush blackBrush = new SolidStyleBrush(StyleColor.Black); #region Transportlayer lm.TransportPolygonLayer.Render(rp); lm.TransportPolylineLayer.Render(rp); lm.TransportPointLayer.Render(rp); #endregion #region GPS-Layer if (config.UseGPS) lm.GPSLayer.Render(rp); #endregion #region Längenanzeige if (config.ShowDistanceLine) { StylePen borderPen = new StylePen(StyleColor.White, 1.0f); // get the scaling factor for other dimensions int multiplikator = (int)(dpiX / 96.0); // get the amount of pixels representing one centimeter int width = Convert.ToInt32(dpiX / 2.54); ; blackPen.Width *= multiplikator; int left = drawingArea.X + 7*multiplikator; int right = left + width; int top = drawingArea.Bottom - 15 * multiplikator; int bottom = top + 7 * multiplikator; double dM = width / mainControler.LayerManager.Scale; if (dM > 1000) // display as kilometers text = String.Format("{0}km", (dM / 1000).ToString("#0.0")); else if (dM > 1) // display as meters text = String.Format("{0}m", Convert.ToInt32(dM).ToString()); else // display as centimeters text = String.Format("{0}cm", Convert.ToInt32(dM * 10).ToString()); textSize = gx.MeasureString(text, font); int x = left + (int)((right - left - textSize.Width) / 2F); int y = top - 4 * multiplikator; // a white background for the text vectorRenderer.FillRectangle(new SolidStyleBrush(StyleColor.White), new Rectangle(x - 1, y - 1, (int)textSize.Width + 2, (int)textSize.Height + 2)); vectorRenderer.DrawLine(blackPen, left, top, left, bottom); vectorRenderer.DrawLine(blackPen, left, bottom, right, bottom); vectorRenderer.DrawLine(blackPen, right, bottom, right, top); // the white outline vectorRenderer.DrawLine(borderPen, left - 1, top, left - 1, bottom); vectorRenderer.DrawLine(borderPen, left + 1, top, left + 1, bottom - 1); vectorRenderer.DrawLine(borderPen, left - 1, top - 1, left + 1, top - 1); vectorRenderer.DrawLine(borderPen, left - 1, bottom + 1, right + 1, bottom + 1); vectorRenderer.DrawLine(borderPen, left + 1, bottom - 1, right - 1, bottom - 1); vectorRenderer.DrawLine(borderPen, right - 1, top, right - 1, bottom - 1); vectorRenderer.DrawLine(borderPen, right + 1, top, right + 1, bottom); vectorRenderer.DrawLine(borderPen, right - 1, top - 1, right + 1, top - 1); // the text vectorRenderer.DrawString(text, font, blackBrush, x, y, format); } #endregion #region Nordpfeil if (config.ShowNorthArrow) { // linke Seite (weiß) vectorRenderer.FillPolygon(new SolidStyleBrush(StyleColor.White), new Point[] { new Point(drawingArea.Right - 20, drawingArea.Bottom -27), new Point(drawingArea.Right - 25, drawingArea.Bottom -5), new Point(drawingArea.Right - 20, drawingArea.Bottom -8)}); vectorRenderer.DrawLines(new StylePen(StyleColor.Black, 1.0f), new Point[] { new Point(drawingArea.Right - 20, drawingArea.Bottom -27), new Point(drawingArea.Right - 25, drawingArea.Bottom -5), new Point(drawingArea.Right - 20, drawingArea.Bottom -8)}); // rechte Seite (schwarz) vectorRenderer.FillPolygon(new SolidStyleBrush(StyleColor.Black), new Point[] { new Point(drawingArea.Right - 20, drawingArea.Bottom -27), new Point(drawingArea.Right - 20, drawingArea.Bottom -8), new Point(drawingArea.Right - 14, drawingArea.Bottom -4), new Point(drawingArea.Right - 20, drawingArea.Bottom -27)}); } #endregion #region Draw backbuffer (Backbuffer is currently disabled!) //e.Graphics.DrawImage(backBuffer, 0, 0); #endregion #region Zoom rectangle if (mZoom) e.Graphics.DrawRectangle(new Pen(Color.Red, 1.0f), zoomRec); #endregion #region SelectedItem / Tracking Info text = String.Empty; if (displayTrackingStatus) { text = _trackingStatus; } else if (selectedTransportShape != null) { text = String.Empty; if (selectedTransportShape as ShpPolyline != null) { text = String.Format("Länge: {0}m", ((ShpPolyline)selectedTransportShape).Length.ToString("#0.00")); } else if (selectedTransportShape as ShpPolygon != null) { ShpPolygon pg = (ShpPolygon)selectedTransportShape; text = String.Format("Umfang: {0}m Fläche: {1} m²", pg.Perimeter.ToString("#0.00"), pg.Area.ToString("#0.00")); } } if (!String.IsNullOrEmpty(text)) { textSize = gx.MeasureString(text, font); m_TextHeight = (int)(textSize.Height + 4); vectorRenderer.FillRectangle(new SolidStyleBrush(StyleColor.White), drawingArea.X, drawingArea.Y, drawingArea.Width, m_TextHeight); vectorRenderer.DrawLine(new StylePen(StyleColor.Blue, 1.0f), drawingArea.X, drawingArea.Y + m_TextHeight, drawingArea.Width, drawingArea.Y + m_TextHeight); vectorRenderer.DrawString(text, font, blackBrush, drawingArea.X + 1, drawingArea.Y + 2, format); } #endregion #region Meta-Define Drawings #if DRAW_INVALIDATEREC foreach (Rectangle r in this.rectangleList) { GKCoord gk = new GKCoord(); gk.r_value = r.X; gk.h_value = r.Y; PointD p = CoordCalculator.calculateDisplayCoords(gk, this.DX, this.DY, mainControler.LayerManager.Scale); gx.DrawRectangle(new Pen(Color.Pink), new Rectangle((int)(p.x),(int)(p.y),r.Width,r.Height)); } #endif #if DRAW_GRID // Grid drawing for (int i = (int)(mainControler.LayerManager.ShapeArray[0].Width * mainControler.LayerManager.Scale); i >= 0; i -= mainControler.LayerManager.ShapeArray[0].PartGrid.Cell_width) { gx.DrawLine(new Pen(Color.Red), (int)d[0] + i, (int)d[1] + margin, (int)d[0] + i, (int)(d[1] + mainControler.LayerManager.ShapeArray[0].Height * mainControler.LayerManager.Scale) - margin); } for (int i = (int)(mainControler.LayerManager.ShapeArray[0].Height * mainControler.LayerManager.Scale); i >= 0; i -= mainControler.LayerManager.ShapeArray[0].PartGrid.Cell_height) { gx.DrawLine(new Pen(Color.Red), (int)d[0] + margin, (int)d[1] + i, (int)(d[0] + mainControler.LayerManager.ShapeArray[0].Width * mainControler.LayerManager.Scale) - margin, (int)d[1] + i); } #endif #if DRAW_QUADTREE mainControler.LayerManager.draw_QuadTree(gx, d); #endif #if DRAW_BOUNDINGBOXES // Draw Boundingboxes List<Rectangle> transportRectangleList = new List<Rectangle>(); // :: Points mainControler.LayerManager.generateBBList(ref transportRectangleList, absoluteZoom); if (transportRectangleList.Count != 0) { Pen temporaryPen = new Pen(Color.Green); for (int i = transportRectangleList.Count - 1; i >= 0; i--) gx.DrawRectangle(temporaryPen, transportRectangleList[i]); } #endif #endregion //Bounding Box of selected IShape //if (selectedTransportShape != null) // vectorRenderer.DrawRectangle(new Pen(Color.Green), selectedTransportShape.getDisplayBoundingBox( // d.x, d.y, config.ExPntLayerPointWidth, scale, 1)); //Boundary rectangle Rectangle rc = this.ClientRectangle; rc.Width--; rc.Height--; //Draw boundary e.Graphics.DrawRectangle(new Pen(Color.Blue), rc); gx.Dispose(); _stopwatch.Stop(); // if the render time is higher than the gps update interval // we have to set the update interval higher if (_stopwatch.ElapsedMilliseconds >= config.GPSUpdateInterval) { // base update interval is render time * 1.2 double newInterval = _stopwatch.ElapsedMilliseconds * 1.2; // since we want full 1000th as interval we round up to the next 1000 try { config.GPSUpdateInterval = Convert.ToUInt32( newInterval + ( 1000 - newInterval % 1000 ) ); } catch { config.GPSUpdateInterval = 5000; } finally { mainControler.OnSettingsChanged(); } } }
public override void FillRectangle(SolidStyleBrush brush, int x, int y, int width, int height) { StyleColor color = brush.Color; _graphics.FillRectangle(new SolidBrush(Color.FromArgb(color.R, color.G, color.B)), x, y, width, height); }
private void SetStyle( GeometryStyle style, string stroke, string strokeWidth, string strokeOpacity, string strokeLinejoin, string strokeLineCap, string strokeDasharray, string strokeDashOffset, string fill, string fillOpacity, string pointSymbolPath ) { if (!String.IsNullOrEmpty(stroke)) { Color color = ColorTranslator.FromHtml(stroke); int opacity = 255; double width = 1; if (!String.IsNullOrEmpty(strokeOpacity)) { opacity = Convert.ToInt32(Math.Round(Convert.ToDouble(strokeOpacity) / 0.0039215, 0)); if (opacity > 255) { opacity = 255; } } if (!String.IsNullOrEmpty(strokeWidth)) { width = Convert.ToDouble(strokeWidth); } StyleBrush brush = new SolidStyleBrush(new StyleColor(Convert.ToInt32(color.B), Convert.ToInt32(color.G), Convert.ToInt32(color.R), opacity)); StylePen pen = new StylePen(brush, width); if (!String.IsNullOrEmpty(strokeLinejoin)) { switch (strokeLinejoin.ToLower()) { case "mitre": pen.LineJoin = StyleLineJoin.Miter; break; case "round": pen.LineJoin = StyleLineJoin.Round; break; case "bevel": pen.LineJoin = StyleLineJoin.Bevel; break; //case "miterclipped": // Not in SLD // pen.LineJoin = StyleLineJoin.MiterClipped; // break; } } if (!String.IsNullOrEmpty(strokeLineCap)) { switch (strokeLineCap.ToLower()) { case "butt": pen.StartCap = StyleLineCap.Flat; pen.EndCap = StyleLineCap.Flat; break; case "round": pen.StartCap = StyleLineCap.Round; pen.EndCap = StyleLineCap.Round; break; case "square": pen.StartCap = StyleLineCap.Square; pen.EndCap = StyleLineCap.Square; break; // N.B. Loads of others not used in SLD } } if (!String.IsNullOrEmpty(strokeDasharray)) { string[] Numbers = strokeDasharray.Split(Char.Parse(" ")); IEnumerable <float> dbls = Processor.Select(Numbers, delegate(string o) { return(float.Parse(o)); }); pen.DashPattern = Enumerable.ToArray(dbls); } if (!String.IsNullOrEmpty(strokeDashOffset)) { float dashOffset; bool success; success = float.TryParse(strokeDashOffset, out dashOffset); if (success) { pen.DashOffset = dashOffset; } } // Set pen style.Line = pen; } if (!String.IsNullOrEmpty(fill)) { Color color = ColorTranslator.FromHtml(fill); int opacity = 255; if (!String.IsNullOrEmpty(fillOpacity)) { opacity = Convert.ToInt32(Math.Round(Convert.ToDouble(fillOpacity) / 0.0039215, 0)); if (opacity > 255) { opacity = 255; } } StyleBrush brush = new SolidStyleBrush(new StyleColor(Convert.ToInt32(color.B), Convert.ToInt32(color.G), Convert.ToInt32(color.R), opacity)); style.Fill = brush; } if (!String.IsNullOrEmpty(pointSymbolPath)) { Uri source = new Uri(pointSymbolPath); if (source.IsFile && File.Exists(source.AbsolutePath)) { Bitmap b = new Bitmap(source.AbsolutePath); MemoryStream ms = new MemoryStream(); b.Save(ms, ImageFormat.Png); ms.Seek(0, SeekOrigin.Begin); style.Symbol = new Symbol2D(ms, new Size2D(12, 10)); } else if (source.IsAbsoluteUri) { ///TODO } } style.Enabled = true; style.EnableOutline = true; }
private static void setupMsSqlSpatial(Map m) { string[] layernames = new[] { "Rivers", "Countries" /*, * "Cities"*/ }; string sridstr = SridMap.DefaultInstance.Process(4326, ""); foreach (string lyrname in layernames) { string tbl = lyrname; AppStateMonitoringFeatureProvider provider = new AppStateMonitoringFeatureProvider( new MsSqlSpatialProvider( new GeometryServices()[sridstr], ConfigurationManager.ConnectionStrings["db"].ConnectionString, "st", "dbo", tbl, "oid", "Geometry") { DefaultProviderProperties = new ProviderPropertiesExpression( new ProviderPropertyExpression[] { new WithNoLockExpression(true) }) }); GeoJsonGeometryStyle style = new GeoJsonGeometryStyle(); switch (tbl) { case "Rivers": { StyleBrush brush = new SolidStyleBrush(StyleColor.Blue); StylePen pen = new StylePen(brush, 1); style.Enabled = true; style.EnableOutline = true; style.Line = pen; style.Fill = brush; break; } case "Countries": { StyleBrush brush = new SolidStyleBrush(new StyleColor(0, 0, 0, 255)); StylePen pen = new StylePen(brush, 2); style.Enabled = true; style.EnableOutline = true; style.Line = pen; style.Fill = new SolidStyleBrush(StyleColor.Green); break; } default: { style = RandomStyle.RandomGeometryStyle(); style.MaxVisible = 100000; break; } } /* include GeoJson styles */ style.IncludeAttributes = false; style.IncludeBBox = true; style.PreProcessGeometries = false; style.CoordinateNumberFormatString = "{0:F}"; GeometryLayer layer = new GeometryLayer(tbl, style, provider); layer.Features.IsSpatiallyIndexed = false; layer.AddProperty(AppStateMonitoringFeatureLayerProperties.AppStateMonitor, provider.Monitor); m.AddLayer(layer); } }