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 Microsoft.Maps.SpatialToolbox.WPF)
- Or you may compile it to dll's and reference them.
In addition, there's also two very useful libraries that could be included in new projects:
PM> Install-Package BingMapsRESTToolkit PM> Install-Package BingMapsSDSToolkit
The REST Toolkit contains several useful helpers for getting data from the Bing REST API's. This include Geocoding, Routing, Traffic, Elevations and more.
And the SDS Toolkit contains useful helpers for accessing the Spatial Data Services like: FindNearby, GetBoundaryData Finding along routes and more.
They are both generic and handles requesting data and retrieving json-results.
Please note that the usage of the API's above will add to your cost connected to your Key. Having a development key for non-profit development is connected to the map itself (in your WPF App), but the usage of heavy-lifting API's is not always included and may be billed to you.
Microsoft Maps Spatial Toolbox
Back to the free and useful stuff: Microsoft has also made the Microsoft Maps Spatial Toolbox some time ago. And it's still available at Codeplex as an archive here: https://archive.codeplex.com/?p=mapstoolbox.
This is an absolute wonderful "gem" and the core includes a lot of useful stuff like:
- Geographic calculations
- Haversine Distance
- Geographic MidPoint
- Heading
- Destination
- Geodesic line (fill a line so it follows the great-circle line)
- VertexReduction
- RadianToDegree and back
- Simple helpers for translating between meters and kilometers to feet and miles
- IO Functions for reading and writing:
- KML and KMZ Files
- Shape files
- GeoJson and GeoRSS
- GML
- WKT and WKB
- GPX, CSV and Bing XML
- OGC Models for exchanging the data:
- Point, MultiPoint
- Polyline, Linestring, MultiLine
- Polygon, MultiPolygon
It also has several extensions for the Bing Maps Control for WPF:
- HeatMap
- Point Clustering
- Animation
- TileMath for calculating tile XYZ and Quad-keys
- PointCompression for packing coordinates to used with REST services
This is a very useful toolbox.
The alternative was, for me, to collect tools and utilities you write yourself or download as libraries. But this toolbox will for instance handle all the file formats with the same data-structure, so there's no need to translate the shapes and points from a handy kml-parser to your solution and then write a different translator to handle the geoJson-parser.
With this toolbox everything has the same format when it's imported, -And this can then be passed into functions to get Geographic distance or calculating the great-circle route. -Or presented for the user.
There's a few "negative" things to observe:
- The WPF Controls works, but there's still a bit of quirks and lack of full databinding.
- It's all WGS84, Web Mercator. There's currently no support for transforming coordinate system
- It's all Geographic (wich is good), but I had to write some Rhumb-line calculations to get back the straight lines when operating local shapes like buldings that should in many cases be straight)
- It has a requirement for SQL Server Spatial Toolbox DLL for some functions. This is a great library, and I have used it alot myself, but I was a bit annoyed by the fact that I had to link to two different dll's for 32- and 64-bits.
But as the comments above indicate, there's a way to come around this. And it's still a very useful library.
I have also dived a bit into making my own controls for WPF for instance editable lines, draggable pins and so on. So I may even go through the "aging" WPF Controls and apply some findings and updates (providing if I'm able to :-)).
Comments
Post a Comment