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.provide('ol.interaction.Touch');
|
||||||
|
|
||||||
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.functions');
|
goog.require('goog.functions');
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('ol.MapBrowserEvent');
|
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.
|
* @param {ol.MapBrowserEvent} mapBrowserEvent Event.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.interaction.Touch.prototype.updateTrackedTouches_ =
|
ol.interaction.Touch.prototype.updateTrackedTouches_ =
|
||||||
function(mapBrowserEvent) {
|
function(mapBrowserEvent) {
|
||||||
var event = mapBrowserEvent.browserEvent.getBrowserEvent();
|
if (ol.interaction.Touch.isTouchEvent_(mapBrowserEvent)) {
|
||||||
if (goog.isDef(event.targetTouches)) {
|
var event = mapBrowserEvent.browserEvent.getBrowserEvent();
|
||||||
// W3C touch events
|
if (goog.isDef(event.targetTouches)) {
|
||||||
this.targetTouches = event.targetTouches;
|
// W3C touch events
|
||||||
} else {
|
this.targetTouches = event.targetTouches;
|
||||||
// IE pointer event
|
} else if (goog.isDef(event.pointerId)) {
|
||||||
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.TOUCHEND) {
|
// IE pointer event
|
||||||
delete this.trackedTouches_[event.pointerId];
|
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 {
|
} 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.TOUCHSTART,
|
||||||
goog.events.EventType.MSPOINTERDOWN
|
goog.events.EventType.MSPOINTERDOWN
|
||||||
], this.handleTouchStart_, false, this),
|
], this.handleTouchStart_, false, this),
|
||||||
goog.events.listen(element, [
|
goog.events.listen(goog.global.document, [
|
||||||
goog.events.EventType.TOUCHMOVE,
|
goog.events.EventType.TOUCHMOVE,
|
||||||
goog.events.EventType.MSPOINTERMOVE
|
goog.events.EventType.MSPOINTERMOVE
|
||||||
], this.handleTouchMove_, false, this),
|
], this.handleTouchMove_, false, this),
|
||||||
goog.events.listen(element, [
|
goog.events.listen(goog.global.document, [
|
||||||
goog.events.EventType.TOUCHEND,
|
goog.events.EventType.TOUCHEND,
|
||||||
goog.events.EventType.MSPOINTERUP
|
goog.events.EventType.MSPOINTERUP
|
||||||
], this.handleTouchEnd_, false, this)
|
], this.handleTouchEnd_, false, this)
|
||||||
@@ -312,10 +312,16 @@ ol.MapBrowserEventHandler.prototype.handleTouchStart_ = function(browserEvent) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.MapBrowserEventHandler.prototype.handleTouchMove_ = function(browserEvent) {
|
ol.MapBrowserEventHandler.prototype.handleTouchMove_ = function(browserEvent) {
|
||||||
this.dragged_ = true;
|
if (this.down_) {
|
||||||
var newEvent = new ol.MapBrowserEvent(
|
// 'touchmove' events are dispatched only when this.down_ is set
|
||||||
ol.MapBrowserEvent.EventType.TOUCHMOVE, this.map_, browserEvent);
|
// (set after a touch start) to prevent unwanted events when the
|
||||||
this.dispatchEvent(newEvent);
|
// 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