Skip to content

Commit

Permalink
GMap.NET.WindowsPresentation: RegenerateShape fix
Browse files Browse the repository at this point in the history
  • Loading branch information
radioman committed May 31, 2018
1 parent 2bb23a7 commit 267f756
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,42 @@ void ForceUpdateOverlays()
ForceUpdateOverlays(ItemsSource);
}

/// <summary>
/// regenerates shape of route
/// </summary>
public virtual void RegenerateShape(IShapable s)
{
var marker = s as GMapMarker;

if(s.Points != null && s.Points.Count > 1)
{
marker.Position = s.Points[0];

var localPath = new List<System.Windows.Point>(s.Points.Count);
var offset = FromLatLngToLocal(s.Points[0]);
foreach(var i in s.Points)
{
var p = FromLatLngToLocal(i);
localPath.Add(new System.Windows.Point(p.X - offset.X, p.Y - offset.Y));
}

var shape = s.CreatePath(localPath, true);

if(marker.Shape is Path)
{
(marker.Shape as Path).Data = shape.Data;
}
else
{
marker.Shape = shape;
}
}
else
{
marker.Shape = null;
}
}

void ForceUpdateOverlays(System.Collections.IEnumerable items)
{
using(Dispatcher.DisableProcessing())
Expand All @@ -799,7 +835,7 @@ void ForceUpdateOverlays(System.Collections.IEnumerable items)

if(i is IShapable)
{
(i as IShapable).RegenerateShape();
RegenerateShape(i as IShapable);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,29 @@ namespace GMap.NET.WindowsPresentation

public class GMapPolygon : GMapMarker, IShapable
{
public readonly List<PointLatLng> Points = new List<PointLatLng>();

public GMapPolygon(IEnumerable<PointLatLng> points)
{
Points.AddRange(points);
RegenerateShape();
Points = new List<PointLatLng>(points);
}

public override void Clear()
public List<PointLatLng> Points
{
base.Clear();
Points.Clear();
get;
set;
}

/// <summary>
/// regenerates shape of polygon
/// </summary>
public virtual void RegenerateShape()
public override void Clear()
{
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 = CreatePolygonPath(localPath, true);

if(this.Shape is Path)
{
(this.Shape as Path).Data = shape.Data;
}
else
{
this.Shape = shape;
}
}
else
{
this.Shape = null;
}
base.Clear();
Points.Clear();
}

/// <summary>
/// <summary>
/// creates path from list of points, for performance set addBlurEffect to false
/// </summary>
/// <param name="pl"></param>
/// <returns></returns>
public virtual Path CreatePolygonPath(List<Point> localPath, bool addBlurEffect)
public virtual Path CreatePath(List<Point> localPath, bool addBlurEffect)
{
// Create a StreamGeometry to use to specify myPath.
StreamGeometry geometry = new StreamGeometry();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +1,48 @@

namespace GMap.NET.WindowsPresentation
{
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Shapes;

public interface IShapable
{
void RegenerateShape();
List<PointLatLng> Points
{
get; set;
}

Path CreatePath(List<System.Windows.Point> localPath, bool addBlurEffect);
}

public class GMapRoute : GMapMarker, IShapable
{
public readonly List<PointLatLng> Points = new List<PointLatLng>();

public GMapRoute(IEnumerable<PointLatLng> points)
{
Points.AddRange(points);
RegenerateShape();
Points = new List<PointLatLng>(points);
}

public override void Clear()
public List<PointLatLng> Points
{
base.Clear();
Points.Clear();
get;
set;
}

/// <summary>
/// regenerates shape of route
/// </summary>
public virtual void RegenerateShape()
public override void Clear()
{
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 = CreateRoutePath(localPath, true);

if(this.Shape is Path)
{
(this.Shape as Path).Data = shape.Data;
}
else
{
this.Shape = shape;
}
}
else
{
this.Shape = null;
}
base.Clear();
Points.Clear();
}

/// <summary>
/// creates path from list of points, for performance set addBlurEffect to false
/// </summary>
/// <param name="pl"></param>
/// <returns></returns>
public virtual Path CreateRoutePath(List<System.Windows.Point> localPath, bool addBlurEffect)
public virtual Path CreatePath(List<System.Windows.Point> localPath, bool addBlurEffect)
{
// Create a StreamGeometry to use to specify myPath.
StreamGeometry geometry = new StreamGeometry();
Expand Down

0 comments on commit 267f756

Please sign in to comment.