Display OpenStreetMap Imagery using Bing Maps Silverlight Control v1

12. November 2009

BingMapsSilverlight_OpenStreetMap The Bing Maps Silverlight SDK documentation on MSDN contains an article on Adding Tile Overlays to the Map, that demonstrates how to overlay your own map imagery over top of the Bing Maps Imagery. However, what if you want to completely replace the Bing Maps Imagery with some other Imagery like the OpenStreeMap Imagery?

In the “Adding Tile Overlays to the Map” article it shows using a “LocationRectTileSource” to add the custom map imagery overlay. To implement the OpenStreetMap imagery you will need to create a simple class that inherits from “TileSource” since you wont be restricting the imagery to only a small portion of the map, but instead will be showing all the OpenStreetMap Imagery in place of the Bing Maps Imagery.

First, Hide the Bing Maps Imagery

Since we will be displaying the OpenStreetMap imagery instead of the Bing Maps Imagery, we want to prevent the Map control from loading/displaying the Bing Maps Imagery completely.

To do this, all you need to do is set the Maps Mode to an instance of the “MercatorMode” object:

<UserControl x:Class="BingMapsSilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
    xmlns:mCore="clr-namespace:Microsoft.Maps.MapControl.Core;assembly=Microsoft.Maps.MapControl">
    <Grid x:Name="LayoutRoot">
        <m:Map>
            <m:Map.Mode>
                <!-- Do Not Display Bing Maps Imagery -->
                <mCore:MercatorMode></mCore:MercatorMode>
            </m:Map.Mode>
        </m:Map>
    </Grid>
</UserControl>

 

Display OpenStreetMap Imagery

Next, we will create a simple “OpenStreetMapTileSource” class that inherits from “TileSource” that will be used to specify the location (URI) of the OpenStreetMap Imagery so the Map control can load and display it.

Here’s the simple OpenStreetMapTileSource class:

public class OpenStreetMapTileSource : Microsoft.Maps.MapControl.TileSource
{
    public OpenStreetMapTileSource()
        : base("http://tile.openstreetmap.org/{2}/{0}/{1}.png")
    {
    }

    public override System.Uri GetUri(int x, int y, int zoomLevel)
    {
        return new Uri(string.Format(this.UriFormat, x, y, zoomLevel));
    }
}

 

Now to put the OpenStreetMapTIleSource in place and actually display the OpenStreetMap Imagery. To do this, we will add a new MapTileLayer to the Maps Children collection, and add an instance of our OpenStreetMapTileSource object to the MapTileLayer objects TileSources collection.

Here’s the code to do this:

<UserControl x:Class="BingMapsSilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
    xmlns:mCore="clr-namespace:Microsoft.Maps.MapControl.Core;assembly=Microsoft.Maps.MapControl"
    xmlns:local="clr-namespace:BingMapsSilverlightApplication1">
    <Grid x:Name="LayoutRoot">
        <m:Map>
            <m:Map.Mode>
                <!-- Do Not Display Bing Maps Imagery -->
                <mCore:MercatorMode></mCore:MercatorMode>
            </m:Map.Mode>
            <m:Map.Children>
                <m:MapTileLayer>
                    <m:MapTileLayer.TileSources>
                        <!-- Display OpenStreetMap Imagery -->
                        <local:OpenStreetMapTileSource></local:OpenStreetMapTileSource>
                    </m:MapTileLayer.TileSources>
                </m:MapTileLayer>
            </m:Map.Children>
        </m:Map>
    </Grid>
</UserControl>

 

Conclusion

It’s really pretty simple to display your own custom map tile image sets and even completely replace the Bing Maps Imagery with the new control. If your interested in seeing how to display Yahoo Maps imagery within the control, then you’ll want to refer to my previous article on doing this with the CTP version of the Bing Maps Silverlight Control.

Bing Maps, Silverlight , , ,

Comments

11/15/2009 11:02:08 PM #
Very close Chris but you will still need to enter a Bing Maps AppID.
If however you create your own map from MapCore and don't use the Bing Maps services then you don't need creditials Smile
11/16/2009 6:47:30 AM #
Yes, I figures the Bing Maps App ID is a given since anyone getting past the "Getting Started" tutorial and on to this and other examples will know that they need an App ID.

However, creating a custom map that inherits MapCore is an interesting idea!
11/16/2009 7:41:50 AM #
Prototype of OpenStreetMap Silverlight Control using DeepEarth and Bing Maps SDK

Prototype of OpenStreetMap Silverlight Control using DeepEarth and Bing Maps SDK
11/16/2009 7:44:52 AM #
I built out a small, basic example of inheriting MapCore as suggested by John here:

pietschsoft.com/.../...Maps_SDK_and_DeepEarth.aspx
11/16/2009 8:35:48 PM #
Hmmm that was weird, my comment got eaten. Anyway I wanted to say thanks for the update.
12/6/2009 5:01:56 PM #
Thank you for the helpful information.
12/10/2009 5:31:36 PM #
Interesting ... as always - is your blog making any cash advance ? ;)
12/17/2009 3:44:50 PM #
Thanks a lot buddy thanks a lot for providing such a great assistance.
12/21/2009 4:02:28 AM #
This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It’s the old what goes around comes around routine.
12/29/2009 3:19:24 PM #
Just try to smile for about 2-3 mins then you can get back to work
12/31/2009 9:45:58 PM #
I love reading your posts. I wish you a Happy New Year!
1/5/2010 8:49:30 AM #
Nice post! keep up the good work.
1/14/2010 12:25:25 AM #
Professional IT services consisting of custom software development, website design and maintenance, search engine optimization, pay-per-click campaign management and implementation of other internet advertising initiatives for businesses worldwide.
1/16/2010 10:18:09 PM #
This article gives the light in which we can observe the reality. this is very nice one and gives indepth information.
1/17/2010 3:01:18 PM #
Jouez aux machines à sous, online slotmachines, jeux de grattage et à d'autres jeux de casino amusant sur Winagames.com.
1/17/2010 3:11:44 PM #
Le meilleur guide online aux jeux de casino, poker et bingo en ligne sur l'internet.
1/20/2010 8:26:01 AM #
Website Architecture – Good Website Architecture along with the Best Web Application and Web Services Architecture is provided by the WebbizDesigns.com. Build your own Website with the best Web Architect.
1/20/2010 12:12:37 PM #
Fight again using of asbestos to stop mesothelioma cancer
1/21/2010 11:14:29 AM #
WebBizIdeas.com is more than a website design company, webbizideas build internet businesses! Webbizideas specialize in website planning, web design, corporate identity, internet marketing, and internet business consulting. Webbizideas are very experienced in building Social Networking, eCommerce, CMS, and Corporate websites.
1/22/2010 5:28:40 AM #
Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts.
1/28/2010 5:06:41 AM #
Stormwater system for residential and commercial use - Stormwater management systems are eco friendly
1/28/2010 7:27:02 AM #
This a little bit funny. I found your site via search engine a few moment ago, and luckily, this is the only information I was looking for the last hours.
1/28/2010 1:32:59 PM #
I have learned from experience that the greater part of our happiness or misery depends on our dispositions and not on our circumstances.
SEO
2/2/2010 8:40:08 PM #
Interesting read, thanks for helping keep me busy at work ..
2/3/2010 11:56:17 AM #
Really appreciate this post. It’s hard to sort the good from the bad sometimes, but I think you’ve nailed it!
2/3/2010 1:14:13 PM #
Sensational info. I look forward to seeing more...
2/7/2010 8:06:15 AM #
welcome
2/7/2010 8:06:49 AM #
2/9/2010 8:20:57 AM #
You will never find time for anything. If you want the time, you must make it.
2/10/2010 11:34:03 AM #
Webbizideas offers best services for your site optimization.It helps search engine friendly urls to rank better over search engines.