Data Binding
When displaying a map, you might also want to visualize some data on it in the form of hot spots, pin points, etc. As showed in the topics under the Information Layer section, you can declare them as static objects. However, the InformationLayer object allows you to dynamically load and display map markers via data binding.
To learn more about the InformationLayer class and its usage read this topic.
In order to display your map data dynamically you just have to treat the InformationLayer as a typical ItemsControl. This means you have to use its ItemsSource and ItemTemplate properties. You can also make a use of the ItemTemplateSelector property, in order to implement advanced visualization depending on the data item.
There are two approaches you can use:
Using Data Binding in the DataTemplate
When loading your map data dynamically there are several attached properties that you can use in order to position and display the marker on its proper place:
MapLayer.Location - represents the latitude and the longitude of the map point.
MapLayer.BaseZoomLevel - represents the zoom level of the map for which the marker should have its normal size.
MapLayer.ZoomRange - represents a range of zoom levels on which the marker should appear.
To learn more about the usage of these properties read this topic.
In order to provide the needed data to your RadMap control, you have to create a collection of business objects, which represent the desired data.
The business object and the sample data for this example can be found at the end of the topic.
The next step is to define the ItemTemplate for the information layer and set the desired bindings in it. In the current example, the marker will be represented by an ellipse marked as a Hot Spot.
The last thing to do is to set the ItemsSource property of the InformationLayer. This has to be done after the initialization of the map provider, otherwise the marker elements will appear before the map has loaded. For this purpose you have to use the InitializationCompleted event, which get raised after the initialization of the map provider completes.
The code for the GetMapData() method can be found at the end of the topic.
As a result you should be able to see the markers on your RadMap.
Using DataMappings
By using this approach you have to define mappings between the data fields and the respective MapLayer properties. This is done by creating the respective DataMapping objects and adding them to the DataMappings collection of the InformationLayer.
The DataMember enumeration used for the ValueMember value allows you to map not only the Location, ZoomLevel and ZoomRange. You can also map Latitude, Longitude, ZoomRangeMin and ZoomRangeMax. Which means that your business object can provide simple double properties for these values instead of the complex Location and ZoomRange ones.
In this example, the same ItemTemplate, business object and sample data will be used as in the example from the previous section of this topic.
The code for the business object and for the sample data can be found at the end of the topic.
To learn how and when to set the ItemsSource of the InformationLayer, please read the previous section.
Finally here is the code for the business object and the GetMapData() method.