If there is no features option, all features will be translated.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
goog.provide('ol.interaction.Translate');
|
goog.provide('ol.interaction.Translate');
|
||||||
|
|
||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
|
goog.require('ol.Collection');
|
||||||
goog.require('ol.events.Event');
|
goog.require('ol.events.Event');
|
||||||
goog.require('ol.functions');
|
goog.require('ol.functions');
|
||||||
goog.require('ol.array');
|
goog.require('ol.array');
|
||||||
@@ -88,9 +89,12 @@ ol.interaction.Translate.handleDownEvent_ = function(event) {
|
|||||||
if (!this.lastCoordinate_ && this.lastFeature_) {
|
if (!this.lastCoordinate_ && this.lastFeature_) {
|
||||||
this.lastCoordinate_ = event.coordinate;
|
this.lastCoordinate_ = event.coordinate;
|
||||||
ol.interaction.Translate.handleMoveEvent_.call(this, event);
|
ol.interaction.Translate.handleMoveEvent_.call(this, event);
|
||||||
|
|
||||||
|
var features = this.features_ || new ol.Collection([this.lastFeature_]);
|
||||||
|
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new ol.interaction.Translate.Event(
|
new ol.interaction.Translate.Event(
|
||||||
ol.interaction.Translate.EventType.TRANSLATESTART, this.features_,
|
ol.interaction.Translate.EventType.TRANSLATESTART, features,
|
||||||
event.coordinate));
|
event.coordinate));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -108,9 +112,12 @@ ol.interaction.Translate.handleUpEvent_ = function(event) {
|
|||||||
if (this.lastCoordinate_) {
|
if (this.lastCoordinate_) {
|
||||||
this.lastCoordinate_ = null;
|
this.lastCoordinate_ = null;
|
||||||
ol.interaction.Translate.handleMoveEvent_.call(this, event);
|
ol.interaction.Translate.handleMoveEvent_.call(this, event);
|
||||||
|
|
||||||
|
var features = this.features_ || new ol.Collection([this.lastFeature_]);
|
||||||
|
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new ol.interaction.Translate.Event(
|
new ol.interaction.Translate.Event(
|
||||||
ol.interaction.Translate.EventType.TRANSLATEEND, this.features_,
|
ol.interaction.Translate.EventType.TRANSLATEEND, features,
|
||||||
event.coordinate));
|
event.coordinate));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -129,22 +136,18 @@ ol.interaction.Translate.handleDragEvent_ = function(event) {
|
|||||||
var deltaX = newCoordinate[0] - this.lastCoordinate_[0];
|
var deltaX = newCoordinate[0] - this.lastCoordinate_[0];
|
||||||
var deltaY = newCoordinate[1] - this.lastCoordinate_[1];
|
var deltaY = newCoordinate[1] - this.lastCoordinate_[1];
|
||||||
|
|
||||||
if (this.features_) {
|
var features = this.features_ || new ol.Collection([this.lastFeature_]);
|
||||||
this.features_.forEach(function(feature) {
|
|
||||||
var geom = feature.getGeometry();
|
features.forEach(function(feature) {
|
||||||
geom.translate(deltaX, deltaY);
|
var geom = feature.getGeometry();
|
||||||
feature.setGeometry(geom);
|
|
||||||
});
|
|
||||||
} else if (this.lastFeature_) {
|
|
||||||
var geom = this.lastFeature_.getGeometry();
|
|
||||||
geom.translate(deltaX, deltaY);
|
geom.translate(deltaX, deltaY);
|
||||||
this.lastFeature_.setGeometry(geom);
|
feature.setGeometry(geom);
|
||||||
}
|
});
|
||||||
|
|
||||||
this.lastCoordinate_ = newCoordinate;
|
this.lastCoordinate_ = newCoordinate;
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new ol.interaction.Translate.Event(
|
new ol.interaction.Translate.Event(
|
||||||
ol.interaction.Translate.EventType.TRANSLATING, this.features_,
|
ol.interaction.Translate.EventType.TRANSLATING, features,
|
||||||
newCoordinate));
|
newCoordinate));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -187,19 +190,13 @@ ol.interaction.Translate.handleMoveEvent_ = function(event) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.interaction.Translate.prototype.featuresAtPixel_ = function(pixel, map) {
|
ol.interaction.Translate.prototype.featuresAtPixel_ = function(pixel, map) {
|
||||||
var found = null;
|
return map.forEachFeatureAtPixel(pixel,
|
||||||
|
|
||||||
var intersectingFeature = map.forEachFeatureAtPixel(pixel,
|
|
||||||
function(feature) {
|
function(feature) {
|
||||||
return feature;
|
if (!this.features_ ||
|
||||||
|
ol.array.includes(this.features_.getArray(), feature)) {
|
||||||
|
return feature;
|
||||||
|
}
|
||||||
}, this, this.layerFilter_);
|
}, this, this.layerFilter_);
|
||||||
|
|
||||||
if (this.features_ &&
|
|
||||||
ol.array.includes(this.features_.getArray(), intersectingFeature)) {
|
|
||||||
found = intersectingFeature;
|
|
||||||
}
|
|
||||||
|
|
||||||
return found;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user