#856 - fix up clone method for vector features - give the geometry base class a clone (though it will likely never be used)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@3788 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -98,19 +98,16 @@ OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, {
|
||||
|
||||
/**
|
||||
* Method: clone
|
||||
* Create a clone of this vector feature. Does not set any non-standard
|
||||
* properties.
|
||||
*
|
||||
* Returns:
|
||||
* <OpenLayers.Feature> An exact clone of this OpenLayers.Feature
|
||||
* {<OpenLayers.Feature.Vector>} An exact clone of this vector feature.
|
||||
*/
|
||||
clone: function (obj) {
|
||||
if (obj == null) {
|
||||
obj = new OpenLayers.Feature(null, this.geometry.clone(), this.data);
|
||||
}
|
||||
|
||||
// catch any randomly tagged-on properties
|
||||
OpenLayers.Util.applyDefaults(obj, this);
|
||||
|
||||
return obj;
|
||||
clone: function () {
|
||||
return new OpenLayers.Feature.Vector(this.geometry.clone(),
|
||||
this.attributes,
|
||||
this.style);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,6 +49,18 @@ OpenLayers.Geometry = OpenLayers.Class({
|
||||
this.bounds = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: clone
|
||||
* Create a clone of this geometry. Does not set any non-standard
|
||||
* properties of the cloned geometry.
|
||||
*
|
||||
* Return:
|
||||
* {<OpenLayers.Geometry>} An exact clone of this geometry.
|
||||
*/
|
||||
clone: function() {
|
||||
return new OpenLayers.Geometry();
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the bounds for this Geometry.
|
||||
*
|
||||
|
||||
@@ -23,6 +23,29 @@
|
||||
"geometry.property set properly" );
|
||||
}
|
||||
|
||||
function test_Feature_Vector_clone(t) {
|
||||
t.plan(5);
|
||||
|
||||
var geometry = new OpenLayers.Geometry.Point(Math.random(),
|
||||
Math.random());
|
||||
var style = {foo: "bar"};
|
||||
var attributes = {bar: "foo"};
|
||||
|
||||
feature = new OpenLayers.Feature.Vector(geometry, attributes, style);
|
||||
var clone = feature.clone();
|
||||
|
||||
t.ok(clone instanceof OpenLayers.Feature.Vector,
|
||||
"new OpenLayers.Feature.Vector returns Feature.Vector object");
|
||||
t.eq(clone.attributes, attributes,
|
||||
"attributes property set properly");
|
||||
t.eq(clone.style, style,
|
||||
"style property set properly");
|
||||
t.eq(clone.geometry.x, geometry.x,
|
||||
"geometry.x property set properly");
|
||||
t.eq(clone.geometry.y, geometry.y,
|
||||
"geometry.y property set properly");
|
||||
}
|
||||
|
||||
|
||||
// -->
|
||||
</script>
|
||||
|
||||
@@ -14,6 +14,15 @@
|
||||
}
|
||||
|
||||
|
||||
function test_Geometry_clone(t) {
|
||||
t.plan(2);
|
||||
var geometry = new OpenLayers.Geometry();
|
||||
var clone = geometry.clone();
|
||||
|
||||
t.eq(clone.CLASS_NAME, "OpenLayers.Geometry", "correct CLASS_NAME")
|
||||
t.ok(clone.id.startsWith("OpenLayers.Geometry_"), "id correctly set");
|
||||
}
|
||||
|
||||
function test_02_Geometry_setBounds(t) {
|
||||
t.plan( 2 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user