Saturday, December 18, 2010

An MVVM Version of Bing Maps with Google / Yahoo / Open Street Maps integrated

I was working with Bing Maps when I found that ZoomLevel and BoundingRect were not Dependency Properties. However you can easily make them since it exposed the ViewChangeEnd event.

Also I wanted to wrap up various types of maps in a simple to use control. I got the tile sources from here
http://pietschsoft.com/post/2010/06/14/Display_Google_Maps_Imagery_using_Bing_Maps_Silverlight_Control.aspx
I just had to update the Satellite view to the latest version since the khm source no longer works.

I made a UserControl out of it. Shared it here : (SourceCodehttp://code.google.com/p/mvvmslmaps/downloads/list
In Action:

Lessons Learned
Just one: I add a MapItemsLayer to the maps in my application so I wanted to redirect the Content Property of the custom UserControl to the Content Property of my bing maps instance.

It was super easy to do :

  • Added the attribute : [ContentProperty("Children")] to your Control. 
  • Added the following as a property : 
             public UIElementCollection Children
            {
                get { return MyMap.Children; }
            }

    This means that when I add a MapItemsControl :

    <Control:MVVMMapControl x:Name="MyMap"> 
                <m:MapItemsControl x:Name="ListOfItems" ItemsSource="{Binding Sites}" ItemTemplate="{StaticResource CellTemplate}" ></m:MapItemsControl> 
            </Control:MVVMMapControl>


    It gets added as a child of my bing maps instance.

    No comments:

    Post a Comment