Example #1
0
 public static void DrawMultiPoint(Graphics graphics, MultiPoint points, Styles.IStyle style, IViewport viewport)
 {
     foreach (Point point in points)
     {
         DrawPoint(graphics, point, style, viewport);
     }
 }
Example #2
0
        public static void DrawPoint(Graphics graphics, Point point, Styles.IStyle style, IViewport viewport)
        {
            var vectorStyle = (Styles.SymbolStyle)style;

            if (vectorStyle.Symbol == null)
            {
                throw  new ArgumentException("No bitmap symbol set in Gdi rendering");                             //todo: allow vector symbol
            }
            Bitmap symbol      = vectorStyle.Symbol.Convert();
            var    symbolscale = vectorStyle.SymbolScale;
            PointF offset      = vectorStyle.SymbolOffset.Convert();
            var    rotation    = vectorStyle.SymbolRotation;

            if (point == null)
            {
                return;
            }
            if (symbol == null)
            {
                symbol = DefaultSymbol;
            }

            PointF dest = ConvertPoint(viewport.WorldToScreen(point));

            if (rotation != 0 && !double.IsNaN(rotation))
            {
                graphics.TranslateTransform(dest.X, dest.Y);
                graphics.RotateTransform((float)rotation);
                graphics.TranslateTransform((int)(-symbol.Width / 2.0), (int)(-symbol.Height / 2.0));
                if (symbolscale == 1f)
                {
                    graphics.DrawImageUnscaled(symbol, (int)(dest.X - symbol.Width / 2.0 + offset.X), (int)(dest.Y - symbol.Height / 2.0 + offset.Y));
                }
                else
                {
                    var width  = symbol.Width * symbolscale;
                    var height = symbol.Height * symbolscale;
                    graphics.DrawImage(symbol, (int)(dest.X - width / 2 + offset.X * symbolscale), (int)(dest.Y - height / 2 + offset.Y * symbolscale), (float)width, (float)height);
                }
            }
            else
            {
                if (symbolscale == 1f)
                {
                    graphics.DrawImageUnscaled(symbol, (int)(dest.X - symbol.Width / 2.0 + offset.X), (int)(dest.Y - symbol.Height / 2.0 + offset.Y));
                }
                else
                {
                    var width  = symbol.Width * symbolscale;
                    var height = symbol.Height * symbolscale;
                    graphics.DrawImage(symbol, (int)(dest.X - width / 2 + offset.X * symbolscale), (int)(dest.Y - height / 2 + offset.Y * symbolscale), (float)width, (float)height);
                }
            }
        }
Example #3
0
        public static bool DoRender(this Styles.IStyle self, Graphics g, Map map)
        {
            if (!self.Enabled)
            {
                return(false);
            }

            var compare = self.VisibilityUnits == Styles.VisibilityUnits.ZoomLevel
                ? map.Zoom
                : map.GetMapScale((int)g.DpiX);

            if (self.MinVisible <= compare || compare <= self.MaxVisible)
            {
                return(false);
            }

            return(true);
        }
Example #4
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);
        }