Using the OverlayManager with Silverlight Maps

Tags: Bing, Maps, Silverlight, OverlayManager, KML

Deciding to switch to Microsoft's Silverlight map control was not without concern. While it is a great platform for displaying maps in Silverlight and gives you the full rich Silverlight UI engine, it does lack some user friendliness. One of the problems with getting started with Silverlight (or WPF) is the overwhelming amount of options you suddenly have. But with all these options come the requirement to manage them. This was one of my first concerns with the Silverlight map control. While it allows you to display rich overlays on the map relatively easy, it doesn't provide you with an easy interface to handle the overlays.

This is why I created the OverlayManager. It hooks on to a map and handles how to display overlays, and order them so your polygon does not cover all your markers, etc. It does this by having it's own layers (MapLayer) so it can easily order overlays by type. To use the OverlayManager, since create it and pass in the map you want it to hook on to, like so:


OverlayManager manager = new OverlayManager(map);

Now you are ready to create your overlays. Here we just create a circle and put it on the map:


Ellipse circle = new Ellipse { Width = 10, Height = 10, Fill = new SolidColorBrush(Colors.Green) };
manager.Add(circle, new Location(51.47,0.0));

As you can see you don't actually add it to the map, but instead add it to the OverlayManager, which in turns figures out how to plot it. You don't have to worry about attached properties and so on.

Another thing I found missing with the map control is the lack of KML support, so I added that to the OverlayManager as well. KML is the current standard for exchanging geographic data, so I was surprised that it was not included. However the OverlayManager makes it easy to read and write compliant KML, simply pass your KML document to the ReadKml method and it will read through it and create the overlays that are compatible with the Silverlight map control.


string kml = "your kml document";

I will go into more detail about the more advanced features, KML styling, displaying infowindows, etc, of the OverlayManager in later posts.

Latest Tweets