Use offsetX and offsetY if available
This commit is contained in:
+16
-7
@@ -592,18 +592,25 @@ ol.Map.prototype.getEventCoordinate = function(event) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the map pixel position for a browser event.
|
* Returns the map pixel position for a browser event relative to the viewport.
|
||||||
* @param {Event} event Event.
|
* @param {Event} event Event.
|
||||||
* @return {ol.Pixel} Pixel.
|
* @return {ol.Pixel} Pixel.
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.getEventPixel = function(event) {
|
ol.Map.prototype.getEventPixel = function(event) {
|
||||||
// goog.style.getRelativePosition is based on event.targetTouches,
|
// Use the offsetX and offsetY values if available.
|
||||||
// but touchend and touchcancel events have no targetTouches when
|
// See http://www.w3.org/TR/cssom-view/#dom-mouseevent-offsetx and
|
||||||
// the last finger is removed from the screen.
|
// http://www.w3.org/TR/cssom-view/#dom-mouseevent-offsety
|
||||||
// So we ourselves compute the position of touch events.
|
if (goog.isDef(event.offsetX) && goog.isDef(event.offsetY)) {
|
||||||
// See https://github.com/google/closure-library/pull/323
|
return [event.offsetX, event.offsetY];
|
||||||
if (goog.isDef(event.changedTouches)) {
|
} else if (goog.isDef(event.changedTouches)) {
|
||||||
|
// offsetX and offsetY are not defined for Touch Event
|
||||||
|
//
|
||||||
|
// goog.style.getRelativePosition is based on event.targetTouches,
|
||||||
|
// but touchend and touchcancel events have no targetTouches when
|
||||||
|
// the last finger is removed from the screen.
|
||||||
|
// So we ourselves compute the position of touch events.
|
||||||
|
// See https://github.com/google/closure-library/pull/323
|
||||||
var touch = event.changedTouches[0];
|
var touch = event.changedTouches[0];
|
||||||
var viewportPosition = goog.style.getClientPosition(this.viewport_);
|
var viewportPosition = goog.style.getClientPosition(this.viewport_);
|
||||||
return [
|
return [
|
||||||
@@ -611,6 +618,8 @@ ol.Map.prototype.getEventPixel = function(event) {
|
|||||||
touch.clientY - viewportPosition.y
|
touch.clientY - viewportPosition.y
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
|
// Compute offsetX and offsetY values for browsers that don't implement
|
||||||
|
// cssom-view specification
|
||||||
var eventPosition = goog.style.getRelativePosition(event, this.viewport_);
|
var eventPosition = goog.style.getRelativePosition(event, this.viewport_);
|
||||||
return [eventPosition.x, eventPosition.y];
|
return [eventPosition.x, eventPosition.y];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user