From 2420ad56c10763144bbc30ceee511e31ace250bb Mon Sep 17 00:00:00 2001 From: Thomas Chandelle Date: Thu, 3 Nov 2016 13:10:24 +0100 Subject: [PATCH] If there is no features option, all features will be translated. --- src/ol/interaction/translate.js | 45 +++++++++++++++------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/ol/interaction/translate.js b/src/ol/interaction/translate.js index 555c65432c..c761f81ec8 100644 --- a/src/ol/interaction/translate.js +++ b/src/ol/interaction/translate.js @@ -1,6 +1,7 @@ goog.provide('ol.interaction.Translate'); goog.require('ol'); +goog.require('ol.Collection'); goog.require('ol.events.Event'); goog.require('ol.functions'); goog.require('ol.array'); @@ -88,9 +89,12 @@ ol.interaction.Translate.handleDownEvent_ = function(event) { if (!this.lastCoordinate_ && this.lastFeature_) { this.lastCoordinate_ = event.coordinate; ol.interaction.Translate.handleMoveEvent_.call(this, event); + + var features = this.features_ || new ol.Collection([this.lastFeature_]); + this.dispatchEvent( new ol.interaction.Translate.Event( - ol.interaction.Translate.EventType.TRANSLATESTART, this.features_, + ol.interaction.Translate.EventType.TRANSLATESTART, features, event.coordinate)); return true; } @@ -108,9 +112,12 @@ ol.interaction.Translate.handleUpEvent_ = function(event) { if (this.lastCoordinate_) { this.lastCoordinate_ = null; ol.interaction.Translate.handleMoveEvent_.call(this, event); + + var features = this.features_ || new ol.Collection([this.lastFeature_]); + this.dispatchEvent( new ol.interaction.Translate.Event( - ol.interaction.Translate.EventType.TRANSLATEEND, this.features_, + ol.interaction.Translate.EventType.TRANSLATEEND, features, event.coordinate)); return true; } @@ -129,22 +136,18 @@ ol.interaction.Translate.handleDragEvent_ = function(event) { var deltaX = newCoordinate[0] - this.lastCoordinate_[0]; var deltaY = newCoordinate[1] - this.lastCoordinate_[1]; - if (this.features_) { - this.features_.forEach(function(feature) { - var geom = feature.getGeometry(); - geom.translate(deltaX, deltaY); - feature.setGeometry(geom); - }); - } else if (this.lastFeature_) { - var geom = this.lastFeature_.getGeometry(); + var features = this.features_ || new ol.Collection([this.lastFeature_]); + + features.forEach(function(feature) { + var geom = feature.getGeometry(); geom.translate(deltaX, deltaY); - this.lastFeature_.setGeometry(geom); - } + feature.setGeometry(geom); + }); this.lastCoordinate_ = newCoordinate; this.dispatchEvent( new ol.interaction.Translate.Event( - ol.interaction.Translate.EventType.TRANSLATING, this.features_, + ol.interaction.Translate.EventType.TRANSLATING, features, newCoordinate)); } }; @@ -187,19 +190,13 @@ ol.interaction.Translate.handleMoveEvent_ = function(event) { * @private */ ol.interaction.Translate.prototype.featuresAtPixel_ = function(pixel, map) { - var found = null; - - var intersectingFeature = map.forEachFeatureAtPixel(pixel, + return map.forEachFeatureAtPixel(pixel, function(feature) { - return feature; + if (!this.features_ || + ol.array.includes(this.features_.getArray(), feature)) { + return feature; + } }, this, this.layerFilter_); - - if (this.features_ && - ol.array.includes(this.features_.getArray(), intersectingFeature)) { - found = intersectingFeature; - } - - return found; };