Move ol.Collection.create to ol3.collection
This commit is contained in:
@@ -2,6 +2,7 @@ goog.provide('ol3');
|
||||
goog.provide('ol3.layer');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('ol.Collection');
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.Layer');
|
||||
goog.require('ol.Map');
|
||||
@@ -14,21 +15,21 @@ goog.require('ol.layer.OpenStreetMap');
|
||||
goog.exportSymbol('ol3', ol3);
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Array|ol.Collection}
|
||||
*/
|
||||
ol3.Collection;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Array.<number>|ol.Coordinate|{x: number, y: number}}
|
||||
*/
|
||||
ol3.Coordinate;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Array.<ol.Layer>|ol.Collection}
|
||||
*/
|
||||
ol3.Layers;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{center: (ol3.Coordinate|undefined),
|
||||
* layers: (ol3.Layers|undefined),
|
||||
* layers: (ol3.Collection|undefined),
|
||||
* renderTo: (Element|string|undefined),
|
||||
* resolution: (number|undefined),
|
||||
* zoom: (number|undefined)}}
|
||||
@@ -48,6 +49,23 @@ ol3.Object;
|
||||
ol3.Projection;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.Collection} collection Collection.
|
||||
* @return {ol.Collection} Collection.
|
||||
*/
|
||||
ol3.collection = function(collection) {
|
||||
if (collection instanceof ol.Collection) {
|
||||
return collection;
|
||||
} else if (goog.isArray(collection)) {
|
||||
var array = /** @type {Array} */ collection;
|
||||
return new ol.Collection(collection);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
goog.exportProperty(ol3, 'collection', ol3.collection);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.Coordinate} coordinate Coordinate.
|
||||
* @return {ol.Coordinate} Coordinate.
|
||||
@@ -80,22 +98,6 @@ ol3.layer.osm = function() {
|
||||
goog.exportProperty(ol3.layer, 'osm', ol3.layer.osm);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.Layers} layers Layers.
|
||||
* @return {ol.Collection} Layers.
|
||||
*/
|
||||
ol3.layers = function(layers) {
|
||||
if (layers instanceof ol.Collection) {
|
||||
return layers;
|
||||
} else if (goog.isArray(layers)) {
|
||||
return new ol.Collection(layers);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
goog.exportProperty(ol3, 'layers', ol3.layers);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.MapOptions=} opt_mapOptions Options.
|
||||
* @return {ol.Map} Map.
|
||||
@@ -104,7 +106,7 @@ ol3.map = function(opt_mapOptions) {
|
||||
var options = opt_mapOptions || {};
|
||||
var center = ol3.coordinate(/** @type {ol3.Coordinate} */
|
||||
(goog.object.get(options, 'center', null)));
|
||||
var layers = ol3.layers(/** @type {ol3.Layers} */
|
||||
var layers = ol3.collection(/** @type {ol3.Collection} */
|
||||
(goog.object.get(options, 'layers', null)));
|
||||
var projection = ol3.projection(/** @type {ol3.Projection} */
|
||||
(goog.object.get(options, 'projection', 'EPSG:3857')));
|
||||
|
||||
22
src/api/collection_test.js
Normal file
22
src/api/collection_test.js
Normal file
@@ -0,0 +1,22 @@
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('ol.Collection');
|
||||
goog.require('ol3');
|
||||
|
||||
|
||||
function testCreateFromArray() {
|
||||
var array = [0, 1, 2];
|
||||
var collection = ol3.collection(array);
|
||||
assertTrue(collection instanceof ol.Collection);
|
||||
assertEquals(3, collection.getLength());
|
||||
assertEquals(0, collection.getAt(0));
|
||||
assertEquals(1, collection.getAt(1));
|
||||
assertEquals(2, collection.getAt(2));
|
||||
}
|
||||
|
||||
|
||||
function testCreateFromCollection() {
|
||||
var collection1 = new ol.Collection();
|
||||
var collection2 = ol3.collection(collection1);
|
||||
assertTrue(collection1 === collection2);
|
||||
}
|
||||
|
||||
@@ -90,19 +90,6 @@ ol.Collection = function(opt_array) {
|
||||
goog.inherits(ol.Collection, ol.Object);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Collection|Array} arg Argument.
|
||||
* @return {ol.Collection} Collection.
|
||||
*/
|
||||
ol.Collection.create = function(arg) {
|
||||
if (arg instanceof ol.Collection) {
|
||||
return arg;
|
||||
} else {
|
||||
return new ol.Collection(arg);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
ol.Collection.prototype.clear = function() {
|
||||
|
||||
@@ -143,26 +143,8 @@ function testSetAtBeyondEnd() {
|
||||
}
|
||||
|
||||
|
||||
function testCreateFromArray() {
|
||||
var array = [0, 1, 2];
|
||||
var collection = ol.Collection.create(array);
|
||||
assertTrue(collection instanceof ol.Collection);
|
||||
assertEquals(3, collection.getLength());
|
||||
assertEquals(0, collection.getAt(0));
|
||||
assertEquals(1, collection.getAt(1));
|
||||
assertEquals(2, collection.getAt(2));
|
||||
}
|
||||
|
||||
|
||||
function testCreateFromCollection() {
|
||||
var collection1 = new ol.Collection();
|
||||
var collection2 = ol.Collection.create(collection1);
|
||||
assertTrue(collection1 === collection2);
|
||||
}
|
||||
|
||||
|
||||
function testLengthChangeInsertAt() {
|
||||
var collection = ol.Collection.create([0, 1, 2]);
|
||||
var collection = new ol.Collection([0, 1, 2]);
|
||||
var lengthEventDispatched;
|
||||
goog.events.listen(collection, 'length_changed', function() {
|
||||
lengthEventDispatched = true;
|
||||
@@ -173,7 +155,7 @@ function testLengthChangeInsertAt() {
|
||||
|
||||
|
||||
function testLengthChangeRemoveAt() {
|
||||
var collection = ol.Collection.create([0, 1, 2]);
|
||||
var collection = new ol.Collection([0, 1, 2]);
|
||||
var lengthEventDispatched;
|
||||
goog.events.listen(collection, 'length_changed', function() {
|
||||
lengthEventDispatched = true;
|
||||
@@ -184,7 +166,7 @@ function testLengthChangeRemoveAt() {
|
||||
|
||||
|
||||
function testLengthChangeSetAt() {
|
||||
var collection = ol.Collection.create([0, 1, 2]);
|
||||
var collection = new ol.Collection([0, 1, 2]);
|
||||
var lengthEventDispatched;
|
||||
goog.events.listen(collection, 'length_changed', function() {
|
||||
lengthEventDispatched = true;
|
||||
@@ -195,7 +177,7 @@ function testLengthChangeSetAt() {
|
||||
|
||||
|
||||
function testForEach() {
|
||||
var collection = ol.Collection.create([1, 2, 4]);
|
||||
var collection = new ol.Collection([1, 2, 4]);
|
||||
var sum = 0;
|
||||
collection.forEach(function(elem) {
|
||||
sum += elem;
|
||||
@@ -205,7 +187,7 @@ function testForEach() {
|
||||
|
||||
|
||||
function testForEachScope() {
|
||||
var collection = ol.Collection.create([0]);
|
||||
var collection = new ol.Collection([0]);
|
||||
var that;
|
||||
var uniqueObj = {};
|
||||
collection.forEach(function(elem) {
|
||||
|
||||
Reference in New Issue
Block a user