This is a migrated thread and some comments may be shown as answers.

MapShape Intersections

2 Answers 77 Views
Map
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 03 Dec 2010, 05:08 PM
I would like to more accurately determine if a Location is in a MapShape, or whether two MapShape intersect each other.

At present, I use something like

LocationRect? selectionRect = null;
foreach(MapShape shape in Items)
{
  LocationRect shapeLocationRect = shape.GeographicalBounds;
  shapeLocationRect.MapControl = MapControl;
  if (shapeLocationRect.Contains(location))
  {
    selectionRect = shapeLocationRect;
    break;
  }
}

This only uses the bounding rectangle, so if I have a MapPolygon, then I can possibly get a hit outside of the actual shape boundaries

The problem becomes more compounded when I need to look for the intersection of two shapes

foreach (var layerItem in layer.Items)
{
    if (layerItem is MapShape)
    {
        MapShape mapShape = (MapShape)layerItem;
        if (selectionRect.HasValue && mapShape.GeographicalBounds.Intersect(selectionRect.Value))
        {
        }
    }
}

One point to note is that because I only have MapPolygons ort MapPaths in my layer I can check the GeographicalBounds for the Intesection.  If I have MapRectangles or MapEllipses then I do not get a hit, unless I set the MapControl.

Hope you can help
Thanks
Simon

2 Answers, 1 is accepted

Sort by
0
Accepted
Andrey
Telerik team
answered on 08 Dec 2010, 07:47 PM
Hello Simon,

To detect whether a location is inside the shape you can use code similar to the following:

private bool IsInShape(Location location, MapShape desiredShape) 
    bool isInside = false
    
    IEnumerable<object> list = this.informationLayer.GetItemsInLocation(location); 
    foreach (object item in list) 
    
        MapShape shape = item as MapShape; 
        if (shape != null && shape == desiredShape) 
        
            isInside = true
            break
        
    
    return isInside; 
  
  
private MapShape GetShapeByLocation(Location location) 
    MapShape containedShape = null;
    
    IEnumerable<object> list = this.informationLayer.GetItemsInLocation(location); 
    foreach (object item in list) 
    
        MapShape shape = item as MapShape; 
        if (shape != null
        
            containedShape = shape;
            break
        
    
  
    return containedShape;

Unfortunately there is no better approach to detect intersection of 2 map shapes currently and this task does not seem to be a trivial one. For now we do not have plans to implement this functionality, but I will make sure it is reconsidered when discussing our future plans.

All the best,
Andrey Murzov
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Simon
Top achievements
Rank 1
answered on 14 Dec 2010, 04:39 PM
Thanks for the solution above.

For intersecting mapshapes I recreated the same MapGeometry in Geometry, and then used the FillContainsWithDetail method
Tags
Map
Asked by
Simon
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Simon
Top achievements
Rank 1
Share this question
or