LayerManager

map.layers is a LayerManager instance that lets you add and remove map sources and layers as named groups. This is useful for overlaying external data — flood zones, planning boundaries, custom GeoJSON — on top of the base map.

Methods

Method Signature Description
add (id: string, style: Partial<StyleSpecification>) → void Register sources and layers under a namespace id. Accepts a style object (without the version key).
remove (id: string) → void Remove all sources and layers registered under id.
has (id: string) → boolean Returns true if the namespace id is currently registered.
clear () → void Remove all managed sources and layers.

Example

const map = new GeoCertaMap.GeoCertaMap({ container: '#map', zoom: 12 });

map.loaded.then(() => {
  // add a GeoJSON overlay namespaced as 'flood-zones'
  map.layers.add('flood-zones', {
    sources: {
      'flood-source': {
        type: 'geojson',
        data: {
          type: 'FeatureCollection',
          features: [ /* ... */ ],
        },
      },
    },
    layers: [
      {
        id: 'flood-fill',
        type: 'fill',
        source: 'flood-source',
        paint: {
          'fill-color': '#3b82f6',
          'fill-opacity': 0.35,
        },
      },
      {
        id: 'flood-outline',
        type: 'line',
        source: 'flood-source',
        paint: {
          'line-color': '#2563eb',
          'line-width': 1.5,
        },
      },
    ],
  });

  // check it exists
  map.layers.has('flood-zones'); // true

  // remove when no longer needed
  map.layers.remove('flood-zones');

  // or remove everything
  map.layers.clear();
});

Layers added via LayerManager are drawn on top of the base map but below drawn features. Wait for map.loaded before calling add to ensure the map is ready.