Allow layers to be passed as an array when creating a map

This commit is contained in:
Tom Payne
2013-03-06 13:04:56 +01:00
parent 388eac3838
commit 61982646ba
2 changed files with 13 additions and 3 deletions

View File

@@ -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

View File

@@ -823,8 +823,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();