Select to view content in your preferred language

How to display a polygon in Silverlight and ESRI maps from xml file

3182
4
08-20-2010 11:14 AM
JohnHarvey
Emerging Contributor
I am a relative newby to Silverlight. I have done maps using Google's api to display polygons which are contained in an xml file, but I am lost as to how to make this happen here. Can someone show me how to add https://kiosk.memphispolice.org/mpdwards.xml into a map? This is a list of MPD precincts.

Thanks,

John Harvey
0 Kudos
4 Replies
MartenLiebster
Deactivated User
I am a relative newby to Silverlight. I have done maps using Google's api to display polygons which are contained in an xml file, but I am lost as to how to make this happen here. Can someone show me how to add https://kiosk.memphispolice.org/mpdwards.xml into a map? This is a list of MPD precincts.

Thanks,

John Harvey


Are you planing to get the file every client request?  If so, you would need to use the WebClient or HTTPRequest functionality built into SL to get the xml file from their sever.

Afterwards, you should be able to simply parse out the points into PointCollection(s), LinqToXML can be used to make this an easier task.

Then just add the Polygons with the collections to a GraphicsLayer.

**

Or if the dataset is rather static, then you could save the data to your database. When you want to show the map, then retrieve the points from the DB and build polygons from that. Or you could use IsolatedStorage to save a cache copy of the XML file data.
0 Kudos
JenniferNery
Esri Regular Contributor
You can use WebClient DownloadStringAsync and parse the result into an XDocument. Based on the XML you provided, it seems like you can use a GraphicsLayer with UniqueValueRenderer (Attribute="precinct") that uses SimpleFillSymbol. Your UniqueValueRendererInfos will have a different color per precinct value.  By setting the renderer, you do not have to create a symbol on individual graphics. But you will still need to create each graphic based on the ward information you just parsed so that each ward becomes a graphic in your GraphicsLayer with geometry from the given pointcollection, and attributes from the given "name" and "precinct" values.

You can look at our SDK samples for guide: esriurl.com/slsdk2.

Good luck.
0 Kudos
JohnHarvey
Emerging Contributor
You can use WebClient DownloadStringAsync and parse the result into an XDocument. Based on the XML you provided, it seems like you can use a GraphicsLayer with UniqueValueRenderer (Attribute="precinct") that uses SimpleFillSymbol. Your UniqueValueRendererInfos will have a different color per precinct value.  By setting the renderer, you do not have to create a symbol on individual graphics. But you will still need to create each graphic based on the ward information you just parsed so that each ward becomes a graphic in your GraphicsLayer with geometry from the given pointcollection, and attributes from the given "name" and "precinct" values.

You can look at our SDK samples for guide: esriurl.com/slsdk2.

Good luck.


Thanks Jennifer. I will take a look at the sdk sample.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
The closest sample is the 'Show GeoRss feed' sample : http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#GeoRSS

In this sample, there is commented part of the code using LINQ to read a XML file.
0 Kudos