Class: module:BackgroundLayerMgr service:ngeoBackgroundLayerMgr

ngeo.map.module:BackgroundLayerMgr.ngeo.map.module:BackgroundLayerMgr

new module:BackgroundLayerMgr(ngeoLayerHelper)

Provides a service for setting/unsetting background layers in maps.

The notion of background/base layers doesn't exist in OpenLayers. This service adds that notion.

Setting a background layer to map is done with the set function:

ngeoBackgroundLayerMgr.set(map, layer);

To unset the background layer pass null as the layer argument:

ngeoBackgroundLayerMgr.set(map, null);

The get function returns the current background layer of the map passed as an argument. null is returned if the map doesn't have a background layer.

The background layer is always added at index 0 in the map's layers collection. When a background layer is set it is inserted (at index 0) if the map does not already have a background layer, otherwise the new background layer replaces the previous one at index 0.

Users can subscribe to a 'change' event to get notified when the background layer changes:

ngeoBackgroundLayerMgr.on('change', function(e) {
  // do something with the layer
  let layer = ngeoBackgroundLayerMgr.get();
  // know which layer was used before
  let previous = e.previous
});

See our live examples: ../examples/backgroundlayer.html ../examples/backgroundlayerdropdown.html

Parameters:
Name Type Description
ngeoLayerHelper ngeo.map.LayerHelper

Themes service.

Extends

  • ol.Observable