geometry-less vector features aren't cloneable, r=pspencer (closes #1557)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@7252 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2008-05-22 13:42:23 +00:00
parent 069a72b5e7
commit 7f8c5d0c13
2 changed files with 11 additions and 5 deletions

View File

@@ -80,7 +80,7 @@ OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, {
OpenLayers.Feature.prototype.initialize.apply(this,
[null, null, attributes]);
this.lonlat = null;
this.geometry = geometry;
this.geometry = geometry ? geometry : null;
this.state = null;
this.attributes = {};
if (attributes) {
@@ -113,9 +113,10 @@ OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, {
* {<OpenLayers.Feature.Vector>} An exact clone of this vector feature.
*/
clone: function () {
return new OpenLayers.Feature.Vector(this.geometry.clone(),
this.attributes,
this.style);
return new OpenLayers.Feature.Vector(
this.geometry ? this.geometry.clone() : null,
this.attributes,
this.style);
},
/**

View File

@@ -59,7 +59,7 @@
}
function test_Feature_Vector_clone(t) {
t.plan(5);
t.plan(6);
var geometry = new OpenLayers.Geometry.Point(Math.random(),
Math.random());
@@ -79,6 +79,11 @@
"geometry.x property set properly");
t.eq(clone.geometry.y, geometry.y,
"geometry.y property set properly");
feature = new OpenLayers.Feature.Vector();
clone = feature.clone();
t.ok(clone instanceof OpenLayers.Feature.Vector,
"clone can clone geometry-less features");
}