Map browser event handling for touch devices

By handling click, dblckick and drag sequences in MapBrowserEvent, we can overcome closure issues with touch events. In particular, these issues were double drag events (from mousemove and touchmove) and a missing dblclick event on touch devices.
This commit is contained in:
ahocevar
2012-09-25 17:27:17 +02:00
parent b151304630
commit ce977e5364
4 changed files with 266 additions and 46 deletions

View File

@@ -1,7 +1,7 @@
goog.provide('ol.interaction.DblClickZoom');
goog.require('goog.events.EventType');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEvent.EventType');
goog.require('ol.interaction.Constraints');
goog.require('ol.interaction.Interaction');
@@ -24,8 +24,8 @@ goog.inherits(ol.interaction.DblClickZoom, ol.interaction.Interaction);
ol.interaction.DblClickZoom.prototype.handleMapBrowserEvent =
function(mapBrowserEvent) {
var browserEvent = mapBrowserEvent.browserEvent;
if (browserEvent.type == goog.events.EventType.DBLCLICK &&
browserEvent.isMouseActionButton()) {
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DBLCLICK &&
mapBrowserEvent.isMouseActionButton()) {
var map = mapBrowserEvent.map;
var resolution = map.getResolution();
var delta = mapBrowserEvent.browserEvent.shiftKey ? -1 : 1;

View File

@@ -93,19 +93,19 @@ ol.interaction.Drag.prototype.handleMapBrowserEvent =
}
var browserEvent = mapBrowserEvent.browserEvent;
if (this.dragging_) {
if (mapBrowserEvent.type == goog.fx.Dragger.EventType.DRAG) {
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DRAG) {
goog.asserts.assert(browserEvent instanceof goog.events.BrowserEvent);
this.deltaX = browserEvent.clientX - this.startX;
this.deltaY = browserEvent.clientY - this.startY;
this.handleDrag(mapBrowserEvent);
} else if (mapBrowserEvent.type == goog.fx.Dragger.EventType.END) {
} else if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DRAGEND) {
goog.asserts.assert(browserEvent instanceof goog.events.BrowserEvent);
this.deltaX = browserEvent.clientX - this.startX;
this.deltaY = browserEvent.clientY - this.startY;
this.handleDragEnd(mapBrowserEvent);
this.dragging_ = false;
}
} else if (mapBrowserEvent.type == goog.fx.Dragger.EventType.START) {
} else if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DRAGSTART) {
goog.asserts.assert(browserEvent instanceof goog.events.BrowserEvent);
this.startX = browserEvent.clientX;
this.startY = browserEvent.clientY;