Table of Contents

Class MlnStyle

Namespace
MapLibreNative.Maui

Provides access to sources and layers. This is a non-owning handle — do not dispose it; it is invalidated when the parent MlnMap is disposed.

public sealed class MlnStyle
Inheritance
MlnStyle
Inherited Members

Fields

MapLibreAttributionHtml

HTML fragment linking to the MapLibre project. This library is built on MapLibre Native, so the project should always be credited — matching the behaviour of maplibre-gl-js, which always shows a "MapLibre" link.

public const string MapLibreAttributionHtml = "<a href=\"https://maplibre.org/\" target=\"_blank\" rel=\"noopener nofollow\">MapLibre</a>"

Field Value

string

Properties

IsTerrainEnabled

Whether 3D terrain is currently enabled.

public bool IsTerrainEnabled { get; }

Property Value

bool

Methods

AddBackgroundLayer(string, string?)

public MlnLayer AddBackgroundLayer(string layerId, string? beforeLayerId = null)

Parameters

layerId string
beforeLayerId string

Returns

MlnLayer

AddCircleLayer(string, string, string?)

public MlnLayer AddCircleLayer(string layerId, string sourceId, string? beforeLayerId = null)

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MlnLayer

AddColorReliefLayer(string, string, string?)

public MlnLayer AddColorReliefLayer(string layerId, string sourceId, string? beforeLayerId = null)

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MlnLayer

AddFillExtrusionLayer(string, string, string?)

public MlnLayer AddFillExtrusionLayer(string layerId, string sourceId, string? beforeLayerId = null)

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MlnLayer

AddFillLayer(string, string, string?)

public MlnLayer AddFillLayer(string layerId, string sourceId, string? beforeLayerId = null)

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MlnLayer

AddGeoJsonSource(string)

public MlnSource AddGeoJsonSource(string sourceId)

Parameters

sourceId string

Returns

MlnSource

AddGeoJsonSourceOptions(string, string?)

Add a GeoJSON source with style-spec options (clustering etc.). optionsJson is a JSON object of GeoJSON source options — the style-spec keys minus type/data: cluster, clusterRadius, clusterMaxZoom, clusterMinPoints, clusterProperties, maxzoom, buffer, tolerance, lineMetrics. Set data afterwards with SetGeoJson(string).

public MlnSource AddGeoJsonSourceOptions(string sourceId, string? optionsJson)

Parameters

sourceId string
optionsJson string

Returns

MlnSource

AddGeoJsonSourceUrl(string, string)

public MlnSource AddGeoJsonSourceUrl(string sourceId, string url)

Parameters

sourceId string
url string

Returns

MlnSource

AddHeatmapLayer(string, string, string?)

public MlnLayer AddHeatmapLayer(string layerId, string sourceId, string? beforeLayerId = null)

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MlnLayer

AddHillshadeLayer(string, string, string?)

public MlnLayer AddHillshadeLayer(string layerId, string sourceId, string? beforeLayerId = null)

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MlnLayer

AddImage(string, int, int, float, bool, byte[])

Add a sprite image. rgbaPremultiplied must be width × height × 4 bytes of premultiplied RGBA.

public void AddImage(string imageId, int width, int height, float pixelRatio, bool sdf, byte[] rgbaPremultiplied)

Parameters

imageId string
width int
height int
pixelRatio float
sdf bool
rgbaPremultiplied byte[]

AddImageSource(string, string, double, double, double, double, double, double, double, double)

Add an image source with an explicit lat/lng quad defining the four corners. Corner order: top-right, top-left, bottom-right, bottom-left (matches MapLibre style spec).

public MlnSource AddImageSource(string sourceId, string url, double lat0, double lon0, double lat1, double lon1, double lat2, double lon2, double lat3, double lon3)

Parameters

sourceId string
url string
lat0 double
lon0 double
lat1 double
lon1 double
lat2 double
lon2 double
lat3 double
lon3 double

Returns

MlnSource

AddLayerJson(string, string?)

Add a layer from a complete MapLibre layer-spec JSON object (must include "id" and "type" fields). Returns a non-owning MlnLayer handle, or null on error.

public MlnLayer? AddLayerJson(string layerJson, string? beforeLayerId = null)

Parameters

layerJson string
beforeLayerId string

Returns

MlnLayer

AddLineLayer(string, string, string?)

public MlnLayer AddLineLayer(string layerId, string sourceId, string? beforeLayerId = null)

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MlnLayer

AddLocationIndicatorLayer(string, string?)

public MlnLayer AddLocationIndicatorLayer(string layerId, string? beforeLayerId = null)

Parameters

layerId string
beforeLayerId string

Returns

MlnLayer

AddRasterDemSource(string, string, int)

public MlnSource AddRasterDemSource(string sourceId, string url, int tileSize = 512)

Parameters

sourceId string
url string
tileSize int

Returns

MlnSource

AddRasterDemTilesSource(string, IEnumerable<string>, int, int, int, string?, string?)

Add a raster-dem source from explicit {z}/{x}/{y} tile URL templates rather than a TileJSON URL. Use this when the DEM has no TileJSON, or when the elevation encoding must be declared — "terrarium" (AWS/Mapzen terrain-tiles) decodes differently from the default "mapbox" encoding, and mis-declaring it renders garbage elevation.

public void AddRasterDemTilesSource(string sourceId, IEnumerable<string> tileUrlTemplates, int tileSize = 512, int minZoom = 0, int maxZoom = 15, string? encoding = null, string? attribution = null)

Parameters

sourceId string
tileUrlTemplates IEnumerable<string>
tileSize int
minZoom int
maxZoom int
encoding string
attribution string

Attribution HTML for the source, shown by the attribution control.

AddRasterLayer(string, string, string?)

public MlnLayer AddRasterLayer(string layerId, string sourceId, string? beforeLayerId = null)

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MlnLayer

AddRasterSource(string, string, int)

public MlnSource AddRasterSource(string sourceId, string url, int tileSize = 512)

Parameters

sourceId string
url string
tileSize int

Returns

MlnSource

AddRasterTilesSource(string, IEnumerable<string>, int, int, int, string?)

Add a raster source from explicit {z}/{x}/{y} tile URL templates rather than a TileJSON URL, optionally with an attribution. A TileJSON source carries its own attribution; templates have nowhere else to declare one.

public void AddRasterTilesSource(string sourceId, IEnumerable<string> tileUrlTemplates, int tileSize = 512, int minZoom = 0, int maxZoom = 22, string? attribution = null)

Parameters

sourceId string
tileUrlTemplates IEnumerable<string>
tileSize int
minZoom int
maxZoom int
attribution string

AddSourceJson(string, string)

Add a source from a raw MapLibre source-spec JSON object (the object value — not including the source ID key). Example: AddSourceJson("my-source", "{"type":"geojson","data":"..."}")

public void AddSourceJson(string sourceId, string sourceJson)

Parameters

sourceId string
sourceJson string

AddSymbolLayer(string, string, string?)

public MlnLayer AddSymbolLayer(string layerId, string sourceId, string? beforeLayerId = null)

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MlnLayer

AddVectorSource(string, string)

public MlnSource AddVectorSource(string sourceId, string url)

Parameters

sourceId string
url string

Returns

MlnSource

AddVectorTilesSource(string, IEnumerable<string>, int, int, string?)

Add a vector source from explicit {z}/{x}/{y} tile URL templates rather than a TileJSON URL, optionally with an attribution. A TileJSON source carries its own attribution; templates have nowhere else to declare one.

public void AddVectorTilesSource(string sourceId, IEnumerable<string> tileUrlTemplates, int minZoom = 0, int maxZoom = 22, string? attribution = null)

Parameters

sourceId string
tileUrlTemplates IEnumerable<string>
minZoom int
maxZoom int
attribution string

EnsureMapLibreAttribution(IEnumerable<string>)

Returns parts with a MapLibre attribution link prepended when none of the existing parts already reference MapLibre (by link or text). Used by every platform's attribution overlay so MapLibre is always credited.

public static IReadOnlyList<string> EnsureMapLibreAttribution(IEnumerable<string> parts)

Parameters

parts IEnumerable<string>

Returns

IReadOnlyList<string>

GetJson()

Returns the currently loaded style as a JSON string.

public string GetJson()

Returns

string

GetLayer(string)

Gets a layer handle by ID, or null if not found.

public MlnLayer? GetLayer(string layerId)

Parameters

layerId string

Returns

MlnLayer

GetLayerIds()

Returns an array of all layer IDs in draw order.

public string[] GetLayerIds()

Returns

string[]

GetName()

Returns the human-readable name of the loaded style, or empty string.

public string GetName()

Returns

string

GetSource(string)

Gets a source handle by ID, or null if not found.

public MlnSource? GetSource(string sourceId)

Parameters

sourceId string

Returns

MlnSource

GetSourceAttributions()

Iterates every source in the loaded style and collects unique, non-empty attribution strings (from TileJSON metadata), in the order they appear. The result is suitable for building an OSM-compliant attribution overlay. Returns an empty array before a style is loaded.

public IReadOnlyList<string> GetSourceAttributions()

Returns

IReadOnlyList<string>

GetSourceIds()

Returns an array of all source IDs currently in the style.

public string[] GetSourceIds()

Returns

string[]

GetUrl()

Returns the URL from which the style was loaded, or empty string.

public string GetUrl()

Returns

string

HasLayer(string)

public bool HasLayer(string layerId)

Parameters

layerId string

Returns

bool

HasSource(string)

public bool HasSource(string sourceId)

Parameters

sourceId string

Returns

bool

RemoveImage(string)

public void RemoveImage(string imageId)

Parameters

imageId string

RemoveLayer(string)

public void RemoveLayer(string layerId)

Parameters

layerId string

RemoveSource(string)

public void RemoveSource(string sourceId)

Parameters

sourceId string

RemoveTerrain()

Disables 3D terrain; the map renders flat again.

public void RemoveTerrain()

SetLightProperty(string, object?)

Set a Light property, serializing the value from a C# object.

public void SetLightProperty(string name, object? value)

Parameters

name string
value object

SetLightProperty(string, string)

Set a Light property by name using a JSON-encoded value. Valid names: "anchor" ("map"|"viewport"), "color" (hex string), "intensity" (0–1), "position" ([radial, azimuthal, polar]).

public void SetLightProperty(string name, string valueJson)

Parameters

name string
valueJson string

SetTerrain(string, float)

Enables 3D terrain, draping the map over elevation from an existing raster-dem source (add it first with AddRasterDemSource(string, string, int) or include it in the style JSON; it may be the same source a hillshade layer uses).

public void SetTerrain(string sourceId, float exaggeration = 1)

Parameters

sourceId string

ID of a raster-dem source already in the style.

exaggeration float

Vertical exaggeration multiplier (1.0 = true scale).

SetTransition(long, long)

Set the global transition duration and optional delay for all animated style property changes.

public void SetTransition(long durationMs, long delayMs = 0)

Parameters

durationMs long
delayMs long