Merge pull request #274 from twpayne/map-layers-api
ol.Collection versus array
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
@exportObjectLiteral ol.MapOptions
|
||||
@exportObjectLiteralProperty ol.MapOptions.controls Array.<ol.control.Control>|undefined
|
||||
@exportObjectLiteralProperty ol.MapOptions.interactions ol.Collection|undefined
|
||||
@exportObjectLiteralProperty ol.MapOptions.layers ol.Collection|undefined
|
||||
@exportObjectLiteralProperty ol.MapOptions.layers Array.<ol.layer.Layer>|ol.Collection|undefined
|
||||
@exportObjectLiteralProperty ol.MapOptions.renderer ol.RendererHint|undefined
|
||||
@exportObjectLiteralProperty ol.MapOptions.renderers Array.<ol.RendererHint>|undefined
|
||||
@exportObjectLiteralProperty ol.MapOptions.target Element|string
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
@exportClass ol.Map ol.MapOptions
|
||||
@exportProperty ol.Map.prototype.addLayer
|
||||
@exportProperty ol.Map.prototype.addPreRenderFunction
|
||||
@exportProperty ol.Map.prototype.addPreRenderFunctions
|
||||
@exportProperty ol.Map.prototype.getInteractions
|
||||
@exportProperty ol.Map.prototype.getRenderer
|
||||
@exportProperty ol.Map.prototype.removeLayer
|
||||
|
||||
@exportSymbol ol.RendererHint
|
||||
@exportProperty ol.RendererHint.CANVAS
|
||||
|
||||
@@ -292,6 +292,16 @@ ol.Map = function(mapOptions) {
|
||||
goog.inherits(ol.Map, ol.Object);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer Layer.
|
||||
*/
|
||||
ol.Map.prototype.addLayer = function(layer) {
|
||||
var layers = this.getLayers();
|
||||
goog.asserts.assert(goog.isDef(layers));
|
||||
layers.push(layer);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.PreRenderFunction} preRenderFunction Pre-render function.
|
||||
*/
|
||||
@@ -619,6 +629,18 @@ ol.Map.prototype.requestRenderFrame = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer Layer.
|
||||
* @return {ol.layer.Layer|undefined} The removed layer or undefined if the
|
||||
* layer was not found.
|
||||
*/
|
||||
ol.Map.prototype.removeLayer = function(layer) {
|
||||
var layers = this.getLayers();
|
||||
goog.asserts.assert(goog.isDef(layers));
|
||||
return /** @type {ol.layer.Layer|undefined} */ (layers.remove(layer));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} time Time.
|
||||
* @private
|
||||
@@ -823,8 +845,18 @@ ol.Map.createOptionsInternal = function(mapOptions) {
|
||||
*/
|
||||
var values = {};
|
||||
|
||||
values[ol.MapProperty.LAYERS] = goog.isDef(mapOptions.layers) ?
|
||||
mapOptions.layers : new ol.Collection();
|
||||
var layers;
|
||||
if (goog.isDef(mapOptions.layers)) {
|
||||
if (goog.isArray(mapOptions.layers)) {
|
||||
layers = new ol.Collection(goog.array.clone(mapOptions.layers));
|
||||
} else {
|
||||
goog.asserts.assert(mapOptions.layers instanceof ol.Collection);
|
||||
layers = mapOptions.layers;
|
||||
}
|
||||
} else {
|
||||
layers = new ol.Collection();
|
||||
}
|
||||
values[ol.MapProperty.LAYERS] = layers;
|
||||
|
||||
values[ol.MapProperty.VIEW] = goog.isDef(mapOptions.view) ?
|
||||
mapOptions.view : new ol.View2D();
|
||||
|
||||
Reference in New Issue
Block a user