Skip to content

LayerOrderingRepository

Defined in: leaflet/ext/layer_ordering.ts:24

This class provides a way to reliably add and remove layers to a map in a way that always preserves the desired layering of the layer on top of each other, but is independent of the order in which the layers are added or removed.

Our layers will have an integer "layer bucket". All layers of a lower bucket will always be placed under layers of a higher bucket. MapLibre's API only provides layering control with the "beforeId" parameter of its addLayer function. This class keeps track of all added layers and their buckets, and when a new layer is added it translates its "bucket id" into the needed "beforeId" parameter for MapLibre.

Caution: O(N^2) complexity in relation to the number of layers. Assumes we won't ever use more than ~10 layers. Assumes unique layerIDs (MapLibre does too I think?).

Methods

addLayerAndGetBeforeId()

addLayerAndGetBeforeId(layerID: string, bucketID?: number): string

Defined in: leaflet/ext/layer_ordering.ts:36

Call when a layer is about to be added to MapLibre. Finds and returns the beforeId parameter that should be used when calling addLayer.

Parameters

Parameter Type Description
layerID string The string ID of the layer to be added. The layer must later also be added to MapLibre using this same string ID.
bucketID? number The numerical ID of the target layer bucket.

Returns

string

The indended beforeId parameter for MapLibre's addLayer that will place this layer at the correct place in the layer order.


removeLayer()

removeLayer(layerId: string): void

Defined in: leaflet/ext/layer_ordering.ts:70

Call when a given layer is removed from MapLibre.

Parameters

Parameter Type Description
layerId string The string ID of the layer to be removed. Must be the same one that was passed to MapLibre. Does nothing if the specified layerId is not present.

Returns

void