LayerCollection
Extends ILayer, IMapObjectCollection.
Collection of layers.
Constructor | Fields | Events | Methods
Constructor
LayerCollection([options])
Collection of layers.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Object Layer options. |
Fields
Name |
Type |
Description |
Event manager. Inherited from IEventEmitter. |
||
Options manager. Inherited from ICustomizable. |
Events
Name |
Description |
A child object was added. Inherited from ICollection. |
|
Layer brightness change event. Inherited from ILayer. |
|
Event for changes to available copyright information. Inherited from ILayer. |
|
Map reference changed. Data fields:
Inherited from IParentOnMap. |
|
Change to the object options. Inherited from ICustomizable. |
|
The parent object reference changed. Data fields:
Inherited from IChild. |
|
A child object was deleted. Inherited from ICollection. |
|
Tile upload status change event. Data fields:
Inherited from ILayer. |
|
Event for changes to available information about the zoom level range. Inherited from ILayer. |
Methods
Name |
Returns |
Description |
Adds a child object to the collection. |
||
Iterates through all the items in the collection and calls a handler function for each of them. |
||
Number |
Returns layer brightness as a number from 0 to 1. |
|
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 iterator for the collection. Inherited from ICollection. |
||
getMap() |
Returns reference to the map. Inherited from IParentOnMap. |
|
IParentOnMap|null |
Returns link to the parent object, or null if the parent element was not set. Inherited from IChildOnMap. |
|
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. |
||
Removes a child object from the collection. |
||
Deletes all the items from a collection. |
||
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 |
— |
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 |
— |
Type: Function Handler function. |
|
— |
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 |
— |
Type: Number[] The point on the map that copyright information is being requested for. |
|
— |
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 |
— |
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 |
— |
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.
Mandatory parameter/option.