Exemple #1
0
        public static void Draw(SKCanvas canvas, IReadOnlyViewport viewport, IStyle style, IFeature feature,
                                IGeometry geometry, SymbolCache symbolCache, float opacity)
        {
            var point       = geometry as Point;
            var destination = viewport.WorldToScreen(point);

            if (style is LabelStyle labelStyle)    // case 1) LabelStyle
            {
                LabelRenderer.Draw(canvas, labelStyle, feature, (float)destination.X, (float)destination.Y,
                                   opacity);
            }
            else if (style is SymbolStyle)
            {
                var symbolStyle = (SymbolStyle)style;

                if (symbolStyle.BitmapId >= 0)    // case 2) Bitmap Style
                {
                    DrawPointWithBitmapStyle(canvas, symbolStyle, destination, symbolCache, opacity);
                }
                else                              // case 3) SymbolStyle without bitmap
                {
                    DrawPointWithSymbolStyle(canvas, symbolStyle, destination, opacity, symbolStyle.SymbolType);
                }
            }
            else if (style is VectorStyle)        // case 4) VectorStyle
            {
                DrawPointWithVectorStyle(canvas, (VectorStyle)style, destination, opacity);
            }
            else
            {
                throw new Exception($"Style of type '{style.GetType()}' is not supported for points");
            }
        }
Exemple #2
0
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature,
                                IDictionary <int, SKBitmapInfo> symbolBitmapCache)
        {
            var point       = feature.Geometry as Point;
            var destination = viewport.WorldToScreen(point);

            var labelStyle = style as LabelStyle;

            if (labelStyle != null)
            {
                LabelRenderer.Draw(canvas, labelStyle, labelStyle.GetLabelText(feature),
                                   (float)destination.X, (float)destination.Y);
            }
            var symbolStyle = style as SymbolStyle;

            if (symbolStyle != null)
            {
                if (symbolStyle.BitmapId >= 0)
                {
                    DrawPointWithSymbolStyle(canvas, symbolStyle, destination, symbolBitmapCache);
                }
                else
                {
                    DrawPointWithVectorStyle(canvas, (VectorStyle)style, destination, symbolStyle.SymbolType);
                }
            }
            else if (style is VectorStyle)
            {
                DrawPointWithVectorStyle(canvas, (VectorStyle)style, destination);
            }
        }
Exemple #3
0
        public static void Draw(SKCanvas canvas, IReadOnlyViewport viewport, IStyle style, IFeature feature, IGeometry geometry,
                                float opacity)
        {
            if (style is LabelStyle labelStyle)
            {
                var worldCenter = geometry.BoundingBox.Centroid;
                var center      = viewport.WorldToScreen(worldCenter);
                LabelRenderer.Draw(canvas, labelStyle, feature, center, opacity);
            }
            else
            {
                var lineString = ((LineString)geometry).Vertices;

                float lineWidth = 1;
                var   lineColor = new Color();

                var     vectorStyle      = style as VectorStyle;
                var     strokeCap        = PenStrokeCap.Butt;
                var     strokeJoin       = StrokeJoin.Miter;
                var     strokeMiterLimit = 4f;
                var     strokeStyle      = PenStyle.Solid;
                float[] dashArray        = null;
                float   dashOffset       = 0;

                if (vectorStyle != null)
                {
                    lineWidth        = (float)vectorStyle.Line.Width;
                    lineColor        = vectorStyle.Line.Color;
                    strokeCap        = vectorStyle.Line.PenStrokeCap;
                    strokeJoin       = vectorStyle.Line.StrokeJoin;
                    strokeMiterLimit = vectorStyle.Line.StrokeMiterLimit;
                    strokeStyle      = vectorStyle.Line.PenStyle;
                    dashArray        = vectorStyle.Line.DashArray;
                    dashOffset       = vectorStyle.Line.DashOffset;
                }

                using (var path = lineString.ToSkiaPath(viewport, canvas.LocalClipBounds))
                    using (var paint = new SKPaint {
                        IsAntialias = true
                    })
                    {
                        paint.IsStroke    = true;
                        paint.StrokeWidth = lineWidth;
                        paint.Color       = lineColor.ToSkia(opacity);
                        paint.StrokeCap   = strokeCap.ToSkia();
                        paint.StrokeJoin  = strokeJoin.ToSkia();
                        paint.StrokeMiter = strokeMiterLimit;
                        if (strokeStyle != PenStyle.Solid)
                        {
                            paint.PathEffect = strokeStyle.ToSkia(lineWidth, dashArray, dashOffset);
                        }
                        else
                        {
                            paint.PathEffect = null;
                        }
                        canvas.DrawPath(path, paint);
                    }
            }
        }
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature, IGeometry geometry,
                                float opacity)
        {
            if (style is LabelStyle)
            {
                var worldCenter = geometry.GetBoundingBox().GetCentroid();
                var center      = viewport.WorldToScreen(worldCenter);
                LabelRenderer.Draw(canvas, (LabelStyle)style, feature, (float)center.X, (float)center.Y, opacity);
            }
            else
            {
                var polygon = (Polygon)geometry;

                float lineWidth   = 1;
                var   lineColor   = Color.Black;       // default
                var   fillColor   = Color.Gray;        // default
                var   strokeCap   = PenStrokeCap.Butt; // default
                var   strokeStyle = PenStyle.Solid;    // default

                var vectorStyle = style as VectorStyle;

                if (vectorStyle != null)
                {
                    lineWidth   = (float)vectorStyle.Outline.Width;
                    lineColor   = vectorStyle.Outline.Color;
                    strokeCap   = vectorStyle.Outline.PenStrokeCap;
                    strokeStyle = vectorStyle.Outline.PenStyle;

                    fillColor = vectorStyle.Fill?.Color;
                }

                using (var path = ToSkia(viewport, polygon))
                {
                    using (var paint = new SKPaint())
                    {
                        paint.IsAntialias = true;
                        paint.StrokeWidth = lineWidth;

                        paint.Style = SKPaintStyle.Fill;
                        paint.Color = fillColor.ToSkia(opacity);
                        canvas.DrawPath(path, paint);
                        paint.Style     = SKPaintStyle.Stroke;
                        paint.Color     = lineColor.ToSkia(opacity);
                        paint.StrokeCap = strokeCap.ToSkia();
                        if (strokeStyle != PenStyle.Solid)
                        {
                            paint.PathEffect = strokeStyle.ToSkia(lineWidth);
                        }
                        canvas.DrawPath(path, paint);
                    }
                }
            }
        }
Exemple #5
0
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature, IGeometry geometry,
                                float opacity)
        {
            if (style is LabelStyle labelStyle)
            {
                var worldCenter = geometry.GetBoundingBox().GetCentroid();
                var center      = viewport.WorldToScreen(worldCenter);
                LabelRenderer.Draw(canvas, labelStyle, feature, (float)center.X, (float)center.Y, opacity);
            }
            else
            {
                var lineString = ((LineString)geometry).Vertices;

                float lineWidth = 1;
                var   lineColor = new Color();

                var     vectorStyle      = style as VectorStyle;
                var     strokeCap        = PenStrokeCap.Butt;
                var     strokeJoin       = StrokeJoin.Miter;
                var     strokeMiterLimit = 4f;
                var     strokeStyle      = PenStyle.Solid;
                float[] dashArray        = null;

                if (vectorStyle != null)
                {
                    lineWidth        = (float)vectorStyle.Line.Width;
                    lineColor        = vectorStyle.Line.Color;
                    strokeCap        = vectorStyle.Line.PenStrokeCap;
                    strokeJoin       = vectorStyle.Line.StrokeJoin;
                    strokeMiterLimit = vectorStyle.Line.StrokeMiterLimit;
                    strokeStyle      = vectorStyle.Line.PenStyle;
                    dashArray        = vectorStyle.Line.DashArray;
                }

                var line = WorldToScreen(viewport, lineString);
                var path = ToSkia(line);

                using (var paint = new SKPaint())
                {
                    paint.IsStroke    = true;
                    paint.StrokeWidth = lineWidth;
                    paint.Color       = lineColor.ToSkia(opacity);
                    paint.StrokeCap   = strokeCap.ToSkia();
                    paint.StrokeJoin  = strokeJoin.ToSkia();
                    paint.StrokeMiter = strokeMiterLimit;
                    if (strokeStyle != PenStyle.Solid)
                    {
                        paint.PathEffect = strokeStyle.ToSkia(lineWidth, dashArray);
                    }
                    canvas.DrawPath(path, paint);
                }
            }
        }
Exemple #6
0
        public static void Draw(SKCanvas canvas, IReadOnlyViewport viewport, IStyle style, IFeature feature,
                                LineString lineString, float opacity)
        {
            if (style is LabelStyle labelStyle)
            {
                if (feature.Extent == null)
                {
                    return;
                }

                var center = viewport.WorldToScreen(feature.Extent.Centroid);
                LabelRenderer.Draw(canvas, labelStyle, feature, center.X, center.Y, opacity);
            }
            else
            {
                float lineWidth = 1;
                var   lineColor = new Color();

                var vectorStyle      = style as VectorStyle;
                var strokeCap        = PenStrokeCap.Butt;
                var strokeJoin       = StrokeJoin.Miter;
                var strokeMiterLimit = 4f;
                var strokeStyle      = PenStyle.Solid;
                float[]? dashArray = null;
                float dashOffset = 0;

                if (vectorStyle is not null && vectorStyle.Line != null)
                {
                    lineWidth        = (float)vectorStyle.Line.Width;
                    lineColor        = vectorStyle.Line.Color;
                    strokeCap        = vectorStyle.Line.PenStrokeCap;
                    strokeJoin       = vectorStyle.Line.StrokeJoin;
                    strokeMiterLimit = vectorStyle.Line.StrokeMiterLimit;
                    strokeStyle      = vectorStyle.Line.PenStyle;
                    dashArray        = vectorStyle.Line.DashArray;
                    dashOffset       = vectorStyle.Line.DashOffset;
                }

                using var path    = lineString.ToSkiaPath(viewport, canvas.LocalClipBounds);
                using var paint   = new SKPaint { IsAntialias = true };
                paint.IsStroke    = true;
                paint.StrokeWidth = lineWidth;
                paint.Color       = lineColor.ToSkia(opacity);
                paint.StrokeCap   = strokeCap.ToSkia();
                paint.StrokeJoin  = strokeJoin.ToSkia();
                paint.StrokeMiter = strokeMiterLimit;
                paint.PathEffect  = strokeStyle != PenStyle.Solid
                    ? strokeStyle.ToSkia(lineWidth, dashArray, dashOffset)
                    : null;
                canvas.DrawPath(path, paint);
            }
        }
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature, IGeometry geometry)
        {
            if (style is LabelStyle)
            {
                var center = geometry.GetBoundingBox().GetCentroid();
                LabelRenderer.Draw(canvas, (LabelStyle)style, feature, (float)center.X, (float)center.Y);
            }
            else
            {
                var polygon = (Polygon)geometry;

                float lineWidth = 1;
                var   lineColor = Color.Black; // default
                var   fillColor = Color.Gray;  // default

                var vectorStyle = style as VectorStyle;

                if (vectorStyle != null)
                {
                    lineWidth = (float)vectorStyle.Outline.Width;
                    lineColor = vectorStyle.Outline.Color;
                    fillColor = vectorStyle.Fill?.Color;
                }

                using (var path = ToSkia(viewport, polygon))
                {
                    using (var paint = new SKPaint())
                    {
                        paint.IsAntialias = true;
                        paint.StrokeWidth = lineWidth;

                        paint.Style = SKPaintStyle.Fill;
                        paint.Color = fillColor.ToSkia();
                        canvas.DrawPath(path, paint);
                        paint.Style = SKPaintStyle.Stroke;
                        paint.Color = lineColor.ToSkia();
                        canvas.DrawPath(path, paint);
                    }
                }
            }
        }
Exemple #8
0
        public static void Draw(SKCanvas canvas, IReadOnlyViewport viewport, IStyle style, IFeature feature,
                                IGeometry geometry, SymbolCache symbolCache, float opacity)
        {
            var point       = geometry as Point;
            var destination = viewport.WorldToScreen(point);

            if (style is CalloutStyle calloutStyle)
            {
                CalloutStyleRenderer.Draw(canvas, viewport, symbolCache, opacity, destination, calloutStyle);
            }
            else if (style is LabelStyle labelStyle)
            {
                LabelRenderer.Draw(canvas, labelStyle, feature, destination, opacity);
            }
            else if (style is SymbolStyle symbolStyle)
            {
                if (symbolStyle.BitmapId >= 0)
                {
                    // todo: Remove this call. ImageStyle should be used instead of SymbolStyle with BitmapId
                    ImageStyleRenderer.Draw(canvas, symbolStyle, destination, symbolCache, opacity, viewport.Rotation);
                }
                else
                {
                    SymbolStyleRenderer.Draw(canvas, symbolStyle, destination, opacity, symbolStyle.SymbolType, viewport.Rotation);
                }
            }
            else if (style is ImageStyle imageStyle)
            {
                ImageStyleRenderer.Draw(canvas, imageStyle, destination, symbolCache, opacity, viewport.Rotation);
            }
            else if (style is VectorStyle vectorStyle)
            {
                // Use the SymbolStyleRenderer and specify Ellipse
                SymbolStyleRenderer.Draw(canvas, vectorStyle, destination, opacity, SymbolType.Ellipse);
            }
            else
            {
                throw new Exception($"Style of type '{style.GetType()}' is not supported for points");
            }
        }
Exemple #9
0
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature, IGeometry geometry)
        {
            if (style is LabelStyle labelStyle)
            {
                var worldCenter = geometry.GetBoundingBox().GetCentroid();
                var center      = viewport.WorldToScreen(worldCenter);
                LabelRenderer.Draw(canvas, labelStyle, feature, (float)center.X, (float)center.Y);
            }
            else
            {
                var lineString = ((LineString)geometry).Vertices;

                float lineWidth = 1;
                var   lineColor = new Color();

                var vectorStyle = style as VectorStyle;
                var strokeCap   = PenStrokeCap.Butt;

                if (vectorStyle != null)
                {
                    lineWidth = (float)vectorStyle.Line.Width;
                    lineColor = vectorStyle.Line.Color;
                    strokeCap = vectorStyle.Line.PenStrokeCap;
                }

                var line = WorldToScreen(viewport, lineString);
                var path = ToSkia(line);

                using (var paint = new SKPaint())
                {
                    paint.IsStroke    = true;
                    paint.StrokeWidth = lineWidth;
                    paint.Color       = lineColor.ToSkia();
                    paint.StrokeJoin  = SKStrokeJoin.Round;
                    paint.StrokeCap   = strokeCap.ToSkia();

                    canvas.DrawPath(path, paint);
                }
            }
        }
Exemple #10
0
        public static void Draw(SKCanvas canvas, IReadOnlyViewport viewport, IStyle style, IFeature feature, IGeometry geometry,
                                float opacity, SymbolCache symbolCache = null)
        {
            if (style is LabelStyle labelStyle)
            {
                var worldCenter = geometry.BoundingBox.Centroid;
                var center      = viewport.WorldToScreen(worldCenter);
                LabelRenderer.Draw(canvas, labelStyle, feature, (float)center.X, (float)center.Y, opacity);
            }
            else if (style is StyleCollection styleCollection)
            {
                foreach (var s in styleCollection)
                {
                    Draw(canvas, viewport, s, feature, geometry, opacity, symbolCache);
                }
            }
            else if (style is VectorStyle vectorStyle)
            {
                var polygon = (Polygon)geometry;

                float   lineWidth        = 1;
                var     lineColor        = Color.Black;       // default
                var     fillColor        = Color.Gray;        // default
                var     strokeCap        = PenStrokeCap.Butt; // default
                var     strokeJoin       = StrokeJoin.Miter;  // default
                var     strokeMiterLimit = 4f;                // default
                var     strokeStyle      = PenStyle.Solid;    // default
                float[] dashArray        = null;              // default

                if (vectorStyle.Outline != null)
                {
                    lineWidth        = (float)vectorStyle.Outline.Width;
                    lineColor        = vectorStyle.Outline.Color;
                    strokeCap        = vectorStyle.Outline.PenStrokeCap;
                    strokeJoin       = vectorStyle.Outline.StrokeJoin;
                    strokeMiterLimit = vectorStyle.Outline.StrokeMiterLimit;
                    strokeStyle      = vectorStyle.Outline.PenStyle;
                    dashArray        = vectorStyle.Outline.DashArray;
                }

                if (vectorStyle.Fill != null)
                {
                    fillColor = vectorStyle.Fill?.Color;
                }

                using (var path = polygon.ToSkiaPath(viewport, canvas.LocalClipBounds, lineWidth))
                    using (var paintFill = new SKPaint {
                        IsAntialias = true
                    })
                    {
                        // Is there a FillStyle?
                        if (vectorStyle.Fill?.FillStyle == FillStyle.Solid)
                        {
                            paintFill.StrokeWidth = 0;
                            paintFill.Style       = SKPaintStyle.Fill;
                            paintFill.PathEffect  = null;
                            paintFill.Shader      = null;
                            paintFill.Color       = fillColor.ToSkia(opacity);
                            canvas.DrawPath(path, paintFill);
                        }
                        else
                        {
                            paintFill.StrokeWidth = 1;
                            paintFill.Style       = SKPaintStyle.Stroke;
                            paintFill.Shader      = null;
                            paintFill.Color       = fillColor.ToSkia(opacity);
                            var scale    = 10.0f;
                            var fillPath = new SKPath();
                            var matrix   = SKMatrix.MakeScale(scale, scale);

                            switch (vectorStyle.Fill?.FillStyle)
                            {
                            case FillStyle.Cross:
                                fillPath.MoveTo(scale * 0.8f, scale * 0.8f);
                                fillPath.LineTo(0, 0);
                                fillPath.MoveTo(0, scale * 0.8f);
                                fillPath.LineTo(scale * 0.8f, 0);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.DiagonalCross:
                                fillPath.MoveTo(scale, scale);
                                fillPath.LineTo(0, 0);
                                fillPath.MoveTo(0, scale);
                                fillPath.LineTo(scale, 0);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.BackwardDiagonal:
                                fillPath.MoveTo(0, scale);
                                fillPath.LineTo(scale, 0);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.ForwardDiagonal:
                                fillPath.MoveTo(scale, scale);
                                fillPath.LineTo(0, 0);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.Dotted:
                                paintFill.Style = SKPaintStyle.StrokeAndFill;
                                fillPath.AddCircle(scale * 0.5f, scale * 0.5f, scale * 0.35f);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.Horizontal:
                                fillPath.MoveTo(0, scale * 0.5f);
                                fillPath.LineTo(scale, scale * 0.5f);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.Vertical:
                                fillPath.MoveTo(scale * 0.5f, 0);
                                fillPath.LineTo(scale * 0.5f, scale);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.Bitmap:
                                paintFill.Style = SKPaintStyle.Fill;
                                var image = GetImage(symbolCache, vectorStyle.Fill.BitmapId);
                                if (image != null)
                                {
                                    paintFill.Shader = image.ToShader(SKShaderTileMode.Repeat, SKShaderTileMode.Repeat);
                                }
                                break;

                            case FillStyle.BitmapRotated:
                                paintFill.Style = SKPaintStyle.Fill;
                                image           = GetImage(symbolCache, vectorStyle.Fill.BitmapId);
                                if (image != null)
                                {
                                    paintFill.Shader = image.ToShader(SKShaderTileMode.Repeat,
                                                                      SKShaderTileMode.Repeat,
                                                                      SKMatrix.MakeRotation((float)(viewport.Rotation * System.Math.PI / 180.0f), image.Width >> 1, image.Height >> 1));
                                }
                                break;

                            default:
                                paintFill.PathEffect = null;
                                break;
                            }

                            // Do this, because if not, path isn't filled complete
                            using (new SKAutoCanvasRestore(canvas))
                            {
                                canvas.ClipPath(path);
                                var bounds = path.Bounds;
                                // Make sure, that the brush starts with the correct position
                                var inflate = ((int)path.Bounds.Width * 0.3f / scale) * scale;
                                bounds.Inflate(inflate, inflate);
                                // Draw rect with bigger size, which is clipped by path
                                canvas.DrawRect(bounds, paintFill);
                            }
                        }

                        if (vectorStyle.Outline != null)
                        {
                            using (var paintStroke = new SKPaint {
                                IsAntialias = true
                            })
                            {
                                paintStroke.Style       = SKPaintStyle.Stroke;
                                paintStroke.StrokeWidth = lineWidth;
                                paintStroke.Color       = lineColor.ToSkia(opacity);
                                paintStroke.StrokeCap   = strokeCap.ToSkia();
                                paintStroke.StrokeJoin  = strokeJoin.ToSkia();
                                paintStroke.StrokeMiter = strokeMiterLimit;
                                if (strokeStyle != PenStyle.Solid)
                                {
                                    paintStroke.PathEffect = strokeStyle.ToSkia(lineWidth, dashArray);
                                }
                                else
                                {
                                    paintStroke.PathEffect = null;
                                }
                                canvas.DrawPath(path, paintStroke);
                            }
                        }
                    }
            }
        }