Merge pull request #925 from fredj/ms_pointer_events
MSPointer events fixes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
goog.provide('ol.interaction.Touch');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.functions');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
@@ -57,24 +58,43 @@ ol.interaction.Touch.centroid = function(touches) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.MapBrowserEvent} mapBrowserEvent Event.
|
||||
* @return {boolean} Whether the event is a touchstart, touchmove
|
||||
* or touchend event.
|
||||
* @private
|
||||
*/
|
||||
ol.interaction.Touch.isTouchEvent_ = function(mapBrowserEvent) {
|
||||
var type = mapBrowserEvent.type;
|
||||
return (
|
||||
type === ol.MapBrowserEvent.EventType.TOUCHSTART ||
|
||||
type === ol.MapBrowserEvent.EventType.TOUCHMOVE ||
|
||||
type === ol.MapBrowserEvent.EventType.TOUCHEND);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.MapBrowserEvent} mapBrowserEvent Event.
|
||||
* @private
|
||||
*/
|
||||
ol.interaction.Touch.prototype.updateTrackedTouches_ =
|
||||
function(mapBrowserEvent) {
|
||||
var event = mapBrowserEvent.browserEvent.getBrowserEvent();
|
||||
if (goog.isDef(event.targetTouches)) {
|
||||
// W3C touch events
|
||||
this.targetTouches = event.targetTouches;
|
||||
} else {
|
||||
// IE pointer event
|
||||
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.TOUCHEND) {
|
||||
delete this.trackedTouches_[event.pointerId];
|
||||
if (ol.interaction.Touch.isTouchEvent_(mapBrowserEvent)) {
|
||||
var event = mapBrowserEvent.browserEvent.getBrowserEvent();
|
||||
if (goog.isDef(event.targetTouches)) {
|
||||
// W3C touch events
|
||||
this.targetTouches = event.targetTouches;
|
||||
} else if (goog.isDef(event.pointerId)) {
|
||||
// IE pointer event
|
||||
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.TOUCHEND) {
|
||||
delete this.trackedTouches_[event.pointerId];
|
||||
} else {
|
||||
this.trackedTouches_[event.pointerId] = event;
|
||||
}
|
||||
this.targetTouches = goog.object.getValues(this.trackedTouches_);
|
||||
} else {
|
||||
this.trackedTouches_[event.pointerId] = event;
|
||||
goog.asserts.fail('unknown touch event model');
|
||||
}
|
||||
this.targetTouches = goog.object.getValues(this.trackedTouches_);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -185,11 +185,11 @@ ol.MapBrowserEventHandler = function(map) {
|
||||
goog.events.EventType.TOUCHSTART,
|
||||
goog.events.EventType.MSPOINTERDOWN
|
||||
], this.handleTouchStart_, false, this),
|
||||
goog.events.listen(element, [
|
||||
goog.events.listen(goog.global.document, [
|
||||
goog.events.EventType.TOUCHMOVE,
|
||||
goog.events.EventType.MSPOINTERMOVE
|
||||
], this.handleTouchMove_, false, this),
|
||||
goog.events.listen(element, [
|
||||
goog.events.listen(goog.global.document, [
|
||||
goog.events.EventType.TOUCHEND,
|
||||
goog.events.EventType.MSPOINTERUP
|
||||
], this.handleTouchEnd_, false, this)
|
||||
@@ -312,10 +312,16 @@ ol.MapBrowserEventHandler.prototype.handleTouchStart_ = function(browserEvent) {
|
||||
* @private
|
||||
*/
|
||||
ol.MapBrowserEventHandler.prototype.handleTouchMove_ = function(browserEvent) {
|
||||
this.dragged_ = true;
|
||||
var newEvent = new ol.MapBrowserEvent(
|
||||
ol.MapBrowserEvent.EventType.TOUCHMOVE, this.map_, browserEvent);
|
||||
this.dispatchEvent(newEvent);
|
||||
if (this.down_) {
|
||||
// 'touchmove' events are dispatched only when this.down_ is set
|
||||
// (set after a touch start) to prevent unwanted events when the
|
||||
// mouse hover the page. This only happens with the IE pointer
|
||||
// event system.
|
||||
this.dragged_ = true;
|
||||
var newEvent = new ol.MapBrowserEvent(
|
||||
ol.MapBrowserEvent.EventType.TOUCHMOVE, this.map_, browserEvent);
|
||||
this.dispatchEvent(newEvent);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user