Minimal example for "Xaml MapControl"
I have mentioned the map control named "Xaml.MapControl" by Clemes Fischer on this blog earlier. This is a very good map control for use in WPF applications and some of the main features are:
- It can get tiles from many sources such as "Open Street Map", "Bing Maps" and custom sorces by using a url format string.
- It can also have WMS layers on from different sources, and you may also add your own tile sources or images.
- You can display UI elements on the map. The mapp add Points, Lines, Elipses and Polygons but you may add xaml-elements yourself to be displayed on your map.
- XAML and MVVM support. Using ItemsControls for multiple elements.
Create project and get the package from Nuget
Xaml.MapControl
" and press install.Show it on the form
<map:Map x:Name="MainMap" Center="59.9,10.7" ZoomLevel="4"> <map:MapTileLayer TileSource="https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png" /> </map:Map>
You should get some squiggly red lines and an error. This is because the reference to the mapControl's not there. Add the following as a new attribute to the "Window":
xmlns:map="clr-namespace:MapControl;assembly=MapControl.WPF"
The full XAML form should then look be something like this:
<Window x:Class="XamlMapBoilerplate.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:map="clr-namespace:MapControl;assembly=MapControl.WPF" Title="MainWindow" Height="450" Width="800"> <Grid> <map:Map x:Name="MainMap" Center="59.9,10.7" ZoomLevel="4"> <map:MapTileLayer TileSource="https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png" /> </map:Map> </Grid> </Window>
Press F5 and this is what you should see:
Just in case...
In case it doesn't show up allrigt this may be some tips:
The TileSource in the xample might have changed. You may try some other URL you can find here: https://wiki.openstreetmap.org/wiki/Tile_servers .
The tile server may have implemented new security features or data limits. Check the above link.
Comments
Post a Comment