Table of Contents

Class MbglStyle

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 MbglMap is disposed.

public sealed class MbglStyle
Inheritance
MbglStyle
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

Methods

AddBackgroundLayer(string, string?)

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

Parameters

layerId string
beforeLayerId string

Returns

MbglLayer

AddCircleLayer(string, string, string?)

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

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MbglLayer

AddColorReliefLayer(string, string, string?)

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

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MbglLayer

AddFillExtrusionLayer(string, string, string?)

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

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MbglLayer

AddFillLayer(string, string, string?)

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

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MbglLayer

AddGeoJsonSource(string)

public MbglSource AddGeoJsonSource(string sourceId)

Parameters

sourceId string

Returns

MbglSource

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 MbglSource AddGeoJsonSourceOptions(string sourceId, string? optionsJson)

Parameters

sourceId string
optionsJson string

Returns

MbglSource

AddGeoJsonSourceUrl(string, string)

public MbglSource AddGeoJsonSourceUrl(string sourceId, string url)

Parameters

sourceId string
url string

Returns

MbglSource

AddHeatmapLayer(string, string, string?)

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

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MbglLayer

AddHillshadeLayer(string, string, string?)

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

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MbglLayer

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 MbglSource 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

MbglSource

AddLayerJson(string, string?)

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

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

Parameters

layerJson string
beforeLayerId string

Returns

MbglLayer

AddLineLayer(string, string, string?)

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

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MbglLayer

AddLocationIndicatorLayer(string, string?)

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

Parameters

layerId string
beforeLayerId string

Returns

MbglLayer

AddRasterDemSource(string, string, int)

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

Parameters

sourceId string
url string
tileSize int

Returns

MbglSource

AddRasterLayer(string, string, string?)

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

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MbglLayer

AddRasterSource(string, string, int)

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

Parameters

sourceId string
url string
tileSize int

Returns

MbglSource

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 MbglLayer AddSymbolLayer(string layerId, string sourceId, string? beforeLayerId = null)

Parameters

layerId string
sourceId string
beforeLayerId string

Returns

MbglLayer

AddVectorSource(string, string)

public MbglSource AddVectorSource(string sourceId, string url)

Parameters

sourceId string
url string

Returns

MbglSource

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 MbglLayer? GetLayer(string layerId)

Parameters

layerId string

Returns

MbglLayer

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 MbglSource? GetSource(string sourceId)

Parameters

sourceId string

Returns

MbglSource

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

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

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