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
Methods
AddBackgroundLayer(string, string?)
public MbglLayer AddBackgroundLayer(string layerId, string? beforeLayerId = null)
Parameters
Returns
AddCircleLayer(string, string, string?)
public MbglLayer AddCircleLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddColorReliefLayer(string, string, string?)
public MbglLayer AddColorReliefLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddFillExtrusionLayer(string, string, string?)
public MbglLayer AddFillExtrusionLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddFillLayer(string, string, string?)
public MbglLayer AddFillLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddGeoJsonSource(string)
public MbglSource 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 MbglSource AddGeoJsonSourceOptions(string sourceId, string? optionsJson)
Parameters
Returns
AddGeoJsonSourceUrl(string, string)
public MbglSource AddGeoJsonSourceUrl(string sourceId, string url)
Parameters
Returns
AddHeatmapLayer(string, string, string?)
public MbglLayer AddHeatmapLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddHillshadeLayer(string, string, string?)
public MbglLayer 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 MbglSource 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 MbglLayer handle, or null on error.
public MbglLayer? AddLayerJson(string layerJson, string? beforeLayerId = null)
Parameters
Returns
AddLineLayer(string, string, string?)
public MbglLayer AddLineLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddLocationIndicatorLayer(string, string?)
public MbglLayer AddLocationIndicatorLayer(string layerId, string? beforeLayerId = null)
Parameters
Returns
AddRasterDemSource(string, string, int)
public MbglSource AddRasterDemSource(string sourceId, string url, int tileSize = 512)
Parameters
Returns
AddRasterLayer(string, string, string?)
public MbglLayer AddRasterLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddRasterSource(string, string, int)
public MbglSource AddRasterSource(string sourceId, string url, int tileSize = 512)
Parameters
Returns
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 MbglLayer AddSymbolLayer(string layerId, string sourceId, string? beforeLayerId = null)
Parameters
Returns
AddVectorSource(string, string)
public MbglSource AddVectorSource(string sourceId, string url)
Parameters
Returns
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 MbglLayer? 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 MbglSource? 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
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
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)