Posts

Showing posts with the label Bing Maps

Using Bing Maps as source for "Xaml MapControl"

In "XAML MapControl" you can also get the map tiles from Bing. You need an API key. This can pe obtained from this site: https://www.bingmapsportal.com/ Building on the example from this blog post: " Minimal Example ", The XAML markup will be: <map:Map x:Name="MainMap" Center="59.9,10.7" ZoomLevel="4"> <map:BingMapsTileLayer Mode="AerialWithLabels" /> </map:Map> But the API key has to be inserted somewhere i code before the map is displayed. The place for this is dependant of your project; For a MVVM project it may be set in the initilization of the ViewModel (if you are using "model-first"). For a more basic tutorial scenario it may be set in the App.Startup or the initialization of the first form. The code is either way:           using MapControl;           public MyViewModel() // or whatever initializes { BingMapsTileLayer.ApiKey = "YOUR-M...

Custom Pushpin in Bing Maps Control for WPF

Image
Pushpins in "Bing Maps Control for WPF" can be styled in XAML. The code below may seem a bit much, but this is actually very flexible and easy to adjust. And it doesn't require code-behind that is forgotten when copying, problems with change of names that isn't reflected in code or overriding rendering events. It also get additional benefits at a later stage since this can also contain text( see below ) be data-bound, bound to other controls or templates or be rotated and transformed. We could also control size or placement according to converters related to real-world sizes like meters or have it's visbility set according to zoom-level. This is out of scope here but I will try to get to that later. In the example below the styles are placed inside the map-control in <m:Map.Resources> . This is handy when designing or for a cut-copy-paste library. But this get quite a bit readable when it's moved into an Application.Resource in App.Xaml or in it...

Remove default Bing Map Layer from the WPF-MapControl

Image
When providing your own tiles to the Map Control in WPF you would want to remove the default map being served by Bing behind your own source. This is the "full" XAML block from one of my example projects: <m:Map Center="48.03,-122.4" Name="MyMap" CredentialsProvider="YOUR-BINGMAP-KEY" ZoomLevel="10"> <m:Map.Mode> <!-- set empty map mode to remove default map layer --> <m:MercatorMode /> </m:Map.Mode> <!-- Included for completeness, but to be replaced by yor own code or wait for a post about this -->     <!-- <local:MyTileLayer x:Name="WebMapLayer" UriFormat="{Binding SelectedTileProvider.UriFormat}"> <m:MapItemsControl ItemsSource="{Binding Places}"> <ItemsControl.ItemTemplate> <DataTemplate> <m:PushPin ...

Bing Maps Control for WPF with Essential Tools

There are alternatives, but the basic Bing Maps for WPF has a lot of resources and a strong documentation available. Microsoft has moved the focus to the UWP-version and the WEB-version, but for desktop applications that requires local file operations this is still the basic tool. I have been using " XAML Map Control " by Clemens Ficher a lot. But since that control is modelled after the features of "BingMaps"the toolkits below will still be relevant. To get started we should get the bing-map-key from Microsoft here: https://www.bingmapsportal.com/ First off there is the Control itself. It can be found on Nuget: PM> Install-Package Microsoft.Maps.MapControl.WPF Then I add the Spatial Toolbox ( see below ). This is not on Nuget, so you have to download it , unpack it, and then include it to your project. You can add a reference to the toolbox project to your solution (Located in the archive folders, and named: Microsoft.Maps.SpatialToolbox.Core and Micros...