How the map composes
MapLibre Compose has no map view object. MaplibreMap is a
composable, and map state lives in state objects: CameraState for
the camera and StyleState for the style. This page explains how
the library applies your composition to the underlying MapLibre style.
The style is base plus content
Section titled “The style is base plus content”A MapLibre style is a document with sources and layers. The baseStyle
parameter loads that document without modification. The content block of
MaplibreMap declares additions to it: your sources, your layers, and the
positions of your layers in the layer stack.
MaplibreMap(baseStyle = BaseStyle.Uri("https://tiles.openfreemap.org/styles/liberty")) { // Sources and layers declared here are added to the base style.}The library manages the sources and layers that you declare in the content
block, and does not modify the rest of the base style. To change a base style
layer, replace it with Anchor.Replace and declare its replacement
yourself.
Recomposition updates the style
Section titled “Recomposition updates the style”The content block is a Compose composition. When the state that it reads changes, it recomposes, and the library applies the difference to the style: a layer that is no longer in the composition is removed from the style, a new layer is added, and a changed property is updated in place. You do not call add or remove functions yourself.
This is the same contract as Compose UI: describe the map content for the current state, and let the runtime reconcile it.
Style switches re-apply your content
Section titled “Style switches re-apply your content”When baseStyle changes, the map loads the new style and the content block
recomposes into it. Your sources and layers are declared again on the new
style, so they persist across the switch without extra code. An Anchor that
names a base layer applies only when that layer exists in the new style.
Layer and source IDs
Section titled “Layer and source IDs”Layers and sources have string IDs because the underlying MapLibre style
identifies them by ID. Within one map, each layer ID must be unique, including
against the base style’s layers. A feature query takes layer IDs to limit its
scope, and an Anchor names a base style layer by its ID.