base dragrotateandzoominteraction on pointer interaction

This commit is contained in:
tsauerwein
2014-02-26 15:24:17 +01:00
parent c593add6d8
commit 56dcdd02ec
2 changed files with 47 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ goog.require('ol.events.ConditionType');
goog.require('ol.events.condition'); goog.require('ol.events.condition');
goog.require('ol.interaction.Drag'); goog.require('ol.interaction.Drag');
goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.Interaction');
goog.require('ol.interaction.PointerInteraction');
/** /**
@@ -25,7 +26,7 @@ ol.interaction.DRAGROTATEANDZOOM_ANIMATION_DURATION = 400;
* *
* This interaction is not included in the default interactions. * This interaction is not included in the default interactions.
* @constructor * @constructor
* @extends {ol.interaction.Drag} * @extends {ol.interaction.PointerInteraction}
* @param {olx.interaction.DragRotateAndZoomOptions=} opt_options Options. * @param {olx.interaction.DragRotateAndZoomOptions=} opt_options Options.
* @todo stability experimental * @todo stability experimental
*/ */
@@ -61,14 +62,19 @@ ol.interaction.DragRotateAndZoom = function(opt_options) {
this.lastScaleDelta_ = 0; this.lastScaleDelta_ = 0;
}; };
goog.inherits(ol.interaction.DragRotateAndZoom, ol.interaction.Drag); goog.inherits(ol.interaction.DragRotateAndZoom,
ol.interaction.PointerInteraction);
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.interaction.DragRotateAndZoom.prototype.handleDrag = ol.interaction.DragRotateAndZoom.prototype.handlePointerDrag =
function(mapBrowserEvent) { function(mapBrowserEvent) {
if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
return;
}
var map = mapBrowserEvent.map; var map = mapBrowserEvent.map;
var size = map.getSize(); var size = map.getSize();
var offset = mapBrowserEvent.pixel; var offset = mapBrowserEvent.pixel;
@@ -101,8 +107,12 @@ ol.interaction.DragRotateAndZoom.prototype.handleDrag =
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.interaction.DragRotateAndZoom.prototype.handleDragEnd = ol.interaction.DragRotateAndZoom.prototype.handlePointerUp =
function(mapBrowserEvent) { function(mapBrowserEvent) {
if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
return false;
}
var map = mapBrowserEvent.map; var map = mapBrowserEvent.map;
// FIXME works for View2D only // FIXME works for View2D only
var view = map.getView(); var view = map.getView();
@@ -122,8 +132,12 @@ ol.interaction.DragRotateAndZoom.prototype.handleDragEnd =
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.interaction.DragRotateAndZoom.prototype.handleDragStart = ol.interaction.DragRotateAndZoom.prototype.handlePointerDown =
function(mapBrowserEvent) { function(mapBrowserEvent) {
if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
return false;
}
if (this.condition_(mapBrowserEvent)) { if (this.condition_(mapBrowserEvent)) {
mapBrowserEvent.map.getView().setHint(ol.ViewHint.INTERACTING, 1); mapBrowserEvent.map.getView().setHint(ol.ViewHint.INTERACTING, 1);
this.lastAngle_ = undefined; this.lastAngle_ = undefined;
@@ -133,3 +147,15 @@ ol.interaction.DragRotateAndZoom.prototype.handleDragStart =
return false; return false;
} }
}; };
/**
* @inheritDoc
*/
ol.interaction.DragRotateAndZoom.prototype.shouldStopEvent =
function(hasHandledEvent) {
/* Stop the event if it was handled, so that interaction `DragZoom`
* does not interfere.
*/
return hasHandledEvent;
};

View File

@@ -136,6 +136,7 @@ ol.interaction.PointerInteraction.prototype.handleMapBrowserEvent =
var mapBrowserPointerEvent = var mapBrowserPointerEvent =
/** @type {ol.MapBrowserPointerEvent} */ (mapBrowserEvent); /** @type {ol.MapBrowserPointerEvent} */ (mapBrowserEvent);
var stopEvent = false;
var view = mapBrowserEvent.map.getView(); var view = mapBrowserEvent.map.getView();
this.updateTrackedPointers_(mapBrowserPointerEvent); this.updateTrackedPointers_(mapBrowserPointerEvent);
if (this.handled_) { if (this.handled_) {
@@ -156,6 +157,20 @@ ol.interaction.PointerInteraction.prototype.handleMapBrowserEvent =
view.setHint(ol.ViewHint.INTERACTING, 1); view.setHint(ol.ViewHint.INTERACTING, 1);
} }
this.handled_ = handled; this.handled_ = handled;
stopEvent = this.shouldStopEvent(handled);
} }
return true; return !stopEvent;
}; };
/**
* This method allows inheriting classes to stop the event from being
* passed to further interactions. For example, this is required for
* interaction `DragRotateAndZoom`.
*
* @protected
* @param {boolean} handled Was the event handled by the interaction?
* @return {boolean} Should the event be stopped?
*/
ol.interaction.PointerInteraction.prototype.shouldStopEvent =
goog.functions.FALSE;