base dragrotateinteraction on pointer interaction
This commit is contained in:
@@ -5,6 +5,7 @@ goog.require('goog.asserts');
|
||||
goog.require('goog.dom.TagName');
|
||||
goog.require('goog.functions');
|
||||
goog.require('ol.MapBrowserEvent.EventType');
|
||||
goog.require('ol.MapBrowserPointerEvent');
|
||||
|
||||
|
||||
/**
|
||||
@@ -120,3 +121,17 @@ ol.events.condition.targetNotEditable = function(mapBrowserEvent) {
|
||||
tagName !== goog.dom.TagName.SELECT &&
|
||||
tagName !== goog.dom.TagName.TEXTAREA);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
|
||||
* @return {boolean} True if the event originates from a mouse device.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.events.condition.mouseOnly = function(mapBrowserEvent) {
|
||||
goog.asserts.assertInstanceof(mapBrowserEvent, ol.MapBrowserPointerEvent);
|
||||
/* pointerId must be 1 for mouse devices,
|
||||
* see: http://www.w3.org/Submission/pointer-events/#pointerevent-interface
|
||||
*/
|
||||
return mapBrowserEvent.pointerEvent.pointerId == 1;
|
||||
};
|
||||
|
||||
@@ -63,7 +63,8 @@ goog.inherits(ol.DragBoxEvent, goog.events.Event);
|
||||
|
||||
/**
|
||||
* Allows the user to zoom the map by clicking and dragging on the map,
|
||||
* when the shift key is held down.
|
||||
* normally combined with an {@link ol.events.condition} that limits
|
||||
* it to when the shift key is held down.
|
||||
*
|
||||
* This interaction is only supported for mouse devices.
|
||||
*
|
||||
@@ -107,25 +108,11 @@ ol.interaction.DragBox = function(opt_options) {
|
||||
goog.inherits(ol.interaction.DragBox, ol.interaction.PointerInteraction);
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the pointer event is generated by a mouse pointer.
|
||||
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.interaction.DragBox.prototype.isMousePointer =
|
||||
function(mapBrowserEvent) {
|
||||
/* pointerId must be 1 for mouse devices,
|
||||
* see: http://www.w3.org/Submission/pointer-events/#pointerevent-interface
|
||||
*/
|
||||
return mapBrowserEvent.pointerEvent.pointerId == 1;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.interaction.DragBox.prototype.handlePointerDrag = function(mapBrowserEvent) {
|
||||
if (!this.isMousePointer(mapBrowserEvent)) {
|
||||
if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -154,7 +141,7 @@ ol.interaction.DragBox.prototype.onBoxEnd = goog.nullFunction;
|
||||
*/
|
||||
ol.interaction.DragBox.prototype.handlePointerUp =
|
||||
function(mapBrowserEvent) {
|
||||
if (!this.isMousePointer(mapBrowserEvent)) {
|
||||
if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -177,7 +164,7 @@ ol.interaction.DragBox.prototype.handlePointerUp =
|
||||
*/
|
||||
ol.interaction.DragBox.prototype.handlePointerDown =
|
||||
function(mapBrowserEvent) {
|
||||
if (!this.isMousePointer(mapBrowserEvent)) {
|
||||
if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ goog.require('ol.events.ConditionType');
|
||||
goog.require('ol.events.condition');
|
||||
goog.require('ol.interaction.Drag');
|
||||
goog.require('ol.interaction.Interaction');
|
||||
goog.require('ol.interaction.PointerInteraction');
|
||||
|
||||
|
||||
/**
|
||||
@@ -19,8 +20,11 @@ ol.interaction.DRAGROTATE_ANIMATION_DURATION = 250;
|
||||
* Allows the user to rotate the map by clicking and dragging on the map,
|
||||
* normally combined with an {@link ol.events.condition} that limits
|
||||
* it to when the alt and shift keys are held down.
|
||||
*
|
||||
* This interaction is only supported for mouse devices.
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.interaction.Drag}
|
||||
* @extends {ol.interaction.PointerInteraction}
|
||||
* @param {olx.interaction.DragRotateOptions=} opt_options Options.
|
||||
*/
|
||||
ol.interaction.DragRotate = function(opt_options) {
|
||||
@@ -43,13 +47,18 @@ ol.interaction.DragRotate = function(opt_options) {
|
||||
this.lastAngle_ = undefined;
|
||||
|
||||
};
|
||||
goog.inherits(ol.interaction.DragRotate, ol.interaction.Drag);
|
||||
goog.inherits(ol.interaction.DragRotate, ol.interaction.PointerInteraction);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.interaction.DragRotate.prototype.handleDrag = function(mapBrowserEvent) {
|
||||
ol.interaction.DragRotate.prototype.handlePointerDrag =
|
||||
function(mapBrowserEvent) {
|
||||
if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var map = mapBrowserEvent.map;
|
||||
var size = map.getSize();
|
||||
var offset = mapBrowserEvent.pixel;
|
||||
@@ -71,7 +80,12 @@ ol.interaction.DragRotate.prototype.handleDrag = function(mapBrowserEvent) {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.interaction.DragRotate.prototype.handleDragEnd = function(mapBrowserEvent) {
|
||||
ol.interaction.DragRotate.prototype.handlePointerUp =
|
||||
function(mapBrowserEvent) {
|
||||
if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var map = mapBrowserEvent.map;
|
||||
// FIXME works for View2D only
|
||||
var view = map.getView();
|
||||
@@ -86,8 +100,12 @@ ol.interaction.DragRotate.prototype.handleDragEnd = function(mapBrowserEvent) {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.interaction.DragRotate.prototype.handleDragStart =
|
||||
ol.interaction.DragRotate.prototype.handlePointerDown =
|
||||
function(mapBrowserEvent) {
|
||||
if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var browserEvent = mapBrowserEvent.browserEvent;
|
||||
if (browserEvent.isMouseActionButton() && this.condition_(mapBrowserEvent)) {
|
||||
var map = mapBrowserEvent.map;
|
||||
|
||||
Reference in New Issue
Block a user