public static CATextLayer RenderLabel(Mapsui.Geometries.Point point, LabelStyle style, IFeature feature, IViewport viewport, string text) { // Offset stackOffset, Mapsui.Geometries.Point p = viewport.WorldToScreen(point); //var pointF = new xPointF((float)p.X, (float)p.Y); var label = new CATextLayer (); var aString = new Foundation.NSAttributedString (text, new CoreText.CTStringAttributes(){ Font = new CoreText.CTFont("ArialMT", 10) }); var frame = new CGRect(new CoreGraphics.CGPoint((int)p.X, (int)p.Y), GetSizeForText(0, aString)); //label.Frame = frame; //frame.Width = (float)(p2.X - p1.X);// + margin); //frame.Height = (float)(p1.Y - p2.Y); label.FontSize = 10; label.ForegroundColor = new CoreGraphics.CGColor (0, 0, 255, 150); label.BackgroundColor = new CoreGraphics.CGColor (255, 0, 2, 150); label.String = text; label.Frame = frame; Console.WriteLine ("Pos " + label.Frame.X + ":" + label.Frame.Y + " w " + label.Frame.Width + " h " + label.Frame.Height); // = MonoTouch.UIKit.UIScreen.MainScreen.Scale; // label.ContentsScale = scale; return label; }
private static SKBitmap CreateLabelAsBitmap(LabelStyle style, string text) { using (var paint = CreatePaint(style)) { return CreateLabelAsBitmap(style, text, paint); } }
public static void RenderTexture(TextureInfo textureInfo, float x, float y, float orientation = 0, float offsetX = 0, float offsetY = 0, LabelStyle.HorizontalAlignmentEnum horizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center, LabelStyle.VerticalAlignmentEnum verticalAlignment = LabelStyle.VerticalAlignmentEnum.Center, float opacity = 1f, float scale = 1f) { GL.Enable(All.Texture2D); GL.BindTexture(All.Texture2D, textureInfo.TextureId); GL.PushMatrix(); GL.Translate(x, y, 0f); GL.Rotate(orientation, 0, 0, 1); GL.Scale (scale, scale, 1); x = offsetX + DetermineHorizontalAlignmentCorrection(horizontalAlignment, textureInfo.Width); y = -offsetY + DetermineVerticalAlignmentCorrection(verticalAlignment, textureInfo.Height); var halfWidth = textureInfo.Width / 2; var halfHeight = textureInfo.Height / 2; var vertextArray = new[] { x - halfWidth, y - halfHeight, x + halfWidth, y - halfHeight, x + halfWidth, y + halfHeight, x - halfWidth, y + halfHeight }; RenderTextureWithoutBinding(textureInfo.TextureId, vertextArray, opacity); GL.PopMatrix(); GL.BindTexture(All.Texture2D, 0); GL.Disable(All.Texture2D); }
public static MemoryStream Create(LabelStyle style, string text) { UIImage image = null; var handle = new ManualResetEvent(false); var view = new UIView(); view.InvokeOnMainThread(() => { view.Opaque = false; view.BackgroundColor = UIColor.Clear; var bitmapSize = UIStringDrawing.StringSize(text, UIFont.SystemFontOfSize(14), new CGSize(115, float.MaxValue), UILineBreakMode.WordWrap); view.Layer.AddSublayer(CreateCATextLayer(style, text)); view.BackgroundColor = new UIColor(ToCGColor(style.BackColor.Color)); image = ToImage(view, new CGRect(0, 0, (float)bitmapSize.Width, (float)bitmapSize.Height)); handle.Set(); }); handle.WaitOne(); using (var nsdata = image.AsPNG()) { return new MemoryStream(nsdata.ToArray()); } }
private static int DetermineHorizontalAlignmentCorrection(LabelStyle.HorizontalAlignmentEnum horizontalAlignment, int width) { if (horizontalAlignment == LabelStyle.HorizontalAlignmentEnum.Left) return width / 2; if (horizontalAlignment == LabelStyle.HorizontalAlignmentEnum.Right) return -width / 2; return 0; // center }
private static int DetermineVerticalAlignmentCorrection(LabelStyle.VerticalAlignmentEnum verticalAlignment, int height) { if (verticalAlignment == LabelStyle.VerticalAlignmentEnum.Top) return -height / 2; if (verticalAlignment == LabelStyle.VerticalAlignmentEnum.Bottom) return height / 2; return 0; // center }
public static void RenderTexture(SKCanvas canvas, SKBitmap bitmap, float x, float y, float orientation = 0, float offsetX = 0, float offsetY = 0, LabelStyle.HorizontalAlignmentEnum horizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center, LabelStyle.VerticalAlignmentEnum verticalAlignment = LabelStyle.VerticalAlignmentEnum.Center, float opacity = 1f, float scale = 1f) { canvas.Save(); canvas.Translate(x, y); canvas.RotateDegrees(orientation, 0, 0); // todo: or degrees? canvas.Scale(scale, scale); x = offsetX + DetermineHorizontalAlignmentCorrection(horizontalAlignment, bitmap.Width); y = -offsetY + DetermineVerticalAlignmentCorrection(verticalAlignment, bitmap.Height); var halfWidth = bitmap.Width/2; var halfHeight = bitmap.Height/2; var rect = new SKRect(x - halfWidth, y - halfHeight, x + halfWidth, y + halfHeight); RenderTexture(canvas, bitmap, rect, opacity); canvas.Restore(); }
public StackedLabelProvider(IProvider provider, LabelStyle labelStyle, Pen rectangleLine = null, Brush rectangleFill = null) { _provider = provider; _labelStyle = labelStyle; _rectangleLine = rectangleLine ?? new Pen(Color.Gray); _rectangleFill = rectangleFill; }
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 void Draw(LabelStyle style, string text, float x, float y) { var key = text + "_" + style.Font.FontFamily + "_" + style.Font.Size + "_" + (float)style.Font.Size + "_" + style.BackColor + "_" + style.ForeColor; if (!LabelBitmapCache.Keys.Contains(key)) { var memoryStream = PlatformLabelBitmap.Create(style, text); LabelBitmapCache[key] = TextureHelper.LoadTexture(memoryStream); } var info = LabelBitmapCache[key]; TextureHelper.RenderTexture(info, x, y, offsetX:(float)style.Offset.X, offsetY:(float)style.Offset.Y, horizontalAlignment: style.HorizontalAlignment, verticalAlignment: style.VerticalAlignment); }
private static SKPaint CreatePaint(LabelStyle style) { return new SKPaint { TextSize = (float) style.Font.Size, IsAntialias = true, Color = style.ForeColor.ToSkia(), Typeface = SKTypeface.FromFamilyName(style.Font.FontFamily), IsStroke = false, FakeBoldText = false, IsEmbeddedBitmapText = true }; }
private static void DetermineTextWidthAndHeightWpf(out double width, out double height, LabelStyle style, string text) { // in WPF the width and height is not calculated at this point. So we use FormattedText var formattedText = new FormattedText( text, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, new Typeface(style.Font.FontFamily), style.Font.Size, new SolidColorBrush(style.ForeColor.ToXaml())); width = formattedText.Width; height = formattedText.Height; }
public static void DrawAsBitmap(SKCanvas canvas, LabelStyle style, IFeature feature, float x, float y) { var text = style.GetLabelText(feature); var key = text + "_" + style.Font.FontFamily + "_" + style.Font.Size + "_" + (float)style.Font.Size + "_" + style.BackColor + "_" + style.ForeColor; if (!LabelBitmapCache.Keys.Contains(key)) LabelBitmapCache[key] = new SKBitmapInfo { Bitmap = CreateLabelAsBitmap(style, text) }; var info = LabelBitmapCache[key]; BitmapHelper.RenderTexture(canvas, info.Bitmap, (int)Math.Round(x), (int)Math.Round(y), offsetX: (float)style.Offset.X, offsetY: (float)-style.Offset.Y, horizontalAlignment: style.HorizontalAlignment, verticalAlignment: style.VerticalAlignment); }
private static SKBitmap CreateLabelAsBitmap(LabelStyle style, string text, SKPaint paint) { var rect = new SKRect(); paint.MeasureText(text, ref rect); var backRect = new SKRect(0, 0, rect.Width + 6, rect.Height + 6); var bitmap = new SKBitmap((int)backRect.Width, (int)backRect.Height); using (var target = new SKCanvas(bitmap)) { target.Clear(); DrawBackground(style, backRect, target); target.DrawText(text, -rect.Left + 3, -rect.Top +3, paint); return bitmap; } }
public static UIElement RenderLabel(Geometries.Point position, LabelStyle labelStyle, IViewport viewport, string labelText) { var screenPosition = viewport.WorldToScreen(position); var windowsPosition = screenPosition.ToXaml(); //set some defaults which should be configurable someday const double witdhMargin = 3.0; const double heightMargin = 0.0; var textblock = new TextBlock { Text = labelText, Foreground = new SolidColorBrush(labelStyle.ForeColor.ToXaml()), FontFamily = new FontFamily(labelStyle.Font.FontFamily), FontSize = labelStyle.Font.Size, Margin = new Thickness(witdhMargin, heightMargin, witdhMargin, heightMargin), FontWeight = FontWeights.Bold }; var border = new Border { Background = new SolidColorBrush(labelStyle.BackColor == null ? Colors.Transparent : labelStyle.BackColor.Color.ToXaml()), CornerRadius = new CornerRadius(4), Child = textblock }; double textWidth; double textHeight; #if NETFX_CORE DetermineTextWidthAndHeightWindows8(out textWidth, out textHeight, border, textblock); #elif SILVERLIGHT DetermineTextWidthAndHeightSilverlight(out textWidth, out textHeight, textblock); #else // WPF DetermineTextWidthAndHeightWpf(out textWidth, out textHeight, labelStyle, labelText); #endif border.SetValue(Canvas.LeftProperty, windowsPosition.X + labelStyle.Offset.X - (textWidth + 2 * witdhMargin) * (short)labelStyle.HorizontalAlignment * 0.5f); border.SetValue(Canvas.TopProperty, windowsPosition.Y + labelStyle.Offset.Y - (textHeight + 2 * heightMargin) * (short)labelStyle.VerticalAlignment * 0.5f); return border; }
public static MemoryStream Create(LabelStyle style, string text) { var font = new Font(style.Font.FontFamily, (float)style.Font.Size, FontStyle.Bold); var size = _graphics.MeasureString(text, font); var targetBitmap = new Bitmap((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb); var targetGraphics = Graphics.FromImage(targetBitmap); targetGraphics.TextRenderingHint = TextRenderingHint.AntiAlias; // Render a text label targetGraphics.Clear((style.BackColor == null) ? Color.Transparent : ToGdi(style.BackColor.Color)); targetGraphics.DrawString(text, font, new SolidBrush(ToGdi(style.ForeColor)), PointF.Empty); var memoryStream = new MemoryStream(); targetBitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png); memoryStream.Position = 0; return memoryStream; }
private static CATextLayer CreateCATextLayer(LabelStyle style, string text) { var label = new CATextLayer (); var ctFont = new CoreText.CTFont (style.Font.FontFamily, (float)style.Font.Size); var aString = new Foundation.NSAttributedString (text, new CoreText.CTStringAttributes() { Font = ctFont }); label.SetFont(ctFont); label.FontSize = (float)style.Font.Size; label.ForegroundColor = ToCGColor(style.ForeColor); label.BackgroundColor = TransparentColor; label.ShadowOpacity = 0; label.BorderWidth = 0; label.String = text; var size = GetSizeForText (0, aString); label.Frame = new CGRect (0, 0, size.Width, size.Height); return label; }
public static MemoryStream Create(LabelStyle style, string text) { throw new NotImplementedException(); }
private static void getTextWidthAndHeight(ref double width, ref double height, LabelStyle style, string text) { var formattedText = new FormattedText( text, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, new Typeface(style.Font.FontFamily), style.Font.Size, new SolidColorBrush(style.ForeColor.ToXaml())); width = formattedText.Width; height = formattedText.Height; }
public static Canvas Render(IViewport viewport, LabelLayer layer) { // todo: Move stack functionality to Mapsui core. // step 1) Split RenderStackedLabelLayer into a method // GetFeaturesInViewStacked en a RenderStackedLabel // which can later be replace by normal label rendering. // The method GetFeaturesInViewStacked // returns a style with an offset determined by the stackoffset // and a position determined by CenterX en Cluster.Box.Bottom. // step 2) Move GetFeaturesInViewStacked to a GetFeaturesInView // method of a new StackedLabelLayed. var canvas = new Canvas { Opacity = layer.Opacity }; // todo: take into account the priority var features = layer.GetFeaturesInView(viewport.Extent, viewport.Resolution).ToArray(); var margin = viewport.Resolution * 50; const int symbolSize = 32; // todo: determine margin by symbol size const int boxMargin = symbolSize / 2; var clusters = new List<Cluster>(); //todo: repeat until there are no more merges ClusterFeatures(clusters, features, margin, layer.Style, viewport.Resolution); const int textHeight = 18; foreach (var cluster in clusters) { var stackOffsetY = double.NaN; var orderedFeatures = cluster.Features.OrderBy(f => f.Geometry.GetBoundingBox().GetCentroid().Y); if (cluster.Features.Count > 1) canvas.Children.Add(RenderBox(cluster.Box, viewport)); foreach (var feature in orderedFeatures) { if (double.IsNaN(stackOffsetY)) // first time stackOffsetY = textHeight * 0.5 + boxMargin; else stackOffsetY += textHeight; //todo: get size from text (or just pass stack nr) LabelStyle style; if (layer.Style is IThemeStyle) { style = (LabelStyle)((IThemeStyle)layer.Style).GetStyle(feature); } else { style = (LabelStyle)layer.Style; } var labelStyle = new LabelStyle(style) { Text = layer.GetLabelText(feature) //we only use the layer for the text, this should be returned by style }; labelStyle.Offset.Y += stackOffsetY; // since the box can be rotated, find the minimal Y value of all 4 corners var rotatedBox = cluster.Box.Rotate(-viewport.Rotation); var minY = rotatedBox.Vertices.Select(v => v.Y).Min(); var position = new Geometries.Point(cluster.Box.GetCentroid().X, minY); var labelText = labelStyle.GetLabelText(feature); canvas.Children.Add(SingleLabelRenderer.RenderLabel(position, labelStyle, viewport, labelText)); } } return canvas; }
private static GradientTheme CreateCountryLabelTheme() { //Lets scale the labels so that big countries have larger texts as well var lblMin = new LabelStyle(); var lblMax = new LabelStyle(); lblMin.ForeColor = Color.Black; lblMin.Font = new Font { FontFamily = "GenericSerif", Size = 6 }; lblMax.ForeColor = Color.Blue; lblMax.BackColor = new Brush { Color = new Color { A = 128, R = 255, G = 255, B = 255 } }; lblMin.BackColor = lblMax.BackColor; lblMax.Font = new Font { FontFamily = "GenericSerif", Size = 9 }; var labelTheme = new GradientTheme("PopDens", 0, 400, lblMin, lblMax); return labelTheme; }
private static LabelStyle CreateCityLabelTheme() { var cityLabelStyle = new LabelStyle(); cityLabelStyle.ForeColor = Color.Black; cityLabelStyle.BackColor = new Brush { Color = Color.Orange }; cityLabelStyle.Font = new Font { FontFamily = "GenericSerif", Size = 11 }; cityLabelStyle.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center; cityLabelStyle.VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Center; cityLabelStyle.Offset = new Offset { X = 0, Y = 0 }; cityLabelStyle.Halo = new Pen { Color = Color.Yellow, Width = 2 }; cityLabelStyle.CollisionDetection = true; return cityLabelStyle; }
public static Map InitializeMap() { //Initialize a new map based on the simple map var map = new Map(); //Layer osm = new Layer("OSM"); //string url = "http://labs.metacarta.com/wms-c/tilecache.py?version=1.1.1&request=GetCapabilities&service=wms-c"; //var tileSources = TileSourceWmsC.TileSourceBuilder(new Uri(url), null); //var tileSource = new List<ITileSource>(tileSources).Find(source => source.Schema.Name == "osm-map"); //osm.DataSource = new TileProvider(tileSource, "OSM"); //map.Layers.Add(osm); //Set up countries layer var countryLayer = new Layer("Countries"); //Set the datasource to a shapefile in the App_data folder countryLayer.DataSource = new ShapeFile("GeoData/World/countries.shp", true); countryLayer.DataSource.SRID = 4326; var style = new VectorStyle { Fill = new Brush { Color = Color.Green }, Outline = new Pen { Color = Color.Black } }; countryLayer.Styles.Add(style); map.Layers.Add(countryLayer); //set up cities layer var cityLayer = new Layer("Cities"); //Set the datasource to a shapefile in the App_data folder cityLayer.DataSource = new ShapeFile("GeoData/World/cities.shp", true); cityLayer.DataSource.SRID = 4326; cityLayer.MaxVisible = 0.09; map.Layers.Add(cityLayer); //Set up a country label layer var countryLabelLayer = new LabelLayer("Country labels"); countryLabelLayer.DataSource = countryLayer.DataSource; countryLabelLayer.DataSource.SRID = 4326; countryLabelLayer.Enabled = true; countryLabelLayer.MaxVisible = 0.18; countryLabelLayer.MinVisible = 0.054; countryLabelLayer.LabelColumn = "NAME"; var labelStyle = new LabelStyle(); labelStyle.ForeColor = Color.Black; labelStyle.Font = new Font { FontFamily = "GenericSerif", Size = 12 }; labelStyle.BackColor = new Brush { Color = new Color { A = 128, R = 255, G = 255, B = 255 } }; labelStyle.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center; countryLabelLayer.MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest; countryLabelLayer.Styles.Add(labelStyle); map.Layers.Add(countryLabelLayer); //Set up a city label layer var cityLabelLayer = new LabelLayer("City labels"); cityLabelLayer.DataSource = cityLayer.DataSource; cityLabelLayer.DataSource.SRID = 4326; cityLabelLayer.Enabled = true; cityLabelLayer.LabelColumn = "NAME"; cityLabelLayer.MaxVisible = countryLabelLayer.MinVisible; cityLabelLayer.MinVisible = 0; cityLabelLayer.LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection; var cityLabelStyle = new LabelStyle(); cityLabelStyle.ForeColor = Color.Black; cityLabelStyle.Font = new Font { FontFamily = "GenericSerif", Size = 11 }; cityLabelStyle.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left; cityLabelStyle.VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom; cityLabelStyle.Offset = new Offset { X = 3, Y = 3 }; cityLabelStyle.Halo = new Pen { Color = Color.Yellow, Width = 2 }; cityLabelStyle.CollisionDetection = true; cityLabelLayer.Styles.Add(cityLabelStyle); map.Layers.Add(cityLabelLayer); //Set a gradient theme on the countries layer, based on Population density //First create two styles that specify min and max styles //In this case we will just use the default values and override the fill-colors //using a colorblender. If different line-widths, line- and fill-colors where used //in the min and max styles, these would automatically get linearly interpolated. IStyle min = new Style(); IStyle max = new Style(); //Create theme using a density from 0 (min) to 400 (max) var popdens = new GradientTheme("PopDens", 0, 400, min, max); //We can make more advanced coloring using the ColorBlend'er. //Setting the FillColorBlend will override any fill-style in the min and max fills. //In this case we just use the predefined Rainbow colorscale popdens.FillColorBlend = ColorBlend.Rainbow5; countryLayer.Styles.Add(popdens); //Lets scale the labels so that big countries have larger texts as well var lblMin = new LabelStyle(); var lblMax = new LabelStyle(); lblMin.ForeColor = Color.Black; lblMin.Font = new Font { FontFamily = "Sans Serif", Size = 6 }; lblMax.ForeColor = Color.Black; lblMax.BackColor = new Brush { Color = new Color { A = 128, R = 255, G = 255, B = 255 } }; lblMin.BackColor = lblMax.BackColor; lblMax.Font = new Font { FontFamily = "Sans Serif", Size = 9 }; countryLabelLayer.Styles.Add(new GradientTheme("PopDens", 0, 400, lblMin, lblMax)); //Lets scale city icons based on city population //cities below 1.000.000 gets the smallest symbol, and cities with more than 5.000.000 the largest symbol var citymin = new SymbolStyle(); var citymax = new SymbolStyle(); const string iconPath = "Images/icon.png"; if (!File.Exists(iconPath)) { throw new Exception( String.Format("Error file '{0}' could not be found, make sure it is at the expected location", iconPath)); } citymin.Symbol = new Bitmap { Data = new FileStream(iconPath, FileMode.Open, FileAccess.Read) }; citymin.SymbolScale = 0.5f; citymax.Symbol = new Bitmap { Data = new FileStream(iconPath, FileMode.Open, FileAccess.Read) }; citymax.SymbolScale = 1f; cityLayer.Styles.Add(new GradientTheme("Population", 1000000, 5000000, citymin, citymax)); var geodanLayer = new Layer("Geodan"); geodanLayer.DataSource = new MemoryProvider(new Point(4.9130567, 52.3422033)); geodanLayer.Styles.Add(new SymbolStyle { Symbol = new Bitmap { Data = new FileStream(iconPath, FileMode.Open, FileAccess.Read) } }); map.Layers.Add(geodanLayer); //limit the zoom to 360 degrees width map.BackColor = Color.White; return map; }
private static Label CreateLabel(IGeometry feature, string text, float rotation, int priority, LabelStyle style, IViewport viewport, Graphics g) { var gdiSize = g.MeasureString(text, style.Font.ToGdi()); var size = new Styles.Size { Width = gdiSize.Width, Height = gdiSize.Height }; var position = viewport.WorldToScreen(feature.GetBoundingBox().GetCentroid()); position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f; position.Y = position.Y - size.Height * (short)style.VerticalAlignment * 0.5f; if (position.X - size.Width > viewport.Width || position.X + size.Width < 0 || position.Y - size.Height > viewport.Height || position.Y + size.Height < 0) return null; Label label; if (!style.CollisionDetection) label = new Label(text, position, rotation, priority, null, style); else { //Collision detection is enabled so we need to measure the size of the string label = new Label(text, position, rotation, priority, new LabelBox(position.X - size.Width * 0.5f - style.CollisionBuffer.Width, position.Y + size.Height * 0.5f + style.CollisionBuffer.Height, size.Width + 2f * style.CollisionBuffer.Width, size.Height + style.CollisionBuffer.Height * 2f), style); } if (!(feature is LineString)) return label; var line = feature as LineString; if (line.Length / viewport.Resolution > size.Width) //Only label feature if it is long enough CalculateLabelOnLinestring(line, ref label, viewport); else return null; return label; }
private static void DrawLabel(SKCanvas target, float x, float y, LabelStyle style, string text) { var paint = CreatePaint(style); var rect = new SKRect(); paint.MeasureText(text, ref rect); var align = CalcAlignFactor(style.VerticalAlignment); rect.Offset( x - rect.Width*0.5f + (float) style.Offset.X, y + rect.Height*0.5f + (float) style.Offset.Y); var backRect = rect; backRect.Inflate(3, 3); DrawBackground(style, backRect, target); target.DrawText(text, rect.Left, rect.Bottom, paint); }
public static CALayer RenderLabel(Mapsui.Geometries.Point point, LabelStyle style, IViewport viewport) { //Offset stackOffset, //return RenderLabel(point, stackOffset, style, viewport, style.Text); return new CALayer (); }
public static void Draw(SKCanvas canvas, LabelStyle style, IFeature feature, float x, float y) { var text = style.GetLabelText(feature); DrawLabel(canvas, x, y, style, text); }
private static object CalcAlignFactor(LabelStyle.VerticalAlignmentEnum verticalAlignment) { return (verticalAlignment == LabelStyle.VerticalAlignmentEnum.Center) ? 0.5f : 0f; }
private static void DrawBackground(LabelStyle style, SKRect rect, SKCanvas target) { if (style.BackColor != null) { var color = style.BackColor?.Color?.ToSkia(); if (color.HasValue) { var rounding = 6; using (var backgroundPaint = new SKPaint {Color = color.Value}) { target.DrawRoundRect(rect, rounding, rounding, backgroundPaint); } } } }