MapLibreNative.Maui.WPF
5.0.0-pre.5
dotnet add package MapLibreNative.Maui.WPF --version 5.0.0-pre.5
NuGet\Install-Package MapLibreNative.Maui.WPF -Version 5.0.0-pre.5
<PackageReference Include="MapLibreNative.Maui.WPF" Version="5.0.0-pre.5" />
<PackageVersion Include="MapLibreNative.Maui.WPF" Version="5.0.0-pre.5" />
<PackageReference Include="MapLibreNative.Maui.WPF" />
paket add MapLibreNative.Maui.WPF --version 5.0.0-pre.5
#r "nuget: MapLibreNative.Maui.WPF, 5.0.0-pre.5"
#:package MapLibreNative.Maui.WPF@5.0.0-pre.5
#addin nuget:?package=MapLibreNative.Maui.WPF&version=5.0.0-pre.5&prerelease
#tool nuget:?package=MapLibreNative.Maui.WPF&version=5.0.0-pre.5&prerelease
MaplibreNativeMAUI
.NET MAUI library for rendering interactive maps with MapLibre Native on Android, iOS, macCatalyst, and Windows.
Architecture
This library takes a pure C ABI approach rather than wrapping the platform-native MapLibre SDKs:
MapLibre Native (C++)
│
▼
mln-cabi (C++ native library — flat C ABI)
│ P/Invoke
▼
MapLibreNative.Maui (C# typed wrappers: MlnMap, MlnStyle, MlnFrontend …)
│
├───────────────────────────────┬───────────────────────────────┐
▼ ▼ ▼
MapLibreNative.Maui.Handlers MapLibreNative.Maui.WPF (any consumer of the
(MAUI MapLibreMap + handlers, (WPF MlnMapImage control) typed C# bindings)
sources, layers, overlays;
Android/iOS/macOS/Windows)
Both the MAUI handlers and the WPF control render the map as an in-tree framework
visual (WinUI/WPF Image fed by glReadPixels, Android TextureView, iOS/mac MTKView)
with their on-map controls as ordinary framework children — see Surface integration.
The mln-cabi native library is compiled per-platform:
| Platform | Renderer | CI |
|---|---|---|
| Android | OpenGL ES (EGL + ANativeWindow) | native-android.yml |
| Android | Vulkan | native-android-vulkan.yml |
| iOS / macCatalyst | Metal (MTKView) | native-apple.yml |
| iOS / macCatalyst | Vulkan (MoltenVK) | native-apple-vulkan.yml |
| Windows | OpenGL (WGL) | native-windows.yml |
| Windows | Vulkan | native-windows-vulkan.yml |
The workflows above (in .github/workflows/) build the releases. This GitHub repository is the
primary one; mirror-gitlab.yml pushes main and the tags to a GitLab copy, whose .gitlab-ci.yml
runs the same native and .NET builds as checks, from scripts in .gitlab/scripts/ that also run locally
(Build-NativeWindows.ps1, build-native-android.sh, build-native-apple.sh). It does not
build the Apple Vulkan (MoltenVK) variant yet.
MapLibre Native is included as a git submodule at dependencies/maplibre-native.
Surface integration (how the rendered map reaches the UI)
On the desktop compositors that enforce airspace (WPF and WinUI), the native GL surface and the
map's controls used to float above the framework content (an HwndHost/WS_POPUP window with the
controls as separate top-level popups). Every platform now renders the map as an ordinary in-tree
framework visual with its controls as real framework children. See
docs/design/in-tree-map-surface.md.
| Platform | Map surface | Controls |
|---|---|---|
| WPF | MlnMapImage — WPF Image backed by a WriteableBitmap (pixels transferred each frame via glReadPixels) |
real WPF children |
| MAUI Windows | WinUI Image + WriteableBitmap via glReadPixels |
real XAML children |
| Android | TextureView (an ordinary in-tree View) |
native subviews |
| iOS / macCatalyst | MTKView |
native subviews |
The old airspace-based paths (WPF HwndHost/MlnMapHost, MAUI Windows WS_POPUP) have been removed.
Getting Started
Add the map to a page
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:maplibre="clr-namespace:MapLibreNative.Maui.Handlers;assembly=MapLibreNative.Maui.Handlers"
xmlns:layers="clr-namespace:MapLibreNative.Maui.Handlers.Layers;assembly=MapLibreNative.Maui.Handlers"
xmlns:sources="clr-namespace:MapLibreNative.Maui.Handlers.Sources;assembly=MapLibreNative.Maui.Handlers"
x:Class="MyApp.MainPage">
<maplibre:MapLibreMap StyleUrl="https://demotiles.maplibre.org/style.json"
MyLocationEnabled="True">
<sources:GeoJsonSource SourceName="my-source" FeatureCollection="{Binding GeoJson}" />
<layers:LineLayer SourceName="my-source"
LayerName="my-line"
Properties="{Binding LineProperties}" />
</maplibre:MapLibreMap>
</ContentPage>
Register the handler in MauiProgram.cs
using MapLibreNative.Maui.Handlers;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler(typeof(MapLibreMap), typeof(MapLibreMapHandler));
});
return builder.Build();
}
}
MapLibreMap Properties
| Property | Type | Description |
|---|---|---|
StyleUrl |
string |
MapLibre style URL or inline JSON |
MinZoom |
float |
Minimum zoom level |
MaxZoom |
float |
Maximum zoom level |
MyLocationEnabled |
bool |
Show user location dot |
MyLocationTrackingMode |
int |
Location tracking mode |
MyLocationRenderMode |
int |
Location indicator render mode |
RotateGesturesEnabled |
bool |
Enable rotation gesture |
ScrollGesturesEnabled |
bool |
Enable pan gesture |
TiltGesturesEnabled |
bool |
Enable pitch gesture |
ZoomGesturesEnabled |
bool |
Enable pinch-to-zoom |
ShowNavigationControls |
bool |
Show the zoom / rotate-pitch d-pad overlay (default true) |
ShowGpsControl |
bool |
Show the GPS tracking control overlay (default true) |
ShowAttributionControl |
bool |
Show the attribution overlay (default true) |
CustomAttribution |
string |
Extra attribution text appended after source-derived attributions |
Attributions |
IReadOnlyList<string> |
Read-only attributions in force (sources', MapLibre's, CustomAttribution), HTML; AttributionsChanged when they change |
ShowTerrainControl |
bool |
Show the 3D-terrain toggle button (default false), see 3D Terrain |
TerrainControlSourceId / TerrainControlExaggeration |
string / float |
The raster-dem source the terrain button toggles, and the exaggeration it applies |
TerrainLoadMode |
TerrainLoadMode |
Terrain loading budget and mesh depth: Quality (default), Balanced, Performance |
TerrainSkirtLength |
TerrainSkirtLength |
Auto (default) or None, to drop the tile-edge skirts over a transparent background |
CenterClampedToGround |
bool |
Let the map centre ride the terrain, as maplibre-gl-js does (default false) |
NavigationControlPosition / GpsControlPosition / TerrainControlPosition / AttributionControlPosition |
MapControlCorner |
Corner each control stacks in, see Map Controls |
ControlInsets |
MapControlInsets |
Read-only room the controls take in each corner; ControlInsetsChanged when it changes |
GpsTrackingMode / GpsBearingMode |
GpsTrackingMode / GpsBearingMode |
The GPS control's modes (Off/Show/Follow, Free/NorthUp/GpsBearing), two-way: they follow its buttons and gestures, and setting them does what the buttons do |
GpsFollowZoomMode / GpsFollowZoom |
GpsFollowZoomMode / double |
How the GPS control picks the zoom when it starts following (default: keep the current zoom) |
UiScale |
double |
Extra multiplier on the display density, e.g. to honour the OS font scale (default 1.0; read once when the map is created) |
ItemsSource / ItemTemplate |
— | Data-bound overlay elements, see Data binding |
VisibleRegion |
MapSpan? |
Read-only visible region, refreshed on camera idle |
Events (as ICommand bindable properties)
| Property | Fired when |
|---|---|
MapReadyCommand |
Native map is initialised |
StyleLoadedCommand |
Style has finished loading |
DidBecomeIdleCommand |
Map has finished all pending operations |
CameraMoveStartedCommand |
Camera movement has started (reason int) |
CameraMoveCommand |
Camera is moving |
CameraIdleCommand |
Camera has stopped |
CameraTrackingChangedCommand / CameraTrackingDismissedCommand |
Location-tracking mode changed / was dismissed |
MapClickCommand |
User taps the map (LatLng; on the terrain surface when terrain is on) |
MapLongClickCommand |
User long-presses the map (LatLng; on the terrain surface when terrain is on) |
UserLocationUpdateCommand |
Device location has changed |
Map Controls
The built-in controls (terrain, navigation, GPS, attribution) and controls of your own stack in the map's corners
as in maplibre-gl-js: the first control in a corner sits nearest it, and later ones stack away from it, down from a
top corner and up from a bottom one. The built-in controls come first, in that order, each in the corner its
…ControlPosition names; turn any of them off with its Show… property. A hidden control takes no room.
AddControl puts any MAUI view on the map as a control, like gl-js's map.addControl(control, position):
var layers = new Button { Text = "Layers" };
layers.Clicked += (_, _) => ShowLayerPicker();
Map.AddControl(layers, MapControlCorner.TopLeft); // first in the top-left corner
Map.AddControl(new Button { Text = "★" }); // top right, below the built-in controls
Map.RemoveControl(layers);
A control takes the map's BindingContext, so bindings in it work as in the page. Adding a control again moves it
to the end of its corner. Controls lists them.
ScaleControl is a scale bar, like gl-js's: a bar of a round distance (1, 2 or 5 times a power of ten) no wider than
MaxBarWidth (default 100), measured at the map's centre and updated as the camera moves. Unit is Metric
(default), Imperial or Nautical.
Map.AddControl(new ScaleControl { Unit = ScaleUnit.Imperial }, MapControlCorner.BottomLeft);
For views of your own laid over the map that aren't controls (a banner, a panel), ControlInsets gives the room
the controls take in each corner, margins included, and ControlInsetsChanged tells when a control is added,
removed, shown, hidden or resized:
Map.ControlInsetsChanged += (_, _) =>
Banner.Margin = new Thickness(Map.ControlInsets.TopLeft.Width, 8, Map.ControlInsets.TopRight.Width, 0);
To show attribution your own way, turn the built-in control off (ShowAttributionControl="False") and show
Attributions instead: OpenStreetMap's licence and most tile providers' terms require it on the map.
Map.AttributionsChanged += (_, _) => Credits.Text = string.Join(" | ", Map.Attributions.Select(StripHtml));
For GPS buttons of your own, hide the built-in control (ShowGpsControl="False") and set GpsTrackingMode and
GpsBearingMode: the map still shows the location fed to UpdateGpsLocation and moves the camera as the
built-in buttons would. Both are two-way, so a pan dropping Follow to Show, or a rotation dropping the bearing
mode to Free, shows in them (and in a binding), whichever buttons are on the map.
FollowButton.Clicked += (_, _) => Map.GpsTrackingMode =
Map.GpsTrackingMode == GpsTrackingMode.Follow ? GpsTrackingMode.Show : GpsTrackingMode.Follow;
HeadingButton.Clicked += (_, _) => Map.GpsBearingMode = GpsBearingMode.GpsBearing;
The sample's Controls page shows controls in three corners, a button that moves the GPS control round them, one that hides the built-in controls, and the insets.
Sources
Declare sources as child elements of MapLibreMap, or add them programmatically via the controller.
| XAML type | Description |
|---|---|
GeoJsonSource |
Inline GeoJSON FeatureCollection or URL |
VectorSource |
Vector tile URL or TileJSON |
RasterSource |
Raster tile URL or TileJSON |
RasterDemSource |
Raster DEM tile source (for hillshade) |
ImageSource |
Image overlay bound to LatLngQuad coordinates |
<sources:GeoJsonSource SourceName="points" FeatureCollection="{Binding PointsJson}" />
<sources:VectorSource SourceName="roads" TileUrl="https://example.com/tiles.json" />
Clustered GeoJSON sources
Pass style-spec GeoJSON source options (clustering etc.) when adding a source programmatically:
// Cluster points within 50px, up to zoom 14
controller.AddGeoJsonSource("aps", featureCollectionJson,
"{\"cluster\":true,\"clusterRadius\":50,\"clusterMaxZoom\":14}");
Cluster features carry cluster: true, cluster_id, and point_count properties.
Drill into a cluster returned by a rendered-features query:
double? zoom = controller.GetClusterExpansionZoom("aps", clusterFeatureJson);
string? kids = controller.GetClusterChildren("aps", clusterFeatureJson);
string? items = controller.GetClusterLeaves("aps", clusterFeatureJson, limit: 25);
Layers
Declare layers as child elements of MapLibreMap. Each layer references a SourceName and accepts a Properties dictionary of MapLibre style paint/layout properties.
| XAML type | MapLibre layer type |
|---|---|
FillLayer |
fill |
LineLayer |
line |
CircleLayer |
circle |
SymbolLayer |
symbol |
RasterLayer |
raster |
HeatmapLayer |
heatmap |
FillExtrusionLayer |
fill-extrusion |
hillshade layers can be added programmatically via controller.AddHillshadeLayer(...);
color-relief (and any other spec layer type) via controller.AddLayerJson(...).
<layers:FillLayer SourceName="polygons"
LayerName="polygons-fill"
Properties="{Binding FillProperties}" />
<layers:LineLayer SourceName="roads"
LayerName="roads-line"
SourceLayer="transportation"
Properties="{Binding LineProperties}" />
Property dictionaries
Properties are a IDictionary<string, object?> mapping MapLibre style property names to values or expressions:
public IDictionary<string, object?> LineProperties => new Dictionary<string, object?>
{
["line-color"] = "#e55e5e",
["line-width"] = 3.0,
};
Overlay elements
For the common "just draw a marker / line / shape here" cases you can use the high-level overlay
elements instead of wiring sources and layers by hand. They mirror the
Microsoft.Maui.Controls.Maps element model (Pin, Polyline, Polygon, Circle) but are
declared as child elements of MapLibreMap. Each element materialises itself as a GeoJSON source
plus style layer(s) when the style loads, so it renders inside the map surface and composites
correctly on every platform. Changing a property (or mutating a Geopath collection) rebuilds it.
| XAML type | Draws | Key properties |
|---|---|---|
Pin |
SDF symbol marker (icon + optional label) | Location, Label, Address, TintColor/IconColor; MarkerClicked |
Polyline |
Line | Geopath (IList<Location>), StrokeColor, StrokeWidth |
Polygon |
Filled area | Geopath, FillColor, StrokeColor, StrokeWidth |
Circle |
Circle of a geographic radius | Center, Radius (Distance), FillColor, StrokeColor, StrokeWidth |
xmlns:overlays="clr-namespace:MapLibreNative.Maui.Handlers.Overlays;assembly=MapLibreNative.Maui.Handlers"
<maplibre:MapLibreMap StyleUrl="https://demotiles.maplibre.org/style.json">
<overlays:Pin Location="{Binding Home}" Label="Home" TintColor="Crimson" />
<overlays:Circle Center="{Binding Home}" Radius="{Binding Range}"
FillColor="#3300A2FF" StrokeColor="#00A2FF" StrokeWidth="2" />
</maplibre:MapLibreMap>
Circle.Radius uses the ported MapLibreNative.Maui.Geometry.Distance (e.g. Distance.FromMeters(500)),
and the circle geometry is generated with GeographyUtils.ToCircumferencePositions.
Pin renders as a SymbolLayer backed by an SDF sprite (mln_marker), so IconColor/TintColor
tinting and text labels work out of the box. MarkerClicked is exposed but must be wired from the
map's click/feature-query pipeline.
Data binding (ItemsSource)
Instead of declaring overlay children statically you can bind a collection to MapLibreMap.ItemsSource
and supply an ItemTemplate (or ItemTemplateSelector) whose DataTemplate produces an overlay
element. Each item becomes that element's BindingContext, mirroring
Microsoft.Maui.Controls.Maps.Map:
<maplibre:MapLibreMap ItemsSource="{Binding Stops}">
<maplibre:MapLibreMap.ItemTemplate>
<DataTemplate>
<overlays:Pin Location="{Binding Coordinate}" Label="{Binding Name}" />
</DataTemplate>
</maplibre:MapLibreMap.ItemTemplate>
</maplibre:MapLibreMap>
Collections implementing INotifyCollectionChanged (e.g. ObservableCollection<T>) sync
add/remove/replace/reset automatically. The template must create a MapOverlayElement (Pin,
Polyline, Polygon, or Circle).
Camera
Use the controller (obtained from MapReadyCommand or StyleLoadedCommand) to manipulate the camera:
// Instant jump
controller.JumpTo(latitude: 51.5, longitude: -0.1, zoom: 12);
// Animated ease
controller.EaseTo(51.5, -0.1, zoom: 14, bearing: 0, pitch: 45, durationMs: 800);
// Animated fly-to
controller.FlyTo(51.5, -0.1, zoom: 14, bearing: 0, pitch: 0, durationMs: 1500);
// Constrain the camera to a bounding box (optionally with zoom/pitch limits)
controller.SetCameraTargetBounds(new LatLngBounds(
ne: new LatLng(51.6, 0.0), sw: new LatLng(51.4, -0.2)));
// Fit a region into view (MapSpan overloads of JumpTo / EaseTo / FlyTo)
controller.EaseTo(MapSpan.FromCenterAndRadius(
new MapCoordinate(51.5, -0.1), Distance.FromKilometers(5)));
// Coordinate conversion (on the terrain surface when 3D terrain is on)
var (x, y) = controller.LatLngToScreenPoint(51.5, -0.1);
LatLng ll = controller.ScreenPointToLatLng(x, y);
// Edge padding: centre the target in the *unobscured* part of the viewport
// (padding order: top, left, bottom, right, in screen pixels). Useful when a
// panel or overlay covers part of the map. Pass double.NaN for zoom / bearing /
// pitch to keep the current value.
controller.EaseTo(51.5, -0.1, zoom: 14, bearing: 0, pitch: 0,
padTop: 0, padLeft: 300, padBottom: 0, padRight: 0);
// Anchored zoom: multiply the map scale (2.0 = one zoom level in),
// optionally about a screen point
controller.ScaleBy(2.0, anchorX: x, anchorY: y, durationMs: 250);
The map also exposes the currently visible region for read-back. MapLibreMap.VisibleRegion
(a MapSpan?) is refreshed whenever the camera becomes idle and raises PropertyChanged for data
binding; GetVisibleRegion() reads it on demand:
if (map.VisibleRegion is { } region)
{
var center = region.Center; // MapCoordinate
var span = (region.LatitudeDegrees, region.LongitudeDegrees);
}
3D Terrain
Terrain needs a raster-dem source in the style, added in the style JSON or from code.
Adding a hillshade layer from the same source makes the relief easier to see:
controller.AddSourceJson("dem",
"{\"type\":\"raster-dem\",\"url\":\"https://tiles.mapterhorn.com/tilejson.json\"}");
controller.AddLayerJson("{\"id\":\"dem-hillshade\",\"type\":\"hillshade\",\"source\":\"dem\"}");
map.SetTerrain("dem", exaggeration: 1.5f); // or ToggleTerrain / RemoveTerrain
bool on = map.IsTerrainEnabled;
For an on-map toggle button like maplibre-gl-js's TerrainControl, set ShowTerrainControl="True"
and TerrainControlSourceId to the raster-dem source's ID. The button doesn't add the source;
it must already be in the style. The button also shows terrain turned on or off from code.
With terrain on, taps, long-presses, ScreenPointToLatLng, LatLngToScreenPoint and the batch
PixelsForLatLngs / LatLngsForPixels report the point on the terrain surface. Without terrain,
or before an elevation tile covers the spot, they report it at sea level.
double? metres = controller.GetTerrainElevation(47.26, 11.40); // null where no DEM is loaded
Gestures that start over terrain move the map's centre up onto the ground, so the camera turns round what you are looking at. A saved camera therefore needs the centre's altitude as well as its centre and zoom. To restore it, set the altitude first:
double altitude = controller.GetCenterAltitude();
// ... later ...
controller.SetCenterAltitudeKeepingView(altitude);
controller.JumpTo(lat, lon, zoom);
| Setting | What it does |
|---|---|
TerrainLoadMode |
Quality (default) builds every terrain tile at once and meshes deepest; Balanced and Performance cap each frame's work, for weaker GPUs, and mesh less deep |
TerrainSkirtLength |
None removes the walls along tile edges, which show over a transparent background, at the cost of seams between zoom levels |
CenterClampedToGround |
The centre follows the terrain height, and the camera stays 10 m above the ground under it |
controller.SetTileLodMode(2) |
Adaptive tile selection: finer tiles near the camera and coarser toward the horizon, as maplibre-gl-js does with terrain |
MlnMapImage (WPF) has the same terrain methods, terrain button and settings except
SetTileLodMode, and its clicks land on the terrain too. GetTerrainElevation and the
centre-altitude calls are on the MAUI controller and on MlnMap only.
Style Global State
A style can declare named values in its root state property, and read them anywhere with the
global-state expression.
Changing one restyles every property that reads it, without reloading the style:
map.SetGlobalStateProperty("units", "imperial"); // null resets it to the style's default
string state = map.GetGlobalState(); // JSON object
Call it from StyleLoaded or later: a value set while the style is still loading is ignored.
Feature Queries
// Query features at a tapped screen position
string? geojson = controller.QueryRenderedFeaturesAtPoint(x, y, layerIds: "my-layer");
// Query features in a bounding box
string? geojson = controller.QueryRenderedFeaturesInBox(x1, y1, x2, y2);
// Query all features in a source's *data*, regardless of visibility
// (sourceLayerIds is required for vector sources, ignored for GeoJSON;
// filterJson is an optional style-spec filter expression)
string? all = controller.QuerySourceFeatures("my-source",
sourceLayerIds: null, filterJson: "[\"==\",[\"get\",\"type\"],\"wifi\"]");
The return value is a GeoJSON FeatureCollection string, or null if the renderer is not ready.
Feature State
Per-feature state lets you change the visual appearance of individual features (e.g. hover effects) without re-loading the style:
// Set state — stateJson is a JSON object
controller.SetFeatureState(sourceId: "my-source", featureId: "123", stateJson: "{\"hover\":true}");
// With an explicit source layer (required for vector tile sources)
controller.SetFeatureState("my-source", "123", "{\"hover\":true}", sourceLayerId: "my-layer");
// Read state back (returns JSON string or null)
string? state = controller.GetFeatureState("my-source", "123");
// Remove a single state key
controller.RemoveFeatureState("my-source", featureId: "123", stateKey: "hover");
// Remove all state for a feature
controller.RemoveFeatureState("my-source", featureId: "123");
// Remove all state for every feature in a source
controller.RemoveFeatureState("my-source");
Viewport Bounds
// Get the lat-lng bounding box of the current camera view
var (latSW, lonSW, latNE, lonNE) = controller.GetVisibleBounds();
Memory Management
// Ask the renderer to release cached GPU resources
controller.ReduceMemoryUse();
// Write renderer diagnostics to the log
controller.DumpDebugLogs();
Offline Maps
Persistent cache
Every map surface uses a persistent tile/resource cache database by default
(MlnCache.DefaultPath — {LocalApplicationData}/MapLibreNative.Maui/{processName}/cache.db),
so tiles survive app restarts.
Live data such as radar or traffic is stale by the next visit, so keep it out of the cache:
map.SetSourceVolatile("radar", true); // its tiles are never written to disk
It applies to tiles requested from then on, so call it right after adding the source, or from
StyleLoaded for a source defined in the style.
Bundled files (asset://)
Styles, GeoJSON, sprites, glyphs and whole tile archives can ship inside the app.
Add them as MauiAsset items (anything under Resources/Raw/) and reference them
with asset://, using the asset's logical name:
map.StyleUrl = "asset://styles/offline.json"; // Resources/Raw/styles/offline.json
map.AddVectorSource("local", "pmtiles://asset://region.pmtiles", null, minZoom: 0, maxZoom: 14);
asset:// resolves to the app's bundled files on every platform: the APK's assets/
folder on Android (read through Android's AssetManager, as the MapLibre Android SDK
does — file:///android_asset/… works there too), the app bundle's resources on
iOS/macCatalyst, and the app directory on Windows and WPF. Pass an explicit assetPath
to MlnMap to point it somewhere else (not on Android).
PMTiles reads only the byte ranges it needs. On Android, store archives uncompressed in the APK, or each seek decompresses everything before it:
<PropertyGroup>
<AndroidStoreUncompressedFileExtensions>.pmtiles</AndroidStoreUncompressedFileExtensions>
</PropertyGroup>
Offline mode
MapLibre's network access can be toggled process-wide. When offline, all network requests are suspended and only cached resources are served; going back online resumes queued requests.
using MapLibreNative.Maui;
MlnNetwork.Online = false; // force offline — serve from cache only
MlnNetwork.Online = true; // resume network access
Offline regions
MlnOfflineManager downloads complete regions (style + tiles + glyphs) for
offline use. It shares the map's cache database by default, so downloaded
regions are rendered by the map automatically:
using MapLibreNative.Maui;
using var offline = new MlnOfflineManager(); // uses MlnCache.DefaultPath
// Progress/error events arrive on MapLibre's database thread — marshal to
// your UI thread before touching UI. The observer's Complete flag is the
// authoritative completion signal.
offline.RegionProgress += p => Console.WriteLine(
$"region {p.RegionId}: {p.CompletedResources}/{p.RequiredResources} complete={p.Complete}");
offline.RegionError += e => Console.WriteLine($"region {e.RegionId}: {e.Message}");
// Create a region (style URL + bounds + zoom range) and start downloading
var region = await offline.CreateRegionAsync(
"https://demotiles.maplibre.org/style.json",
latSw: 51.4, lonSw: -0.3, latNe: 51.6, lonNe: 0.0,
minZoom: 0, maxZoom: 12,
metadata: Encoding.UTF8.GetBytes("{\"name\":\"London\"}"));
offline.ObserveRegion(region.Id);
offline.SetDownloadState(region.Id, active: true);
// Inspect / manage
var regions = await offline.ListRegionsAsync();
var status = await offline.GetRegionStatusAsync(region.Id);
byte[]? meta = offline.GetRegionMetadata(region.Id);
await offline.DeleteRegionAsync(region.Id);
// Side-load a prebuilt cache database
var merged = await offline.MergeDatabaseAsync(@"C:\data\prepared-regions.db");
// Ambient cache maintenance
await offline.SetMaximumAmbientCacheSizeAsync(100UL * 1024 * 1024);
await offline.ClearAmbientCacheAsync();
await offline.PackDatabaseAsync();
A geometry overload (CreateRegionAsync(styleUrl, geometryGeoJson, …)) downloads
tiles covering an arbitrary GeoJSON geometry instead of a bounding box. See the
MAUI sample's Offline tab for a working download → offline-toggle demo.
Generic JSON Sources and Layers
In addition to the typed XAML source/layer elements you can add sources and layers from raw MapLibre style-spec JSON:
// Add any source type by spec JSON
controller.AddSourceJson("my-source",
"{\"type\":\"geojson\",\"data\":{\"type\":\"FeatureCollection\",\"features\": []}}");
// Add any layer type by spec JSON
controller.AddLayerJson(
"{\"id\":\"my-fill\",\"type\":\"fill\",\"source\":\"my-source\"," +
"\"paint\":{\"fill-color\":\"#ff0000\",\"fill-opacity\":0.5}}");
// Insert before an existing layer
controller.AddLayerJson(layerJson, beforeLayerId: "labels");
Style & Layer Inspection
Once a style is loaded, you can inspect and modify it via the controller:
// Enumerate the loaded style
string url = controller.GetStyleUrl();
string[] sources = controller.GetStyleSourceIds();
string[] layers = controller.GetStyleLayerIds();
// Read layer properties (returns JSON-encoded value, or null if not set)
string? color = controller.GetLayerPaintProperty("my-layer", "line-color");
string? vis = controller.GetLayerLayoutProperty("my-layer", "visibility");
// Show / hide a layer
bool visible = controller.GetLayerVisibility("my-layer");
controller.SetLayerVisibility("my-layer", !visible);
Debug Overlays
MapLibre Native has built-in debug overlays controlled by a bitmask:
// Enable tile borders + collision boxes
controller.SetDebugOptions(0x02 | 0x10);
// Read current state
int current = controller.GetDebugOptions();
// Disable all
controller.SetDebugOptions(0);
The MlnDebugOptions enum in MapLibreNative.Maui names the individual bits (TileBorders, ParseStatus, Timestamps, Collision, Overdraw, StencilClip, DepthBuffer).
WPF Usage
For classic WPF apps (not MAUI), use MlnMapImage from MapLibreNative.Maui.WPF:
xmlns:mlwpf="clr-namespace:MapLibreNative.Maui.WPF;assembly=MapLibreNative.Maui.WPF"
<mlwpf:MlnMapImage x:Name="MapHost"
StyleUrl="https://demotiles.maplibre.org/style.json"
ShowNavigationControls="True"
MapReady="MapHost_MapReady"
StyleLoaded="MapHost_StyleLoaded"
CameraIdle="MapHost_CameraIdle" />
MlnMapImage renders MapLibre into a WPF Image backed by a WriteableBitmap (pixels transferred
each frame via glReadPixels), so the map is an ordinary WPF visual and its nav / GPS / attribution
controls are real WPF children — no HwndHost, no floating Popups, correct z-order/clipping, and
input via normal WPF events. It supports the same camera, source, layer, and query operations as the
MAUI handler. See sample/WpfExample for a full working example, and
docs/design/in-tree-map-surface.md for the design.
Google Play native debug symbols
The Android libmln-cabi.so in the packages is stripped, so on its own a native crash inside
MapLibre reaches Play's Android vitals as bare addresses. Each GitHub release attaches the same
builds before stripping: MapLibreNative.Maui-<version>-android-symbols.zip (and
MapLibreNative.Maui.Vulkan-… for the Vulkan package), one <abi>/libmln-cabi.so per ABI.
Upload the zip matching your package version as your app version's native debug symbols: in
Play Console under App bundle explorer → the version → Downloads → Native debug symbols, or
through the Play Developer API's edits.deobfuscationfiles.upload with type nativeCode. Play
matches each library by its build ID. Releases up to 5.0.0-pre.4 have none.
Building from Source
Prerequisites
- .NET 10 SDK (LTS) — projects multi-target .NET 9 and .NET 10
- CMake ≥ 3.25 and Ninja
- Android: Android NDK r28c (28.2.13676358, the version maplibre-native uses)
- Apple: macOS with Xcode 26 (CI builds with 26.5)
- Windows: Visual Studio 2022 with the C++ workload (MSVC 14.44). MSVC 14.52 from Visual Studio 2026 crashes on maplibre-native's code when building for arm64.
Clone with submodules
git clone --recurse-submodules https://github.com/TechIdiots-LLC/MaplibreNativeMAUI.git
Or if you already cloned without submodules:
git submodule update --init --recursive
Build native library
The scripts in .gitlab/scripts/ run the same builds as CI and work locally. Run them from the
repository root with the submodules checked out. Each copies its library to native-out/:
# Windows (PowerShell): -Arch x64|arm64, -Renderer opengl|vulkan
.\.gitlab\scripts\Build-NativeWindows.ps1 -Arch x64 -Renderer opengl
# Android: <arm64-v8a|armeabi-v7a|x86_64> <opengl|vulkan>
.gitlab/scripts/build-native-android.sh arm64-v8a opengl
# Apple (Metal): <ios|iossimulator|maccatalyst>
.gitlab/scripts/build-native-apple.sh maccatalyst
To pack, copy the libraries into bindings/native/ (bindings/native-vulkan/ for the Vulkan
package), one folder per platform: win-x64/ and win-arm64/ (mln-cabi.dll), android-arm64/,
android-arm/ and android-x64/ (libmln-cabi.so), maccatalyst/ (libmln-cabi.a) and
ios/libmln-cabi.xcframework. The iOS XCFramework is made from the ios and iossimulator
builds with xcodebuild -create-xcframework.
Build and run the sample
dotnet build sample/MauiSample.csproj -f net10.0-android
License
This project is BSD 2-Clause licensed — see LICENSE.
| Dependency | License | Notes |
|---|---|---|
| MapLibre Native | BSD 2-Clause | Linked natively via mln-cabi |
| maplibre-native-ffi | BSD 2-Clause | Reference only — no code included; project structure and C ABI conventions (typed handles, status codes, log callback) informed the design of mln-cabi |
| Original maplibre-maui by Benjamin Trounson | MIT | Portions adapted |
.NET MAUI (src/Core/maps) |
MIT | Map primitives in bindings/Geometry (MapSpan, Distance, GeographyUtils, MapType) adapted from the official MAUI maps source; its handler + property/command mapper pattern also informed the design of MapLibreNative.Maui.Handlers |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0-windows10.0.19041 is compatible. net10.0-windows was computed. net10.0-windows10.0.19041 is compatible. |
-
net10.0-windows10.0.19041
- MapLibreNative.Maui (>= 5.0.0-pre.5)
-
net9.0-windows10.0.19041
- MapLibreNative.Maui (>= 5.0.0-pre.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 5.0.0-pre.5 | 44 | 11/23/2026 |
| 5.0.0-pre.4 | 72 | 11/14/2026 |
| 5.0.0-pre.3 | 125 | 9/4/2026 |
| 5.0.0-pre.2 | 125 | 9/3/2026 |
| 5.0.0-pre.1 | 96 | 9/3/2026 |
| 4.5.1 | 208 | 8/28/2026 |
| 4.5.0 | 165 | 7/16/2026 |
| 4.4.0 | 145 | 7/13/2026 |
| 4.2.2 | 143 | 7/12/2026 |
| 4.2.1 | 141 | 7/11/2026 |
| 4.2.0 | 150 | 7/10/2026 |
| 4.1.3 | 142 | 7/9/2026 |
| 4.1.2 | 133 | 7/7/2026 |
| 4.1.0 | 131 | 7/5/2026 |
| 4.0.0 | 144 | 7/5/2026 |
| 3.2.10 | 139 | 6/30/2026 |
| 3.2.9 | 162 | 6/29/2026 |
| 3.2.8 | 208 | 6/25/2026 |
| 3.2.7 | 142 | 6/25/2026 |
| 3.2.6 | 141 | 6/23/2026 |