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

Query Items within a Polygon

3 Answers 36 Views
Map
This is a migrated thread and some comments may be shown as answers.
Mark Jakes
Top achievements
Rank 1
Mark Jakes asked on 07 Dec 2011, 02:21 AM

Hello

I am using UriImageProvider and have an MVVM bound set of objects displayed in an InformationLayer, all is working well but I need to display a collection that that falls with-in a user defined polygon.

I have seen this post which describes how to do this within a rectangle but can't see how to do this for a Polygon?

Any clues?

Many thanks

Mark.

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 09 Dec 2011, 01:28 PM
Hi Mark Jakes,

The post you've referred to demonstrates an approach which can be used to detect points in any map shape object, not rectangle only. It shows how 2 methods from the InformationLayer (GetElementsInRectangle and GetItemsInLocation) can be used to list points that fall within any map shape object.

Best regards,
Andrey Murzov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Mark Jakes
Top achievements
Rank 1
answered on 09 Dec 2011, 02:24 PM
Hi Andrey

Thanks for your reply.  The reason for posting the question was that when I use these routines, they return objects outside of my polygon, equal (I think) to the Location rect.

To explain, I draw the polygon on one layer (background), and use the Poloygon as the parameter to the GetPinPointsInShape(MapShape shape)method from objects in a RIA collection, using MapLayer.SetLocation(object), but it clearly only returns the items with a boundary which looks like a rectangle with objects outside of the polygon area.

I guess I am using the polygon incorrectly as the parameter.  Here is some (not very efficient) test code I used to test...

InformationLayer tempLayer = new InformationLayer();
tempLayer.MapControl = MapControl; 
_polygon.Points = GetPolygonPoints(testPolygon);  // grabs polygon points from class

foreach (Asset o in _allAssets) 
    MapPinPoint pp = new MapPinPoint(); 
    pp.Tag = o; 
          
    tempLayer.Items.Add(pp); 
    MapLayer.SetLocation(pp, new Location(o.Asset_Lattitude, o.Asset_Longtitude)); 
    
                    
var shapes = tempLayer.GetElementsInRectangle(_polygon.GeographicalBounds); 
foreach (MapPinPoint item in shapes) 
    InformationLayerAssets.Add(item.Tag); 
tempLayer.Items.Clear();


Could you show me an example of say, showing items within a triangle to get me started?

Actually, I would rather only populate with items that fall within the polygon region, rather than add them all to a tempoary layer and then repopulate with a filtered set,  as shown above, but this was really just for testing purposes.  

Are there any routines that don't involve the UI to perform the calculation, this would be useful for our MVVM pattern, something like pseudo code

List<Locations> LocationsInRegion = Get_Items_In_Region( polygon_region, AllLocations<Locations>  )

Apologies if this seems a bit simpleton, but I have not worked with the Map control before and I am still learning its capabilities.

Thanks

Mark.
0
Andrey
Telerik team
answered on 14 Dec 2011, 08:56 AM
Hello Mark Jakes,

First all, in your code I don't see anything wich looks like the code in this post. Simple copy-paste whole code from it in your application (both GetPinPointsInShape and IsLocationInShape methods). Then use GetPinPointsInShape for your purposes.

Next, these methods require that pin points and shape will be on screen already. Otherwise it will not work. Similar to any other ItemsControl the information layer takes some time to process all shapes and pin points in the list and show them over the map. So if you try to use this method right after adding the items into information layer, then it will not work, because at this moment elements aren't on the screen yet.

As I can see from your code you create a temporary information layer, but never add it to the RadMap control, so all elements from it will never be shown on the screen. In this case nothing will work. The shape and pin points must be on screen to get this things to work. I also couldn't find out where do you add a shape (polygon) to the information layer. 

Unfortunately there is no way to do this task without using the UI to perform the calculation.

Best wishes,
Andrey Murzov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Map
Asked by
Mark Jakes
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Mark Jakes
Top achievements
Rank 1
Share this question
or