If there is no features option, all features will be translated.

This commit is contained in:
Thomas Chandelle
2016-11-03 13:10:24 +01:00
parent 760a231306
commit 2420ad56c1

View File

@@ -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;
};