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.
11/28/2009 11:03:39 PM #
מקלחון חזית
מקלחון פינתי
מקלחון זכוכית
מקלחון מעוגל
מקלחון
מקלחונים
12/2/2009 2:34:20 AM #
צימר לדתיים
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 12:29:51 AM #
Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck!
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/24/2009 11:12:11 PM #
This is a really good read for me, Must admit that you are one of the best bloggers I ever saw.Thanks for posting this informative article.
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/11/2010 8:37:14 AM #
I have been surfing online more than three hours today, yet I never found any interesting article like yours. It's pretty worth enough for me. In my opinion, if all webmasters and bloggers made good content as you did, the internet will be much more useful than ever before.
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/14/2010 6:50:33 AM #
There are certainly a lot of details like that to take into consideration. That is a great point to bring up. I offer the thoughts above as general inspiration but clearly there are questions like the one you bring up where the most important thing will be working in honest good faith. I don?t know if best practices have emerged around things like that, but I am sure that your job is clearly identified as a fair game.
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 5:14:37 AM #
Aw, this was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article... but what can I say... I procrastinate alot and never seem to get something done.
1/17/2010 5:56:09 AM #
Thank you for the sensible critique. Me & my neighbour were preparing to do some research about that. We got a good book on that matter from our local library and most books where not as influensive as your information. I am very glad to see such information which I was searching for a long time.This made very glad Smile
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/22/2010 10:33:46 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 is the old what goes around comes around routine. Did you acquired lots of links and I see lots of trackbacks??
1/24/2010 6:30:25 PM #
Thank you for the sensible critique. Me & my neighbour were preparing to do some research about that. We got a good book on that matter from our local library and most books where not as influensive as your information. I am very glad to see such information which I was searching for a long time.This made very glad Smile
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.
1/31/2010 6:47:59 AM #
Keep 'em coming... you all do such a great job at such Concepts... can't tell you how much I, for one appreciate all you do!
2/2/2010 3:17:17 AM #
Keep 'em coming... you all do such a great job at such Concepts... can't tell you how much I, for one appreciate all you do!
SEO
2/2/2010 8:40:08 PM #
Interesting read, thanks for helping keep me busy at work ..
2/3/2010 5:23:34 AM #
Great post! I am just starting out in community management/marketing media and trying to learn how to do it well - resources like this article are incredibly helpful. As our company is based in the US, it?s all a bit new to us. The example above is something that I worry about as well, how to show your own genuine enthusiasm and share the fact that your product is useful in that case.
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.
2/11/2010 12:06:43 AM #
Valuable information and excellent design you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!! Thumbs up
Comments are closed