1

Closed

WPF GMapPolygon has hard-coded fill effects

description

Inside of GMapControl.cs the myPath has hard-coded values. This prevents the user from being able to customize any GMapPolygon properties such as color, stroke thickness etc.


// Create a path to draw a geometry with.
     Path myPath = new Path();
     {
        // Specify the shape of the Path using the StreamGeometry.
        myPath.Data = geometry;

        if (addBlurEffect)
        {
            BlurEffect ef = new BlurEffect();
            {
                ef.KernelType = KernelType.Gaussian;
                ef.Radius = 3.0;
                ef.RenderingBias = RenderingBias.Performance;
            }

            myPath.Effect = ef;
        }

        myPath.Stroke = Brushes.MidnightBlue;
        myPath.StrokeThickness = 5;
        myPath.StrokeLineJoin = PenLineJoin.Round;
        myPath.StrokeStartLineCap = PenLineCap.Triangle;
        myPath.StrokeEndLineCap = PenLineCap.Square;

        myPath.Fill = Brushes.AliceBlue;

        myPath.Opacity = 0.6;
        myPath.IsHitTestVisible = false;
     }
     return myPath;
Closed Jul 26, 2016 at 8:22 PM by radioman
override f*** function

public virtual Path CreatePolygonPath(List<Point> localPath, bool addBlurEffect)

comments

MikeOldHouse wrote Aug 4, 2016 at 9:51 PM

Well radioman...

When wants to draw a polygon via "GMapPolygon" we do not have access to said field, because of this "var shape = map.CreatePolygonPath(localPath);"

Thanks for being an a** hole
public class GMapPolygon : GMapMarker, IShapable
    {
        public readonly List<PointLatLng> Points = new List<PointLatLng>();

        public GMapPolygon(IEnumerable<PointLatLng> points)
        {
            Points.AddRange(points);
            RegenerateShape(null);
        }
        
        public override void Clear()
        {
            base.Clear();
            Points.Clear();
        }

        /// <summary>
        /// regenerates shape of polygon
        /// </summary>
        public virtual void RegenerateShape(GMapControl map)
        {
             if(map != null)
             {
                this.Map = map;
                 
                if(Points.Count > 1)
                {
                   Position = Points[0];
                   
                   var localPath = new List<System.Windows.Point>(Points.Count);
                   var offset = Map.FromLatLngToLocal(Points[0]);
                   foreach(var i in Points)
                   {
                      var p = Map.FromLatLngToLocal(i);
                      localPath.Add(new System.Windows.Point(p.X - offset.X, p.Y - offset.Y));
                   }
    
                   var shape = map.CreatePolygonPath(localPath);
    
                   if(this.Shape is Path)
                   {
                      (this.Shape as Path).Data = shape.Data;
                   }
                   else
                   {
                      this.Shape = shape;
                   }
                }
                else
                {
                   this.Shape = null;
                }
             }
        }
    }