Skip to content

ym.modules.provider.LayerGroup

Overview

Used to group several layers and treat them as one. When you add a layer group to the map, all the layers added to or removed from the group are also added or removed on the map.

Initialization

Factory: ym.layerGroup(layers)

Creates a layer group (optionally with an initial set of layers).

Parameter Description Data type Default value
layers [optional] ILayer[]

Methods

addTo(map)

Adds the layer group to the map.

Parameter Description Data type Default value
map Map
  • Return: this

addLayer(layer)

Adds a specific layer to the group.

Parameter Description Data type Default value
layer ILayer
  • Return: this

removeLayer(layer)

Removes a specific layer from the group.

Parameter Description Data type Default value
layer ILayer
  • Return: this

removeLayer(id)

Removes a given layer of the specified ID from the group.

Parameter Description Data type Default value
id string
  • Return: this

hasLayer(layer)

Returns true when the specified layer is added to the group.

Parameter Description Data type Default value
layer ILayer
  • Return: bool

getLayer(id)

Returns the layer with the specified ID.

Parameter Description Data type Default value
id string
  • Return: ILayer

getLayers()

Returns an array of all layers added to the group.

  • Return: ILayer[]

clearLayers()

Removes all layers from the group.

  • Return: this

eachLayer(fn, context)

Iterates over the layers of the group and optionally gives the context of the iterator function.

group.eachLayer(function (layer) {    
   layer.bindPopup('Hello');
});
Parameter Description Data type Default value
fn Function
context [optional] Object
  • Return: this

toGeoJSON()

Returns a GeoJSON representation of the layer group (GeoJSON FeatureCollection).

  • Return: Object