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

Find points inside polygon

3 Answers 168 Views
Map
This is a migrated thread and some comments may be shown as answers.
Esther
Top achievements
Rank 1
Esther asked on 24 Jan 2011, 04:52 PM
Hello,
I´ve a RadMap with several MapPinPoints on it. After drawing an ellipse I want to know how many point are inside this ellipse.
¿Which is the easiest way of doing that?
Thanks in advance,
Esther

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 26 Jan 2011, 08:55 AM
Hi Esther,

If ellipse is a map shape object (MapEllipse) which is visible over the map, then you can use following method to detect whether specified location is inside the shape:

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;
}

Then you can loop through the list of the objects and use this method to detect whether the object location is inside the specified shape.

Kind regards,
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>>
0
Esther
Top achievements
Rank 1
answered on 26 Jan 2011, 12:01 PM
Thanks for the reply.
The problem that I have now is that when I get the list of elements of the information layer, they are MapPinPoints and it fails when I do the cast to MapShape. TryCast returns Nothing. This is my code:

Private Function pr__IsLocationInShape(ByVal shapeToTest As MapShape, ByVal location As Location) As Boolean
       Dim isInShape As Boolean = False
       Try
           Dim list As IEnumerable(Of Object) = Me.m_c_marker_layer.GetItemsInLocation(location)
 
      
           For Each item As Object In list
               Dim shape As MapShape = TryCast(item, MapShape)
               If shape IsNot Nothing AndAlso shape.Equals(shapeToTest) Then
                   isInShape = True
                   Exit For
               End If
           Next
 
           Return isInShape
 
       Catch ex As Exception
 
           Return False
       End Try
   End Function
0
Accepted
Andrey
Telerik team
answered on 31 Jan 2011, 08:29 AM
Hello Esther,

It is the expected behavior. My C# and your VB.NET code looks for the MapShape object in the information layer. The information layer can contain objects of different types. If item from the layer can be casted to the MapShape the result will not be Nothing (null in C#) and we will be able to compare it with given map shape. Otherwise we just check next item.

As I've mentioned alredy the map shape object (MapEllipse) must be visible over the map. If you use 2 layers (one for pin points and second for ellipse), then you should call GetItemsInLocation method for the layer which contains MapEllipse (or other shape).

All the best,
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>>
Tags
Map
Asked by
Esther
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Esther
Top achievements
Rank 1
Share this question
or