Do not call preFeatureInsert() and onFeatureInsert() callbacks when the modify feature control and the regular polygon handler internally adds point geometries to the layer. This is accomplished by adding an 'options' argument to the addFeatures() method in Layer.Vector. If that options argument has the silent property set to true, then the preFeatureInsert() and onFeatureInsert() callbacks aren't called. Thanks tschaub and fredj for your input. Thanks crschmidt for the final review. (closes #1148)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@5470 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2007-12-17 14:36:39 +00:00
parent ccf16fa024
commit dc2cc625f3
4 changed files with 33 additions and 9 deletions

View File

@@ -514,8 +514,8 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
} }
} }
collectComponentVertices.call(this, this.feature.geometry); collectComponentVertices.call(this, this.feature.geometry);
this.layer.addFeatures(this.vertices); this.layer.addFeatures(this.vertices, {silent: true});
this.layer.addFeatures(this.virtualVertices); this.layer.addFeatures(this.virtualVertices, {silent: true});
}, },
/** /**
@@ -534,7 +534,7 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
geometry.move(x, y); geometry.move(x, y);
} }
this.dragHandle = origin; this.dragHandle = origin;
this.layer.addFeatures([this.dragHandle]); this.layer.addFeatures([this.dragHandle], {silent: true});
}, },
/** /**
@@ -574,7 +574,7 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
} }
} }
this.radiusHandle = radius; this.radiusHandle = radius;
this.layer.addFeatures([this.radiusHandle]); this.layer.addFeatures([this.radiusHandle], {silent: true});
}, },
/** /**

View File

@@ -216,7 +216,7 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
} }
this.feature = new OpenLayers.Feature.Vector(); this.feature = new OpenLayers.Feature.Vector();
this.createGeometry(); this.createGeometry();
this.layer.addFeatures([this.feature]); this.layer.addFeatures([this.feature], {silent: true});
this.layer.drawFeature(this.feature, this.style); this.layer.drawFeature(this.feature, this.style);
}, },

View File

@@ -242,12 +242,15 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
* *
* Parameters: * Parameters:
* features - {Array(<OpenLayers.Feature.Vector>)} * features - {Array(<OpenLayers.Feature.Vector>)}
* options - {Object}
*/ */
addFeatures: function(features) { addFeatures: function(features, options) {
if (!(features instanceof Array)) { if (!(features instanceof Array)) {
features = [features]; features = [features];
} }
var notify = !options || !options.silent;
for (var i = 0; i < features.length; i++) { for (var i = 0; i < features.length; i++) {
var feature = features[i]; var feature = features[i];
@@ -267,14 +270,18 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
feature.style = OpenLayers.Util.extend({}, this.style); feature.style = OpenLayers.Util.extend({}, this.style);
} }
if (notify) {
this.preFeatureInsert(feature); this.preFeatureInsert(feature);
}
if (this.drawn) { if (this.drawn) {
this.drawFeature(feature); this.drawFeature(feature);
} }
if (notify) {
this.onFeatureInsert(feature); this.onFeatureInsert(feature);
} }
}
}, },

View File

@@ -16,16 +16,33 @@
} }
function test_02_Layer_Vector_addFeatures(t) { function test_02_Layer_Vector_addFeatures(t) {
t.plan(2); t.plan(4);
var layer = new OpenLayers.Layer.Vector(name); var layer = new OpenLayers.Layer.Vector(name);
var point = new OpenLayers.Geometry.Point(-111.04, 45.68); var point = new OpenLayers.Geometry.Point(-111.04, 45.68);
var pointFeature = new OpenLayers.Feature.Vector(point); var pointFeature = new OpenLayers.Feature.Vector(point);
layer.preFeatureInsert = function(feature) {
t.ok(feature == pointFeature, "OpenLayers.Layer.Vector.addFeatures calls preFeatureInsert with the right arg");
}
layer.onFeatureInsert = function(feature) {
t.ok(feature == pointFeature, "OpenLayers.Layer.Vector.addFeatures calls onFeatureInsert with the right arg");
}
layer.addFeatures([pointFeature]); layer.addFeatures([pointFeature]);
t.eq(layer.features.length, 1, "OpenLayers.Layer.Vector.addFeatures adds something to the array"); t.eq(layer.features.length, 1, "OpenLayers.Layer.Vector.addFeatures adds something to the array");
t.ok(layer.features[0] == pointFeature, "OpenLayers.Layer.Vector.addFeatures returns an array of features"); t.ok(layer.features[0] == pointFeature, "OpenLayers.Layer.Vector.addFeatures returns an array of features");
layer.preFeatureInsert = function(feature) {
t.fail("OpenLayers.Layer.Vector.addFeatures calls preFeatureInsert while it must not");
}
layer.onFeatureInsert = function(feature) {
t.fail("OpenLayers.Layer.Vector.addFeatures calls onFeatureInsert while it must not");
}
layer.addFeatures([pointFeature], {silent: true});
} }
function test_03_Layer_Vector_removeFeatures(t) { function test_03_Layer_Vector_removeFeatures(t) {