From 299647a95754117f1c343206b4595c53f76801bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20Peru=C4=8Di=C4=87?= Date: Thu, 26 Mar 2015 22:36:38 +0100 Subject: [PATCH] remove unnecessary flag dragging_ --- src/ol/interaction/snapinteraction.js | 43 ++++++++------------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/src/ol/interaction/snapinteraction.js b/src/ol/interaction/snapinteraction.js index 4f29b24427..a55963eca0 100644 --- a/src/ol/interaction/snapinteraction.js +++ b/src/ol/interaction/snapinteraction.js @@ -8,7 +8,6 @@ goog.require('ol.Collection'); goog.require('ol.CollectionEvent'); goog.require('ol.CollectionEventType'); goog.require('ol.Feature'); -goog.require('ol.MapBrowserEvent.EventType'); goog.require('ol.Observable'); goog.require('ol.coordinate'); goog.require('ol.extent'); @@ -46,9 +45,9 @@ goog.require('ol.structs.RBush'); ol.interaction.Snap = function(opt_options) { goog.base(this, { - handleDownEvent: ol.interaction.Snap.handleDownAndUpEvent, handleEvent: ol.interaction.Snap.handleEvent, - handleUpEvent: ol.interaction.Snap.handleDownAndUpEvent + handleDownEvent: goog.functions.TRUE, + handleUpEvent: ol.interaction.Snap.handleUpEvent }); var options = goog.isDef(opt_options) ? opt_options : {}; @@ -125,8 +124,9 @@ goog.inherits(ol.interaction.Snap, ol.interaction.Pointer); ol.interaction.Snap.prototype.addFeature = function(feature, opt_listen) { var listen = goog.isDef(opt_listen) ? opt_listen : true; var geometry = feature.getGeometry(); - if (goog.isDef(this.SEGMENT_WRITERS_[geometry.getType()])) { - this.SEGMENT_WRITERS_[geometry.getType()].call(this, feature, geometry); + var segmentWriter = this.SEGMENT_WRITERS_[geometry.getType()]; + if (goog.isDef(segmentWriter)) { + segmentWriter.call(this, feature, geometry); } if (listen) { @@ -143,16 +143,6 @@ goog.exportProperty( ol.interaction.Snap.prototype.addFeature); -/** - * Flag turned on when detecting a pointer drag|move event, and turned off when - * detecting any other type of event. Skip the update of the geometry index - * while dragging. - * @type {boolean} - * @private - */ -ol.interaction.Snap.prototype.dragging_ = false; - - /** * 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' @@ -198,7 +188,7 @@ ol.interaction.Snap.prototype.getFeatures_ = function() { /** - * Handle 'pointerdown', 'pointermove' and 'pointerup' events. + * Handle all pointer events events. * @param {ol.MapBrowserEvent} evt A move event. * @return {boolean} Pass the event to other interactions. * @private @@ -251,7 +241,7 @@ ol.interaction.Snap.prototype.handleFeatureRemove_ = function(evt) { * @private */ ol.interaction.Snap.prototype.handleGeometryChanged_ = function(feature, evt) { - if (this.dragging_) { + if (this.handlingDownUpSequence) { if (goog.isNull(this.featurePending_)) { this.featurePending_ = feature; } @@ -563,14 +553,12 @@ ol.interaction.Snap.SegmentDataType; * @this {ol.interaction.Snap} * @api */ -ol.interaction.Snap.handleDownAndUpEvent = function(evt) { - this.dragging_ = false; - if (evt.type === ol.MapBrowserEvent.EventType.POINTERUP && - !goog.isNull(this.featurePending_)) { +ol.interaction.Snap.handleUpEvent = function(evt) { + if (!goog.isNull(this.featurePending_)) { this.updateFeature_(this.featurePending_); this.featurePending_ = null; } - return this.handleEvent_(evt); + return false; }; @@ -581,15 +569,8 @@ ol.interaction.Snap.handleDownAndUpEvent = function(evt) { * @api */ ol.interaction.Snap.handleEvent = function(mapBrowserEvent) { - var pass = true; - if (mapBrowserEvent.type === ol.MapBrowserEvent.EventType.POINTERDRAG || - mapBrowserEvent.type === ol.MapBrowserEvent.EventType.POINTERMOVE) { - pass = this.handleEvent_(mapBrowserEvent); - this.dragging_ = true; - } else { - this.dragging_ = false; - } - return ol.interaction.Pointer.handleEvent.call(this, mapBrowserEvent) && pass; + return ol.interaction.Pointer.handleEvent.call(this, mapBrowserEvent) && + this.handleEvent_(mapBrowserEvent); };