Class: BackgroundLayerMgr service:ngeoBackgroundLayerMgr

ngeo.BackgroundLayerMgr

new BackgroundLayerMgr()

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

Extends

Methods

get(map)

Return the current background layer of a given map. null is returned if the map does not have a background layer.

Parameters:
Name Type Description
map ol.Map

Map.

Returns:
ol.layer.Base

layer The background layer.

set(map, layer)

Set the background layer of a map. If layer is null the background layer is removed.

Parameters:
Name Type Description
map ol.Map

The map.

layer ol.layer.Base

The new background layer.

Returns:
ol.layer.Base

The previous background layer.

updateDimensions(map, dimensions)

Parameters:
Name Type Description
map ol.Map

The map.

dimensions Object.

The global dimensions object.