location range within shapes

3 posts, 0 answers
  1. Donna
    Donna avatar
    12 posts
    Member since:
    Dec 2010

    Posted 07 Feb 2011 Link to this post

    Is it possible, once a shape is drawn on the map, to be able to determine any pin points that fall within the shape?
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 09 Feb 2011 Link to this post

    Hi Donna,

    The information layer contains the GetElementsInRectangle method. You can use it to get pin points within the geographical bounds of the MapShape. Also you can select the pin points which are inside the shape using the InformationLayer.GetItemsInLocation method.
    The sample GetPinPointsInShape method is below.
    private Collection<MapPinPoint> GetPinPointsInShape(MapShape shape)
    {
        Collection<MapPinPoint> points = new Collection<MapPinPoint>();

        
    var shapes = this.informationLayer.GetElementsInRectangle(shape.GeographicalBounds);
        foreach (object item in shapes)
        {
            MapPinPoint point = item as MapPinPoint;
            if (point != null && this.IsLocationInShape(shape, MapLayer.GetLocation(point)))
            {
                points.Add(point);
            }
        }

        
    return points;
    }

    private
    bool IsLocationInShape(MapShape shapeToTest, Location location)
    {
        bool isInShape = false;

        
    IEnumerable<object> list = this.informationLayer.GetItemsInLocation(location);
        foreach (object item in list)
        {
            MapShape shape = item as MapShape;
            if (shape != null && shape == shapeToTest)
            {
                isInShape = true;
                break;
            }
        }

        
    return isInShape;
    }

    Best wishes,
    Andrey Murzov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. DevCraft banner
  4. Donna
    Donna avatar
    12 posts
    Member since:
    Dec 2010

    Posted 09 Feb 2011 Link to this post

    This works for me. Thank you very much!
Back to Top