Stop current kinetic animation on DOWN events
This commit is contained in:
@@ -80,6 +80,13 @@ ol.interaction.Drag.prototype.handleDragEnd = goog.nullFunction;
|
|||||||
ol.interaction.Drag.prototype.handleDragStart = goog.functions.FALSE;
|
ol.interaction.Drag.prototype.handleDragStart = goog.functions.FALSE;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.MapBrowserEvent} mapBrowserEvent Event.
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
ol.interaction.Drag.prototype.handleDown = goog.nullFunction;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
@@ -91,6 +98,10 @@ ol.interaction.Drag.prototype.handleMapBrowserEvent =
|
|||||||
}
|
}
|
||||||
var view = map.getView();
|
var view = map.getView();
|
||||||
var browserEvent = mapBrowserEvent.browserEvent;
|
var browserEvent = mapBrowserEvent.browserEvent;
|
||||||
|
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DOWN) {
|
||||||
|
goog.asserts.assert(browserEvent instanceof goog.events.BrowserEvent);
|
||||||
|
this.handleDown(mapBrowserEvent);
|
||||||
|
}
|
||||||
if (this.dragging_) {
|
if (this.dragging_) {
|
||||||
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DRAG) {
|
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DRAG) {
|
||||||
goog.asserts.assert(browserEvent instanceof goog.events.BrowserEvent);
|
goog.asserts.assert(browserEvent instanceof goog.events.BrowserEvent);
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ ol.interaction.DragPan = function(condition, opt_kinetic) {
|
|||||||
*/
|
*/
|
||||||
this.kinetic_ = opt_kinetic;
|
this.kinetic_ = opt_kinetic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {?ol.PreRenderFunction}
|
||||||
|
*/
|
||||||
|
this.kineticPreRenderFn_ = null;
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.interaction.DragPan, ol.interaction.Drag);
|
goog.inherits(ol.interaction.DragPan, ol.interaction.Drag);
|
||||||
|
|
||||||
@@ -77,12 +83,12 @@ ol.interaction.DragPan.prototype.handleDragEnd = function(mapBrowserEvent) {
|
|||||||
var distance = this.kinetic_.getDistance();
|
var distance = this.kinetic_.getDistance();
|
||||||
var angle = this.kinetic_.getAngle();
|
var angle = this.kinetic_.getAngle();
|
||||||
var center = view.getCenter();
|
var center = view.getCenter();
|
||||||
var kineticPanFrom = ol.animation.createPanFrom({
|
this.kineticPreRenderFn_ = ol.animation.createPanFrom({
|
||||||
source: center,
|
source: center,
|
||||||
duration: this.kinetic_.getDuration(),
|
duration: this.kinetic_.getDuration(),
|
||||||
easing: this.kinetic_.getEasingFn()
|
easing: this.kinetic_.getEasingFn()
|
||||||
});
|
});
|
||||||
map.addPreRenderFunction(kineticPanFrom);
|
map.addPreRenderFunction(this.kineticPreRenderFn_);
|
||||||
|
|
||||||
var centerpx = map.getPixelFromCoordinate(center);
|
var centerpx = map.getPixelFromCoordinate(center);
|
||||||
var destpx = new ol.Pixel(
|
var destpx = new ol.Pixel(
|
||||||
@@ -111,3 +117,21 @@ ol.interaction.DragPan.prototype.handleDragStart = function(mapBrowserEvent) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.interaction.DragPan.prototype.handleDown = function(mapBrowserEvent) {
|
||||||
|
var map = mapBrowserEvent.map;
|
||||||
|
// FIXME works for View2D only
|
||||||
|
var view = map.getView();
|
||||||
|
goog.asserts.assert(view instanceof ol.View2D);
|
||||||
|
goog.asserts.assert(!goog.isNull(mapBrowserEvent.frameState));
|
||||||
|
if (!goog.isNull(this.kineticPreRenderFn_) &&
|
||||||
|
map.removePreRenderFunction(this.kineticPreRenderFn_)) {
|
||||||
|
map.requestRenderFrame();
|
||||||
|
view.setCenter(mapBrowserEvent.frameState.view2DState.center);
|
||||||
|
this.kineticPreRenderFn_ = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user