PDA

View Full Version : Exceeding Standard Zoom-Levels in the Bing Maps Silverlight Control



Johannes Kebeck's Blog
06-09-2010, 03:16 PM
<p>With tools like the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=9BBF4A21-DA3A-4AE5-924B-E22D6F360122&displaylang=en">MapCruncher</a> it was always possible to create your own tile-layers and overlay them on top of the <a href="http://www.microsoft.com/maps/">Bing Maps</a> base map, e.g. in order to use your own aerial imagery or to overlay floor-plans. Particularly when you work with floor-plans you might want to get closer than the maximum zoom-level 21 that <a href="http://www.microsoft.com/maps/">Bing Maps</a> uses by default. The MapCruncher supports the generation of tiles for these higher zoom-levels and in the <a href="http://www.microsoft.com/maps/">Bing Maps</a> AJAX control you can just set the minimum and maximum zoom-level in the <a href="http://msdn.microsoft.com/en-us/library/bb429539.aspx">VETileSourceSpecification</a></p> <blockquote> <p>tileSourceSpec.MinZoomLevel = 18;<br />tileSourceSpec.MaxZoomLevel = 23;</p></blockquote> <p>In the <a href="http://www.microsoft.com/maps/">Bing Maps</a>*<a href="http://www.silverlight.net/">Silverlight</a> Control there is a similar property of the <a href="http://msdn.microsoft.com/en-us/library/microsoft.maps.mapcontrol.locationrecttilesource_m embers(v=MSDN.10).aspx">LocationRectTileSource</a> which suggest that you can just set the zoom-range beyond level 21 as well, e.g.</p> <blockquote> <p>Dim tileSource As New LocationRectTileSource()<br />tileSource.ZoomRange = New Range(Of Double)(18, 23)</p></blockquote> <p>However, this alone does not do the trick because the default MapModes have the maximum zoom-level 21. In order to go beyond level 21 you can derive from AerialMode or RoadMode and override the <a href="http://msdn.microsoft.com/en-us/library/microsoft.maps.mapcontrol.aerialmode.getzoomrange. aspx">GetZoomRange</a>-method, e.g.<pre><span style="color:blue">Public Class </span><span style="color:#2b91af">MyAerialMode
</span><span style="color:blue">Inherits </span><span style="color:#2b91af">AerialMode
</span><span style="color:blue">Protected Overrides Function </span>GetZoomRange(<span style="color:blue">ByVal </span>center <span style="color:blue">As </span><span style="color:#2b91af">Location</span>) <span style="color:blue">As </span><span style="color:#2b91af">Range</span>(<span style="color:blue">Of Double</span>)
<span style="color:blue">Return New </span><span style="color:#2b91af">Range</span>(<span style="color:blue">Of Double</span>)(1, 23)
<span style="color:blue">End Function
End Class

</span></pre><a href="http://11011.net/software/vspaste"></a>
<p>And then we can point to MyAerialMode rather than the default AerialMode, e.g.<pre><span style="color:blue">Private Sub </span>MapStyleAerial(<span style="color:blue">ByVal </span>sender <span style="color:blue">As </span>System.<span style="color:#2b91af">Object</span>, <span style="color:blue">ByVal </span>e <span style="color:blue">As </span>System.Windows.Input.<span style="color:#2b91af">MouseButtonEventArgs</span>)
MyMap.MapForeground.Copyright.Attributions.Clear()
MyMap.Mode = <span style="color:blue">New </span><span style="color:#2b91af">MyAerialMode
</span><span style="color:blue">End Sub</span></pre><a href="http://11011.net/software/vspaste"></a>
<p>Thatís it, now we can zoom down to my desk again:
<p><a href="https://psijhg.blu.livefilestore.com/y1mucK1YSeGrUSQTEqvBIvOuApb4khkMuiQ0rK5Tc1yB1M_I8j XU9qd8QMckpOS1tK5Bq_Iy1N2OzN76Eocc119DW5HF8YdpV778 9ImiCbihR9ofX7ePgdMfH4_pMEQtTddslA77DE3tx8l_-S_mxyNNw/image[3] 60624A80.png?download&psid=1" rel="WLPP"><img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px" title="image" border="0" alt="image" src="https://psijhg.blu.livefilestore.com/y1mPd21ZmMfrlnCkzM63d604tuVp0BAxwg0K2lv07catReUa0t tZIx4_YpTwv5fwbUg8F8uSGXBpU5DFhay8GGTddQ-iy10VfvnsqGkZOKXzPfF0fY86wNXrHUKSzuyV7oNQNSqJDSrdQ kjr501sliq4Q/image_thumb[1] 605E3681.png?download&psid=1" width="644" height="346" /></a>
<p>
<div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px">Technorati Tags: <a href="http://technorati.com/tags/Bing+Maps" rel="tag">Bing Maps</a>,<a href="http://technorati.com/tags/Silverlight" rel="tag">Silverlight</a></div></p> </p></p></p>

Click here to view the article. (http://johanneskebeck.spaces.live.com/Blog/cns!42E1F70205EC8A96!12495.entry)