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
Properties
IsTerrainEnabled
Whether 3D terrain is currently enabled.
public bool IsTerrainEnabled { get; }
Property Value
Methods
AddBackgroundLayer(string, string?)
public MlnLayer AddBackgroundLayer(string layerId, string? beforeLayerId = null)
Parameters
Returns
AddCircleLayer(string, string, string?)
public MlnLayer AddCircleLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddColorReliefLayer(string, string, string?)
public MlnLayer AddColorReliefLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddFillExtrusionLayer(string, string, string?)
public MlnLayer AddFillExtrusionLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddFillLayer(string, string, string?)
public MlnLayer AddFillLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddGeoJsonSource(string)
public MlnSource AddGeoJsonSource(string sourceId)
Parameters
sourceIdstring
Returns
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
Returns
AddGeoJsonSourceUrl(string, string)
public MlnSource AddGeoJsonSourceUrl(string sourceId, string url)
Parameters
Returns
AddHeatmapLayer(string, string, string?)
public MlnLayer AddHeatmapLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddHillshadeLayer(string, string, string?)
public MlnLayer AddHillshadeLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
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
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
sourceIdstringurlstringlat0doublelon0doublelat1doublelon1doublelat2doublelon2doublelat3doublelon3double
Returns
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
Returns
AddLineLayer(string, string, string?)
public MlnLayer AddLineLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddLocationIndicatorLayer(string, string?)
public MlnLayer AddLocationIndicatorLayer(string layerId, string? beforeLayerId = null)
Parameters
Returns
AddRasterDemSource(string, string, int)
public MlnSource AddRasterDemSource(string sourceId, string url, int tileSize = 512)
Parameters
Returns
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
sourceIdstringtileUrlTemplatesIEnumerable<string>tileSizeintminZoomintmaxZoomintencodingstringattributionstringAttribution HTML for the source, shown by the attribution control.
AddRasterLayer(string, string, string?)
public MlnLayer AddRasterLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddRasterSource(string, string, int)
public MlnSource AddRasterSource(string sourceId, string url, int tileSize = 512)
Parameters
Returns
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
sourceIdstringtileUrlTemplatesIEnumerable<string>tileSizeintminZoomintmaxZoomintattributionstring
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
AddSymbolLayer(string, string, string?)
public MlnLayer AddSymbolLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddVectorSource(string, string)
public MlnSource AddVectorSource(string sourceId, string url)
Parameters
Returns
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
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
partsIEnumerable<string>
Returns
- IReadOnlyList<string>
GetJson()
Returns the currently loaded style as a JSON string.
public string GetJson()
Returns
GetLayer(string)
Gets a layer handle by ID, or null if not found.
public MlnLayer? GetLayer(string layerId)
Parameters
layerIdstring
Returns
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
GetSource(string)
Gets a source handle by ID, or null if not found.
public MlnSource? GetSource(string sourceId)
Parameters
sourceIdstring
Returns
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
HasLayer(string)
public bool HasLayer(string layerId)
Parameters
layerIdstring
Returns
HasSource(string)
public bool HasSource(string sourceId)
Parameters
sourceIdstring
Returns
RemoveImage(string)
public void RemoveImage(string imageId)
Parameters
imageIdstring
RemoveLayer(string)
public void RemoveLayer(string layerId)
Parameters
layerIdstring
RemoveSource(string)
public void RemoveSource(string sourceId)
Parameters
sourceIdstring
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
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
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
sourceIdstringID of a raster-dem source already in the style.
exaggerationfloatVertical 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)