Class: BackgroundLayerMgr service:ngeoBackgroundLayerMgr

ngeo.BackgroundLayerMgr

new 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.LayerHelper

Themes service.

Extends

  • ol.Observable

Members

(static, constant) BACKGROUNDLAYERGROUP_NAME

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.

getOpacityBgLayer(map)

Return the current background layer overlay of a given map, used by the opacity slider. null is returned if the map does not have an opacity background layer.

Parameters:
Name Type Description
map ol.Map

Map.

Returns:
ol.layer.Base

layer The opacity 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.

setOpacityBgLayer(map, layer)

Set an background layer overlay, used by the opacity slider.

Parameters:
Name Type Description
map ol.Map

The map.

layer ol.layer.Base

The opacity background layer.

updateDimensions(map, dimensions)

Parameters:
Name Type Description
map ol.Map

The map.

dimensions Object.

The global dimensions object.