LayerCollection

Extends ILayer, IMapObjectCollection.

Collection of layers.

Constructor | Fields | Events | Methods

Constructor

LayerCollection([options])

Collection of layers.

Parameters:

Parameter

Default value

Description

options

Type: Object

Layer options.

Fields

Name

Type

Description

events

IEventManager

Event manager.

Inherited from IEventEmitter.

options

IOptionManager

Options manager.

Inherited from ICustomizable.

Events

Name

Description

add

A child object was added.

Inherited from ICollection.

brightnesschange

Layer brightness change event.

Inherited from ILayer.

copyrightschange

Event for changes to available copyright information.

Inherited from ILayer.

mapchange

Map reference changed. Data fields:

  • oldMap - Old map.
  • newMap - New map.

Inherited from IParentOnMap.

optionschange

Change to the object options.

Inherited from ICustomizable.

parentchange

The parent object reference changed.

Data fields:

  • oldParent - Old parent.
  • newParent - New parent.

Inherited from IChild.

remove

A child object was deleted.

Inherited from ICollection.

tileloadchange

Tile upload status change event. Data fields:

  • readyTileNumber - Number of ready tiles. A tile is considered ready when it is downloaded and rendered. Type: Number.
  • totalTileNumber - Total number of visible tiles. Type: Number.

Inherited from ILayer.

zoomrangechange

Event for changes to available information about the zoom level range.

Inherited from ILayer.

Methods

Name

Returns

Description

add(child)

LayerCollection

Adds a child object to the collection.

each(callback[, context])

Iterates through all the items in the collection and calls a handler function for each of them.

getBrightness()

Number

Returns layer brightness as a number from 0 to 1.

getCopyrights([coords[, zoom]])

vow.Promise

Requests information about copyrights at the specified point with the specified zoom. If the point and zoom are omitted, it uses the map center and zoom.

getIterator()

IIterator

Returns iterator for the collection.

Inherited from ICollection.

getMap()

Map

Returns reference to the map.

Inherited from IParentOnMap.

getParent()

IParentOnMap|null

Returns link to the parent object, or null if the parent element was not set.

Inherited from IChildOnMap.

getZoomRange([coords])

vow.Promise

Checks the available range of zoom levels at the specified point. If there is data, the returned promise object will be resolved and will pass as a result an array of two numbers - the minimum and maximum zoom level available at the point. If there is no data, the promise is rejected with an error. If the collection does not have a single descendant providing information about the zoom level range, the promise will be rejected with the "noProvider" message.

remove(child)

LayerCollection

Removes a child object from the collection.

removeAll()

Collection

Deletes all the items from a collection.

setParent(parent)

IChildOnMap

Sets the parent object. If the null value is passed, the manager element will only be deleted from the current parent object.

Inherited from IChildOnMap.

Methods details

add

{LayerCollection} add(child)

Adds a child object to the collection.

Returns self-reference.

Parameters:

Parameter

Default value

Description

child*

Type: ILayer|String

Layer to add (key from layer.storage or an instance of the ILayer class).

* Mandatory parameter/option.

Example:

// Let's say we want to add several layers to our collection.
var layerCollection = new ymaps.LayerCollection();
var customLayer = new ymaps.Layer('http://tile.openstreetmap.org/%z/%x/%y.png', {
    projection: ymaps.projection.sphericalMercator
});
// We can use a key from layer.storage to set the layer.
var satelliteLayer = 'yandex#satellite';
// Adding layers to our collection.
layerCollection
    .add(customLayer)
    .add(satelliteLayer);

each

{} each(callback[, context])

Iterates through all the items in the collection and calls a handler function for each of them.

Parameters:

Parameter

Default value

Description

callback*

Type: Function

Handler function.

context

Type: Object

Context for the function.

* Mandatory parameter/option.

getBrightness

{Number} getBrightness()

Returns layer brightness as a number from 0 to 1.

getCopyrights

{vow.Promise} getCopyrights([coords[, zoom]])

Requests information about copyrights at the specified point with the specified zoom. If the point and zoom are omitted, it uses the map center and zoom.

Returns a Promise object that will be resolved and will pass as a result an array of strings or DOM elements with information about copyrights.

Parameters:

Parameter

Default value

Description

coords

Type: Number[]

The point on the map that copyright information is being requested for.

zoom

Type: Number

The zoom level that copyright information is being requested for.

Example:

// Let's say we have a service that can return copyrights
// using the coordinates and zoom level
myLayer.getCopyrights = function (coords, zoom) {
    var deferred = ymaps.vow.defer();
    $.ajax('url/to/copyrights/provider?ll=' +
        (coords || map.getCenter()).join(',') + '&z=' +
        (zoom || map.getZoom()),
    function (res) {
        deferred.resolve(res || []);
    });
    return deferred.promise();
};

getZoomRange

{vow.Promise} getZoomRange([coords])

Checks the available range of zoom levels at the specified point. If there is data, the returned promise object will be resolved and will pass as a result an array of two numbers - the minimum and maximum zoom level available at the point. If there is no data, the promise is rejected with an error. If the collection does not have a single descendant providing information about the zoom level range, the promise will be rejected with the "noProvider" message.

Returns Promise object.

Parameters:

Parameter

Default value

Description

coords

Type: Number[]

Coordinates of a point. If omitted, the current map center is used.

Example:

// Assuming that our layer was drawn for the 2-15 zoom level for the entire earth
myLayer.getZoomRange = function () {
    return ymaps.vow.resolve([2, 15]);
}

remove

{LayerCollection} remove(child)

Removes a child object from the collection.

Returns self-reference.

Parameters:

Parameter

Default value

Description

child*

Type: ILayer|String

Layer to delete (key string from layer.storage or an instance of the ILayer class).

* Mandatory parameter/option.

removeAll

{Collection} removeAll()

Deletes all the items from a collection.

Returns self-reference.

Previous