MapShape Intersections

3 posts, 1 answers
  1. Simon
    Simon avatar
    34 posts
    Member since:
    Oct 2010

    Posted 03 Dec 2010 Link to this post

    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. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 08 Dec 2010 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Simon
    Simon avatar
    34 posts
    Member since:
    Oct 2010

    Posted 14 Dec 2010 Link to this post

    Thanks for the solution above.

    For intersecting mapshapes I recreated the same MapGeometry in Geometry, and then used the FillContainsWithDetail method
Back to Top