Move ol.Object.createFromObject to its proper home as a simplified API function
This commit is contained in:
@@ -5,6 +5,7 @@ goog.require('goog.dom');
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.Layer');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.Object');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.createMap');
|
||||
goog.require('ol.layer.OpenStreetMap');
|
||||
@@ -35,6 +36,12 @@ ol3.Layers;
|
||||
ol3.MapOptions;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object|ol.Object}
|
||||
*/
|
||||
ol3.Object;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {ol.Projection|string}
|
||||
*/
|
||||
@@ -125,6 +132,23 @@ ol3.map = function(opt_mapOptions) {
|
||||
goog.exportProperty(ol3, 'map', ol3.map);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.Object} object Object.
|
||||
* @return {ol.Object} Object.
|
||||
*/
|
||||
ol3.object = function(object) {
|
||||
if (object instanceof ol.Object) {
|
||||
return object;
|
||||
} else if (goog.isObject(object)) {
|
||||
var values = /** @type {Object} */ object;
|
||||
return new ol.Object(values);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
goog.exportProperty(ol3, 'object', ol3.object);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.Projection} projection Projection.
|
||||
* @return {ol.Projection} Projection.
|
||||
|
||||
19
src/api/object_test.js
Normal file
19
src/api/object_test.js
Normal file
@@ -0,0 +1,19 @@
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('ol.Object');
|
||||
goog.require('ol3');
|
||||
|
||||
|
||||
function testObject1() {
|
||||
var obj = {k: 1};
|
||||
obj = ol3.object(obj);
|
||||
assertTrue(obj instanceof ol.Object);
|
||||
assertEquals(1, obj.get('k'));
|
||||
}
|
||||
|
||||
|
||||
function testObject2() {
|
||||
var obj1 = new ol.Object();
|
||||
var obj2 = ol3.object(obj1);
|
||||
assertTrue(obj2 === obj1);
|
||||
}
|
||||
|
||||
@@ -67,21 +67,6 @@ ol.Object.capitalize = function(str) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Object|Object} arg Argument.
|
||||
* @return {ol.Object} Object.
|
||||
*/
|
||||
ol.Object.create = function(arg) {
|
||||
if (arg instanceof ol.Object) {
|
||||
return arg;
|
||||
} else {
|
||||
var object = new ol.Object();
|
||||
object.setOptions(arg);
|
||||
return object;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Object} obj Object.
|
||||
* @return {Object.<string, {target: ol.Object, key: string}>} Accessors.
|
||||
|
||||
@@ -367,21 +367,6 @@ function testBindSelf() {
|
||||
}
|
||||
|
||||
|
||||
function testCreateFromObject() {
|
||||
var obj = {k: 1};
|
||||
obj = ol.Object.create(obj);
|
||||
assertTrue(obj instanceof ol.Object);
|
||||
assertEquals(1, obj.get('k'));
|
||||
}
|
||||
|
||||
|
||||
function testCreateFromObject() {
|
||||
var obj1 = new ol.Object();
|
||||
var obj2 = ol.Object.create(obj1);
|
||||
assertTrue(obj2 === obj1);
|
||||
}
|
||||
|
||||
|
||||
function testCreateWithOptions() {
|
||||
var obj = new ol.Object({k: 1});
|
||||
assertEquals(1, obj.get('k'));
|
||||
|
||||
Reference in New Issue
Block a user