Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rbrundritt/azuremapswpfcontrol
This is a code sample that shows how to get the Bing Maps WPF control to work with Azure Maps.
https://github.com/rbrundritt/azuremapswpfcontrol
Last synced: about 1 month ago
JSON representation
This is a code sample that shows how to get the Bing Maps WPF control to work with Azure Maps.
- Host: GitHub
- URL: https://github.com/rbrundritt/azuremapswpfcontrol
- Owner: rbrundritt
- License: mit
- Created: 2024-06-10T22:12:34.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-09-16T21:25:18.000Z (3 months ago)
- Last Synced: 2024-09-17T02:42:24.722Z (3 months ago)
- Size: 25.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Azure Maps WPF Control
On May 29th, 2024 Microsoft announced that the [Bing Maps for Enterprise platform would be retiring](https://www.microsoft.com/en-us/maps/bing-maps/discontinued-services), and recommended moving to Azure Maps.
The Bing Maps WPF SDK was actually deprecated many years ago, however, since it used the same production services of Bing Maps as their Web SDK, it continued to work. The original download page for the SDK is long gone (links in the docs are dead), but their is a NuGet package still around that was last updated in 2015. Because of this, there are still some apps out there using the Bing Maps WPF SDK.
The goal of this project is to provide an easy way to port over an app using the Bing Maps WPF SDK to use Azure Maps instead. In all, this solution can have your app using Azure Maps services instead of Bing Maps services in as few as 5 easy steps.
## Important Note
This is a hack! It does several undocumented things with the Bing Maps WPF control. Given that the Bing Maps WPF control was deprecated years ago, and not recieved any updates since then, that means it hasn't had any security or stability improvements made either. Given that the NuGet package could be removed at any time without warning, consider this a temporary solution.
Additionally, this solution has hardcoded URLs to specific versions of the Azure Maps services. Versions may increase over time, and the code may need to be updated accordingly to keep working. Azure Maps will likely send an email notice if you are using an older version of a service that needs to be updated. This solutions uses the `Map tile` and `Map Attribution` services of the [Azure Maps REST Render services](https://learn.microsoft.com/en-us/rest/api/maps/render).
Current Render service version used by this solution: `2024-04-01`
## Supported features
- **Localization support** - Most of the culture codes by Bing Maps work directly with Azure Maps. This solution is passes the culture code as is to Azure Maps and relies on it to determine how to fallback. As Azure Maps adds support for additional culture codes, this solution will automatically improve with it.
- **Copyright support** - To align with the terms of service, this solution dynamically updates the copyrights displayed in the bottom right corner of the map as required.
- **Bing logo removed** - Azure Maps terms of use do not require a logo to be displayed, and there is no need for a Bing logo when using Azure Maps data, so this solution removes it help keep the map a bit cleaner.
- **Support for multiple maps instances** - Load two or more maps, with different cultures without any issues.## How to use this in your app
1. Get an [Azure Maps subscription key](https://learn.microsoft.com/en-us/azure/azure-maps/how-to-manage-authentication).
2. Go into the `sample\BingMapsWPF_AzureMapsTiles\BingMapsWPF_AzureMapsTiles` folder of this project and copy and paste the `AzureMapsControl.cs` file into your app. [Here is a direct link to the file](https://github.com/rbrundritt/AzureMapsWPFControl/blob/main/sample/BingMapsWPF_AzureMapsTiles/BingMapsWPF_AzureMapsTiles/AzureMapsControl.cs).
3. In the XAML file where you add the map, add this namespace `xmlns:azmaps="clr-namespace:Azure.Maps.WPF"`
4. Locate the XAML for the map control in your app, it looks something like `
```
## Known limitation
This solution overrides the map controls `Mode` property (map style) and changes it to `MercatorMode` which prevents requests to Bing Maps tiles from being made. This is done for performance reasons. However, it's possible that your app may have logic that checks the `Mode` property, and this would likely break some functionality of your app. A common scenario where this type of logic is often added is to a button that toggles the map mode/style between road and aerial. To keep things simple, for the apps where overriding the `Mode` would cause an issue, a property has been added to the Azure Maps control that disables this behaviour. Simply add `AllowMapModeOverride="False"` to the maps XAML. For example:
```xaml
```
## License
MIT
## Resources
- [Bing Maps WPF SDK documentation](https://learn.microsoft.com/en-us/previous-versions/bing/wpf-control/hh750210(v%3dmsdn.10))
- [Bing Maps WPF NuGet package](https://www.nuget.org/packages/Microsoft.Maps.MapControl.WPF)
- [Azure Maps documentation](https://learn.microsoft.com/en-us/azure/azure-maps/)## Alternative solutions
This is one solution for those using the Bing Maps WPF SDK. There are two other common alternative solutions.
1. Use the Azure Maps Web SDK in a `WebView` control. This requires using a combination of c# and JavaScript code, but provides you with a very rich set of map capabilities.
2. Use a 3rd party (commerical) or open-source native map control for WPF. Here are few:
- [Maps UI](https://github.com/Mapsui/Mapsui) – Fairly popular open source Native Map SDK.
- [MapLibre Native](https://github.com/maplibre/maplibre-native) – MapLibre is the underlying rendering engine of the Azure Maps Web SDK and also the recommended control to use for iOS and Android so this is a good option to consider. Until recently there wasn’t much work around Windows but it looks like this has changed. Microsoft is a sponsor of the MapLibre community.
- [XAML Map Control](https://github.com/ClemensFischer/XAML-Map-Control) – I just came across this one and it appears to have some API interface alignment with the UWP map control. I don’t know much about it, but worth a look.
- [GreatMaps](https://github.com/radioman/greatmaps) – An older open source project focused on WPF and WinForm apps.