Select to view content in your preferred language

Binding aplication defrined data in a layer

841
3
08-11-2010 01:03 AM
surjithu
New Contributor
Hi All,

I see that in the samples given data like city name population are retrieved through the function in the sdk and binds it to the layers.
I would like to know is there a method to display application defined data in the layers above the map?

I need to retrieve some information from the application's database and display them on top of the map, for example suppose if I just want to display number of hospitals in each city, how can I do that.

I'm using Silverlight sdk version 2.0

Thanks,
Surjith
0 Kudos
3 Replies
AliMirzabeigi
Emerging Contributor
You can add an attribute to the attribute collection of your layer when the graphic collection of your layer changes, i.e. assuming that you've already populated your application specific data in a class, say Cities, use the "CollectionChanged" event handler of "Graphics" in your leyer and add appropriate attribute to each graphic with the value you're retrieving from your class. That would be something similar to the following code snippet:
private void Graphics_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
     Graphic graphic = e.NewItems[0] as Graphic;
     graphic.Attributes.Add("NumberOfHospitals", Cities.NumberOfHospitals);
}


Hope this helps.
0 Kudos
ChristopherHill
Deactivated User
If you are getting a set of hospitals and cities, then it sounds like you are need to make an aggregation of the data that is being loaded. I am assuming that your using a feature layer and that it loads all hostipals and the city that they belong to. assuming also that you don't want to make any additional request to the server to build your sub-set of data. on UpdateCompleted you can use a Linq query to build a Dictionary<string,int> your Key would be "City" your int would be "Count" you can add entries into the dictionary. I am not sure if you intend on showing all results at one time or just one at a time. If you intended on using binding you might want to make a class to hold the data instead. List<HospitalsByCity> where class is defined

private class HospitalByCity
{
    string City, //create dependancy property
    int Count //create dependancy property
}
0 Kudos
surjithu
New Contributor
Ali& Christopher Thank you very much
0 Kudos