Example #1
0
        public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, Styles.IStyle style, ISymbolCache symbolCache, long iteration)
        {
            var centroid = feature.Extent?.Centroid;

            if (centroid is null)
            {
                return(false);
            }

            var calloutStyle = (CalloutStyle)style;

            // Todo: Use opacity
            var opacity = (float)(layer.Opacity * style.Opacity);

            var(x, y) = viewport.WorldToScreenXY(centroid.X, centroid.Y);

            if (calloutStyle.BitmapId < 0 || calloutStyle.Invalidated)
            {
                if (calloutStyle.Content < 0 && calloutStyle.Type == CalloutType.Custom)
                {
                    return(false);
                }

                if (calloutStyle.Invalidated)
                {
                    UpdateContent(calloutStyle);
                }

                RenderCallout(calloutStyle);
            }

            // Now we have the complete callout rendered, so we could draw it
            if (calloutStyle.BitmapId < 0)
            {
                return(false);
            }

            var picture = (SKPicture)BitmapRegistry.Instance.Get(calloutStyle.BitmapId);

            // Calc offset (relative or absolute)
            MPoint symbolOffset = calloutStyle.SymbolOffset.ToPoint();

            if (calloutStyle.SymbolOffset.IsRelative)
            {
                symbolOffset.X *= picture.CullRect.Width;
                symbolOffset.Y *= picture.CullRect.Height;
            }

            var rotation = (float)calloutStyle.SymbolRotation;

            if (viewport.Rotation != 0)
            {
                if (calloutStyle.RotateWithMap)
                {
                    rotation += (float)viewport.Rotation;
                }
                if (calloutStyle.SymbolOffsetRotatesWithMap)
                {
                    symbolOffset = symbolOffset.Rotate(-viewport.Rotation);
                }
            }

            // Save state of the canvas, so we could move and rotate the canvas
            canvas.Save();

            // Move 0/0 to the Anchor point of Callout
            canvas.Translate((float)(x - symbolOffset.X), (float)(y - symbolOffset.Y));
            canvas.Scale((float)calloutStyle.SymbolScale, (float)calloutStyle.SymbolScale);

            // 0/0 are assumed at center of image, but Picture has 0/0 at left top position
            canvas.RotateDegrees(rotation);
            canvas.Translate((float)calloutStyle.Offset.X, (float)calloutStyle.Offset.Y);

            using var skPaint = new SKPaint()
                  {
                      IsAntialias = true
                  };
            canvas.DrawPicture(picture, skPaint);

            canvas.Restore();

            return(true);
        }
Example #2
0
        public static void Draw(SKCanvas canvas, IReadOnlyViewport viewport,
                                float opacity, double x, double y, CalloutStyle calloutStyle)
        {
            if (calloutStyle.BitmapId < 0 || calloutStyle.Invalidated)
            {
                if (calloutStyle.Content < 0 && calloutStyle.Type == CalloutType.Custom)
                {
                    return;
                }

                if (calloutStyle.Invalidated)
                {
                    UpdateContent(calloutStyle);
                }

                RenderCallout(calloutStyle);
            }

            // Now we have the complete callout rendered, so we could draw it
            if (calloutStyle.BitmapId < 0)
            {
                return;
            }

            var picture = (SKPicture)BitmapRegistry.Instance.Get(calloutStyle.BitmapId);

            // Calc offset (relative or absolute)
            MPoint symbolOffset = calloutStyle.SymbolOffset.ToPoint();

            if (calloutStyle.SymbolOffset.IsRelative)
            {
                symbolOffset.X *= picture.CullRect.Width;
                symbolOffset.Y *= picture.CullRect.Height;
            }

            var rotation = (float)calloutStyle.SymbolRotation;

            if (viewport.Rotation != 0)
            {
                if (calloutStyle.RotateWithMap)
                {
                    rotation += (float)viewport.Rotation;
                }
                if (calloutStyle.SymbolOffsetRotatesWithMap)
                {
                    symbolOffset = symbolOffset.Rotate(-viewport.Rotation);
                }
            }

            // Save state of the canvas, so we could move and rotate the canvas
            canvas.Save();

            // Move 0/0 to the Anchor point of Callout
            canvas.Translate((float)(x - symbolOffset.X), (float)(y - symbolOffset.Y));
            canvas.Scale((float)calloutStyle.SymbolScale, (float)calloutStyle.SymbolScale);

            // 0/0 are assumed at center of image, but Picture has 0/0 at left top position
            canvas.RotateDegrees(rotation);
            canvas.Translate((float)calloutStyle.Offset.X, (float)calloutStyle.Offset.Y);

            using var skPaint = new SKPaint()
                  {
                      IsAntialias = true
                  };
            canvas.DrawPicture(picture, skPaint);

            canvas.Restore();
        }