XAML-Map-Control/README.md

89 lines
5.4 KiB
Markdown
Raw Normal View History

# XAML Map Control
2025-10-23 19:22:40 +02:00
A set of controls for WPF, UWP, WinUI and Avalonia UI for rendering raster maps from different providers and various types of map overlays.
2017-04-01 19:04:31 +02:00
2021-02-05 21:58:49 +01:00
Map providers can easily be added by specifying a template string for their map tile URLs.
Map overlay layers allow to draw and interact with graphical objects and pushpins on the map.
2021-02-05 21:58:49 +01:00
The Map Control API is similar to the Microsoft Bing Maps Control for WPF, except that no API key is required.
2017-04-01 19:04:31 +02:00
2024-06-19 09:27:07 +02:00
The project includes sample applications for all platforms, which demonstrate the features of XAML Map Control.
2017-04-01 19:04:31 +02:00
2017-08-04 23:06:14 +02:00
Map Control supports multiple map projections. However, the MapTileLayer class only works with WebMercatorProjection.
2021-02-05 21:58:49 +01:00
For other projections, an appropriate WmtsTileLayer or WmsImageLayer could be used.
---
Main classes are
2026-01-21 22:58:54 +01:00
- `MapBase`: The core map control. Provides properties like Center, ZoomLevel and Heading,
2020-03-20 18:58:58 +01:00
which define the currently displayed map viewport.
2026-01-21 22:58:54 +01:00
- `Map`: MapBase with basic mouse and touch input handling for zoom, pan, and rotation.
2026-01-22 08:44:18 +01:00
- `MapTileLayer`: Provides [tiled map content](https://wiki.openstreetmap.org/wiki/Raster_tile_providers) (e.g. from OpenStreetMap) by means of a `TileSource`.
2026-01-22 08:44:18 +01:00
- `WmtsTileLayer`: Provides tiled map content from a Web Map Tile Service ([WMTS](https://en.wikipedia.org/wiki/Web_Map_Tile_Service)).
2026-01-22 08:44:18 +01:00
- `MapImageLayer`, `WmsImageLayer`: Provides single image map content, e.g. from a Web Map Service ([WMS](https://en.wikipedia.org/wiki/Web_Map_Service)).
2025-02-27 13:22:11 +01:00
2026-01-21 22:58:54 +01:00
- `MapItemsControl`: Displays a collection of `MapItem` objects (with a geographic location).
---
2026-01-21 22:58:54 +01:00
In order to use OpenStreetMap tile servers in accordance with their [Tile Usage Policy](https://operations.osmfoundation.org/policies/tiles/),
2026-01-22 08:35:33 +01:00
your application must set a unique HTTP `User-Agent` request header, e.g. by adding it to the `DefaultRequestHeaders`
of the `HttpClient` instance returned by the static `ImageLoader.HttpClient` property:
ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "Your-Application/1.0");
The tile usage policy also requires that an application caches map tiles locally.
2026-01-21 22:58:54 +01:00
The `TileImageLoader` class uses
[`IDistributedCache`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.distributed.idistributedcache)
2024-02-05 10:38:29 +01:00
for optional caching of map tile bitmaps. By default, the cache is a
2026-01-21 22:58:54 +01:00
[`MemoryDistributedCache`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.distributed.memorydistributedcache)
2024-02-05 10:38:29 +01:00
instance with all default options.
2024-02-03 21:46:17 +01:00
2026-01-21 22:58:54 +01:00
Map Control provides three minimal `IDistributedCache` implementations for persistent caching:
* `ImageFileCache`, an implementation that stores each cached map tile as a single image file,
2024-02-05 10:44:11 +01:00
in the original file format delivered by the map provider (typically PNG or JPG). ImageFileCache is part of the MapControl library.
2026-01-21 22:58:54 +01:00
* `FileDbCache`, based on [EzTools FileDb](https://github.com/eztools-software/FileDb),
2024-02-05 10:44:11 +01:00
a simple file based No-SQL database, in a separate library FileDbCache.
2026-01-21 22:58:54 +01:00
* `SQLiteCache`, based on [System.Data.SQLite](https://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki),
2024-02-03 21:48:41 +01:00
in a separate library SQLiteCache.
2024-02-07 07:57:07 +01:00
You can of course also use a full-featured cache like
2026-01-21 22:58:54 +01:00
[`RedisCache`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.stackexchangeredis.rediscache).
2024-02-07 07:57:07 +01:00
2026-01-21 22:58:54 +01:00
To try the sample applications with `FileDbCache` or `SQLiteCache`, add an appropriate package reference to their
Visual Studio projects and modify the `TileImageLoader.Cache` assignment accordingly in `MainWindow.xaml.cs`.
2017-08-04 23:29:05 +02:00
---
2024-09-11 18:13:50 +02:00
XAML Map Control is available on NuGet, as a set of framework-specific packages with Package Ids
* [XAML.MapControl.WPF](https://www.nuget.org/packages/XAML.MapControl.WPF/),
2025-10-23 19:20:33 +02:00
* [XAML.MapControl.UWP](https://www.nuget.org/packages/XAML.MapControl.UWP/),
2024-09-11 18:16:00 +02:00
* [XAML.MapControl.WinUI](https://www.nuget.org/packages/XAML.MapControl.WinUI/),
2024-09-11 18:13:50 +02:00
* [XAML.MapControl.Avalonia](https://www.nuget.org/packages/XAML.MapControl.Avalonia/).
There are also packages for an extension library with additional map projections, based on
[ProjNET4GeoAPI](https://github.com/NetTopologySuite/ProjNet4GeoAPI), with Package Ids
* [XAML.MapControl.MapProjections.WPF](https://www.nuget.org/packages/XAML.MapControl.MapProjections.WPF/),
2025-10-23 19:20:33 +02:00
* [XAML.MapControl.MapProjections.UWP](https://www.nuget.org/packages/XAML.MapControl.MapProjections.UWP/),
2024-09-11 18:16:00 +02:00
* [XAML.MapControl.MapProjections.WinUI](https://www.nuget.org/packages/XAML.MapControl.MapProjections.WinUI/),
2024-09-11 18:13:50 +02:00
* [XAML.MapControl.MapProjections.Avalonia](https://www.nuget.org/packages/XAML.MapControl.MapProjections.Avalonia/),
and a library for [MBTiles](https://wiki.openstreetmap.org/wiki/MBTiles) support, with Package Ids
* [XAML.MapControl.MBTiles.WPF](https://www.nuget.org/packages/XAML.MapControl.MBTiles.WPF/),
2025-10-23 19:20:33 +02:00
* [XAML.MapControl.MBTiles.UWP](https://www.nuget.org/packages/XAML.MapControl.MBTiles.UWP/),
2024-09-11 18:16:00 +02:00
* [XAML.MapControl.MBTiles.WinUI](https://www.nuget.org/packages/XAML.MapControl.MBTiles.WinUI/),
2024-09-11 18:13:50 +02:00
* [XAML.MapControl.MBTiles.Avalonia](https://www.nuget.org/packages/XAML.MapControl.MBTiles.Avalonia/),
FileDbCache and SQLiteCache are available with Package Ids
* [XAML.MapControl.FileDbCache](https://www.nuget.org/packages/XAML.MapControl.FileDbCache/),
2024-09-11 18:15:15 +02:00
* [XAML.MapControl.SQLiteCache](https://www.nuget.org/packages/XAML.MapControl.SQLiteCache/).
2017-04-01 19:04:31 +02:00
---
2017-04-01 19:04:31 +02:00
The project is not open for contributions. Pull requests will not be accepted.