From c33a3372d9d322d7a4c8293223ed19e79c84771b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Fri, 28 Mar 2014 16:03:34 +0100 Subject: [PATCH 1/3] Fix initial state of the Modify interaction Features that are in the features collection need to be added to the R-Tree. --- src/ol/interaction/modifyinteraction.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ol/interaction/modifyinteraction.js b/src/ol/interaction/modifyinteraction.js index 7b5f003351..d23e929186 100644 --- a/src/ol/interaction/modifyinteraction.js +++ b/src/ol/interaction/modifyinteraction.js @@ -110,6 +110,7 @@ ol.interaction.Modify = function(options) { */ this.features_ = options.features; + this.features_.forEach(this.addFeature_, this); goog.events.listen(this.features_, ol.CollectionEventType.ADD, this.addFeature_, false, this); goog.events.listen(this.features_, ol.CollectionEventType.REMOVE, From afa5f35cef94866e13df617fb58962a6424de9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Fri, 28 Mar 2014 16:07:03 +0100 Subject: [PATCH 2/3] Create the R-Tree in the Modify constructor In this way features can be added/removed to/from the R-Tree even when the interaction does not have a map. --- src/ol/interaction/modifyinteraction.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/ol/interaction/modifyinteraction.js b/src/ol/interaction/modifyinteraction.js index d23e929186..f9832ac122 100644 --- a/src/ol/interaction/modifyinteraction.js +++ b/src/ol/interaction/modifyinteraction.js @@ -80,7 +80,7 @@ ol.interaction.Modify = function(options) { * @type {Object.<*, ol.structs.RBush>} * @private */ - this.rBush_ = null; + this.rBush_ = new ol.structs.RBush(); /** * @type {number} @@ -140,15 +140,6 @@ goog.inherits(ol.interaction.Modify, ol.interaction.Pointer); * @inheritDoc */ ol.interaction.Modify.prototype.setMap = function(map) { - if (!goog.isNull(map)) { - if (goog.isNull(this.rBush_)) { - this.rBush_ = new ol.structs.RBush(); - } - } else { - // removing from a map, clean up - this.rBush_ = null; - } - this.overlay_.setMap(map); goog.base(this, 'setMap', map); }; From c82d5ba88e89d0ce956f325261b00ba55858bcb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Fri, 28 Mar 2014 16:09:52 +0100 Subject: [PATCH 3/3] Make the Modify interaction more robust This prevents a JavaScript error when features are added while the interaction does not have a map. --- src/ol/interaction/modifyinteraction.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ol/interaction/modifyinteraction.js b/src/ol/interaction/modifyinteraction.js index f9832ac122..9912e44ea4 100644 --- a/src/ol/interaction/modifyinteraction.js +++ b/src/ol/interaction/modifyinteraction.js @@ -156,7 +156,10 @@ ol.interaction.Modify.prototype.addFeature_ = function(evt) { if (goog.isDef(this.SEGMENT_WRITERS_[geometry.getType()])) { this.SEGMENT_WRITERS_[geometry.getType()].call(this, feature, geometry); } - this.handlePointerAtPixel_(this.lastPixel_, this.getMap()); + var map = this.getMap(); + if (!goog.isNull(map)) { + this.handlePointerAtPixel_(this.lastPixel_, map); + } };