Is there a way how I can get the actual path/ring clicked rather than the whole feature?
void graphicsLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs e)
{
var clicked = Map.ScreenToMap(e.GetPosition(Map));
var polygon = (Polygon)e.Graphic.Geometry;
foreach(var ring in polygon.Rings)
if (Intterra.Projection.Utilities.PointIsInGeometry(ring, clicked))
{
//you found the correct ring
}
}
static bool PointIsInGeometry(PointCollection points, MapPoint point)
{
int i;
int j = points.Count - 1;
bool output = false;
for (i = 0; i < points.Count; i++)
{
if (points.X < point.X && points.X >= point.X || points.X < point.X && points.X >= point.X)
{
if (points.Y + (point.X - points.X) / (points.X - points.X) * (points.Y - points.Y) < point.Y)
{
output = !output;
}
}
j = i;
}
return output;
}
void Graphics_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action != NotifyCollectionChangedAction.Add) return;
var gc = (GraphicCollection)sender;
foreach (var item in e.NewItems)
{
var g = (Graphic) item;
if (!(g.Geometry is Polygon) || ((Polygon) g.Geometry).Rings.Count <= 1) continue;
var p = (Polygon) g.Geometry;
Dispatcher.BeginInvoke(() =>
{
foreach (var ring in p.Rings)
{
var newg = new Graphic {Geometry = new Polygon {SpatialReference = p.SpatialReference}};
foreach (var a in g.Attributes) newg.Attributes.Add(a);
((Polygon)newg.Geometry).Rings.Add(ring);
gc.Add( newg );
}
gc.Remove(g);
});
}
}