Merge pull request #3417 from fperucic/ol.interaction.Snap-extentFix

ol.interaction.Snap extent fix
This commit is contained in:
Andreas Hocevar
2015-03-30 16:08:57 +02:00
+18 -16
View File
@@ -27,8 +27,8 @@ goog.require('ol.structs.RBush');
/** /**
* @classdesc * @classdesc
* Handles snapping of vector features while modifying or drawing them. The * Handles snapping of vector features while modifying or drawing them. The
* features can come from a {@link ol.source.Vector}, a {@link ol.Collection} * features can come from a {@link ol.source.Vector} or {@link ol.Collection}
* or a plain array. Any interaction object that allows the user to interact * Any interaction object that allows the user to interact
* with the features using the mouse can benefit from the snapping, as long * with the features using the mouse can benefit from the snapping, as long
* as it is added before. * as it is added before.
* *
@@ -94,6 +94,15 @@ ol.interaction.Snap = function(opt_options) {
*/ */
this.indexedFeaturesExtents_ = {}; this.indexedFeaturesExtents_ = {};
/**
* If a feature geometry changes while a pointer drag|move event occurs, the
* feature doesn't get updated right away. It will be at the next 'pointerup'
* event fired.
* @type {Object.<number, ol.Feature>}
* @private
*/
this.pendingFeatures_ = {};
/** /**
* Used for distance sorting in sortByDistance_ * Used for distance sorting in sortByDistance_
* @type {ol.Coordinate} * @type {ol.Coordinate}
@@ -154,7 +163,8 @@ ol.interaction.Snap.prototype.addFeature = function(feature, opt_listen) {
var segmentWriter = this.SEGMENT_WRITERS_[geometry.getType()]; var segmentWriter = this.SEGMENT_WRITERS_[geometry.getType()];
if (goog.isDef(segmentWriter)) { if (goog.isDef(segmentWriter)) {
var feature_uid = goog.getUid(feature); var feature_uid = goog.getUid(feature);
this.indexedFeaturesExtents_[feature_uid] = geometry.getExtent(); this.indexedFeaturesExtents_[feature_uid] = geometry.getExtent(
ol.extent.createEmpty());
segmentWriter.call(this, feature, geometry); segmentWriter.call(this, feature, geometry);
if (listen) { if (listen) {
@@ -174,16 +184,6 @@ goog.exportProperty(
ol.interaction.Snap.prototype.addFeature); ol.interaction.Snap.prototype.addFeature);
/**
* If a feature geometry changes while a pointer drag|move event occurs, the
* feature doesn't get updated right away. It will be at the next 'pointerup'
* event fired.
* @type {Object.<number, ol.Feature>}
* @private
*/
ol.interaction.Snap.prototype.pendingFeatures_ = null;
/** /**
* @param {ol.Feature} feature Feature. * @param {ol.Feature} feature Feature.
* @private * @private
@@ -602,9 +602,11 @@ ol.interaction.Snap.handleEvent_ = function(evt) {
* @private * @private
*/ */
ol.interaction.Snap.handleUpEvent_ = function(evt) { ol.interaction.Snap.handleUpEvent_ = function(evt) {
goog.array.forEach(goog.object.getValues(this.pendingFeatures_), var featuresToUpdate = goog.object.getValues(this.pendingFeatures_);
this.updateFeature_, this); if (featuresToUpdate.length) {
this.pendingFeatures_ = {}; goog.array.forEach(featuresToUpdate, this.updateFeature_, this);
this.pendingFeatures_ = {};
}
return false; return false;
}; };