public void DrawMarkers(IEnumerable<Land> landPieces) { if (landPieces == null) return; ClearGraphics(); if (Current.Instance.MapControl.Viewport.Resolution > 50) { return; } foreach (var land in landPieces.Where(x => x.DemandAuthorities)) { var sphericalMid = SphericalMercator.FromLonLat(land.Longitude, land.Latitude); var feature = new Feature { Geometry = new Mapsui.Geometries.Point(sphericalMid.x, sphericalMid.y), }; var offset = new Offset(); offset.X = 100; double scale = 19.109256744384766 / Current.Instance.MapControl.Viewport.Resolution; //var symbolStyle = new SymbolStyle { Symbol = GetSymbol("demandar.png"), SymbolType = SymbolType.Rectangle, SymbolOffset = offset, SymbolScale = scale }; var symbolStyle = new SymbolStyle { Symbol = GetSymbol("demandar.png"), SymbolScale = 1 }; feature.Styles.Add(symbolStyle); source.Features.Add(feature); } Current.Instance.MapControl.OnViewChanged(true); }
/// <summary> /// Renders a label to the map. /// </summary> /// <param name="graphics">Graphics reference</param> /// <param name="labelPoint">Label placement</param> /// <param name="offset">Offset of label in screen coordinates</param> /// <param name="font">Font used for rendering</param> /// <param name="forecolor">Font forecolor</param> /// <param name="backcolor">Background color</param> /// <param name="halo">Color of halo</param> /// <param name="rotation">Text rotation in degrees</param> /// <param name="text">Text to render</param> /// <param name="viewport"></param> public static void DrawLabel(Graphics graphics, Point labelPoint, Offset offset, Styles.Font font, Styles.Color forecolor, Styles.Brush backcolor, Styles.Pen halo, double rotation, string text, IViewport viewport, StyleContext context) { SizeF fontSize = graphics.MeasureString(text, font.ToGdi(context)); //Calculate the size of the text labelPoint.X += offset.X; labelPoint.Y += offset.Y; //add label offset if (Math.Abs(rotation) > Constants.Epsilon && !double.IsNaN(rotation)) { graphics.TranslateTransform((float)labelPoint.X, (float)labelPoint.Y); graphics.RotateTransform((float)rotation); graphics.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2); if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent) graphics.FillRectangle(backcolor.ToGdi(context), 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f); var path = new GraphicsPath(); path.AddString(text, new FontFamily(font.FontFamily), (int)font.ToGdi(context).Style, font.ToGdi(context).Size, new System.Drawing.Point(0, 0), null); if (halo != null) graphics.DrawPath(halo.ToGdi(context), path); graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path); //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0); } else { if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent) graphics.FillRectangle(backcolor.ToGdi(context), (float)labelPoint.X, (float)labelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f); var path = new GraphicsPath(); //Arial hack path.AddString(text, new FontFamily("Arial"), (int)font.ToGdi(context).Style, (float)font.Size, new System.Drawing.Point((int)labelPoint.X, (int)labelPoint.Y), null); if (halo != null) graphics.DrawPath(halo.ToGdi(context), path); graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path); //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y); } }
public SymbolStyle() { SymbolOffset = new Offset(); SymbolScale = 1f; Opacity = 1f; BitmapId = -1; }
public SymbolStyle() { SymbolOffset = new Offset(); SymbolScale = 1f; Opacity = 1f; BitmapId = -1; Width = DefaultWidth; Height = DefaultHeight; }
public LabelStyle() { Font = new Font { FontFamily = "Verdana", Size = 12 }; Offset = new Offset { X = 0, Y = 0 }; CollisionDetection = false; ForeColor = Color.Black; BackColor = new Brush { Color = Color.White }; HorizontalAlignment = HorizontalAlignmentEnum.Center; VerticalAlignment = VerticalAlignmentEnum.Center; }
public LabelStyle(LabelStyle labelStyle) { Font = new Font(labelStyle.Font); Offset = new Offset(labelStyle.Offset); CollisionDetection = false; CollisionBuffer = new Size(labelStyle.CollisionBuffer); ForeColor = new Color(labelStyle.ForeColor); BackColor = new Brush(labelStyle.BackColor); HorizontalAlignment = HorizontalAlignmentEnum.Center; VerticalAlignment = VerticalAlignmentEnum.Center; }
public LabelStyle(LabelStyle labelStyle) { Font = new Font(labelStyle.Font); Offset = new Offset(labelStyle.Offset); CollisionDetection = false; ForeColor = new Color(labelStyle.ForeColor); BackColor = new Brush(labelStyle.BackColor); HorizontalAlignment = HorizontalAlignmentEnum.Center; VerticalAlignment = VerticalAlignmentEnum.Center; Text = labelStyle.Text; LabelColumn = labelStyle.LabelColumn; LabelMethod = labelStyle.LabelMethod; }
public static Canvas RenderStackedLabelLayer(IViewport viewport, LabelLayer layer) { var canvas = new Canvas(); canvas.Opacity = layer.Opacity; //todo: take into account the priority var features = layer.GetFeaturesInView(viewport.Extent, viewport.Resolution); var margin = viewport.Resolution * 50; foreach (var layerStyle in layer.Styles) { var style = layerStyle; var clusters = new List<Cluster>(); //todo: repeat until there are no more merges ClusterFeatures(clusters, features, margin, layerStyle, viewport.Resolution); foreach (var cluster in clusters) { Offset stackOffset = null; foreach (var feature in cluster.Features.OrderBy(f => f.Geometry.GetBoundingBox().GetCentroid().Y)) { if (layerStyle is IThemeStyle) style = (layerStyle as IThemeStyle).GetStyle(feature); if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.Resolution) || (style.MaxVisible < viewport.Resolution)) continue; if (stackOffset == null) //first time { stackOffset = new Offset(); if (cluster.Features.Count > 1) canvas.Children.Add(RenderBox(cluster.Box, viewport)); } else stackOffset.Y += 18; //todo: get size from text, (or just pass stack nr) if (!(style is LabelStyle)) throw new Exception("Style of label is not a LabelStyle"); var labelStyle = style as LabelStyle; string labelText = layer.GetLabel(feature); var position = new Mapsui.Geometries.Point(cluster.Box.GetCentroid().X, cluster.Box.Bottom); canvas.Children.Add(RenderLabel(position, stackOffset, labelStyle, viewport, labelText)); } } } return canvas; }
public static Canvas RenderLabelLayer(IViewport viewport, LabelLayer layer) { var canvas = new Canvas(); canvas.Opacity = layer.Opacity; //todo: take into account the priority var features = layer.GetFeaturesInView(viewport.Extent, viewport.Resolution).ToList(); var stackOffset = new Offset(); foreach (var layerStyle in layer.Styles) { var style = layerStyle; foreach (var feature in features) { if (layerStyle is IThemeStyle) style = (layerStyle as IThemeStyle).GetStyle(feature); if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.Resolution) || (style.MaxVisible < viewport.Resolution)) continue; if (!(style is LabelStyle)) throw new Exception("Style of label is not a LabelStyle"); var labelStyle = style as LabelStyle; string labelText = layer.GetLabel(feature); canvas.Children.Add(RenderLabel(feature.Geometry.GetBoundingBox().GetCentroid(), stackOffset, labelStyle, viewport, labelText)); } } return canvas; }
public static UIElement RenderLabel(Mapsui.Geometries.Point point, Offset stackOffset, LabelStyle style, IViewport viewport, string text) { Mapsui.Geometries.Point p = viewport.WorldToScreen(point); var windowsPoint = new WinPoint(p.X, p.Y); var border = new Border(); var textblock = new TextBlock(); //Text textblock.Text = text; //Colors textblock.Foreground = new SolidColorBrush(style.ForeColor.ToXaml()); border.Background = new SolidColorBrush(style.BackColor.Color.ToXaml()); //Font textblock.FontFamily = new FontFamily(style.Font.FontFamily); textblock.FontSize = style.Font.Size; //set some defaults which should be configurable someday const double witdhMargin = 3.0; const double heightMargin = 0.0; textblock.Margin = new Thickness(witdhMargin, heightMargin, witdhMargin, heightMargin); border.CornerRadius = new CornerRadius(4); border.Child = textblock; //Offset var textWidth = textblock.ActualWidth; var textHeight = textblock.ActualHeight; #if !SILVERLIGHT && !NETFX_CORE // in WPF the width and height is not calculated at this point. So we use FormattedText getTextWidthAndHeight(ref textWidth, ref textHeight, style, text); #endif border.SetValue(Canvas.LeftProperty, windowsPoint.X + style.Offset.X + stackOffset.X - (textWidth + 2 * witdhMargin) * (short)style.HorizontalAlignment * 0.5f); border.SetValue(Canvas.TopProperty, windowsPoint.Y + style.Offset.Y + stackOffset.Y - (textHeight + 2 * heightMargin) * (short)style.VerticalAlignment * 0.5f); return border; }
public static UIElement RenderLabel(Mapsui.Geometries.Point point, Offset stackOffset, LabelStyle style, IViewport viewport) { return RenderLabel(point, stackOffset, style, viewport, style.Text); }
public static CALayer RenderLabelLayer(IViewport viewport, LabelLayer layer, List<IFeature> features) { var canvas = new CALayer(); canvas.Opacity = (float)layer.Opacity; //todo: take into account the priority var stackOffset = new Offset(); if (layer.Style != null) { var style = layer.Style; foreach (var feature in features) { if (style is IThemeStyle) style = (style as IThemeStyle).GetStyle(feature); if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.Resolution) || (style.MaxVisible < viewport.Resolution)) continue; if (!(style is LabelStyle)) throw new Exception("Style of label is not a LabelStyle"); //var labelStyle = style as LabelStyle; string labelText = layer.GetLabelText(feature); var label = RenderLabel (feature.Geometry as Mapsui.Geometries.Point, style as LabelStyle, feature, viewport, labelText); canvas.AddSublayer(label); } } return canvas; }
public bool Equals(Offset offset) { if (X != offset.X) return false; if (Y != offset.Y) return false; return true; }
public Offset(Offset offset) { X = offset.X; Y = offset.Y; }