Skip to content

Commit

Permalink
Make touch emulate hover for GeoMoose popups on touch.
Browse files Browse the repository at this point in the history
  • Loading branch information
klassenjs committed Sep 22, 2017
1 parent f4a4090 commit 3cb2e53
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions lib/OpenLayers/Handler/Hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ OpenLayers.Handler.Hover = OpenLayers.Class(OpenLayers.Handler, {
* {Number} - The id of the timer.
*/
timerId: null,

/**
* Property: down
* {Object} Object that store relevant information about the last
* mousedown or touchstart. Its 'xy' OpenLayers.Pixel property gives
* the average location of the mouse/touch event. Its 'touches'
* property records clientX/clientY of each touches.
*/
down: null,

/**
* Property: last
* {Object} Object that store relevant information about the last
* mousemove or touchmove. Its 'xy' OpenLayers.Pixel property gives
* the average location of the mouse/touch event. Its 'touches'
* property records clientX/clientY of each touches.
*/
last: null,

/**
* Constructor: OpenLayers.Handler.Hover
Expand All @@ -70,6 +88,52 @@ OpenLayers.Handler.Hover = OpenLayers.Class(OpenLayers.Handler, {
* the handler.
*/


/**
* Method: touchstart
* Handle touchstart.
*
* Returns:
* {Boolean} Continue propagating this event.
*/
touchstart: function(evt) {
this.startTouch();
this.down = {xy: evt.xy};
this.last = {xy: evt.xy};
return true;
},

/**
* Method: touchmove
* Store position of last move, because touchend event can have
* an empty "touches" property.
*
* Returns:
* {Boolean} Continue propagating this event.
*/
touchmove: function(evt) {
this.last = {xy: evt.xy};
return true;
},

/**
* Method: touchend
* Correctly set event xy property, and add lastTouches to have
* touches property from last touchstart or touchmove
*
* Returns:
* {Boolean} Continue propagating this event.
*/
touchend: function(evt) {
// touchstart may not have been allowed to propagate
if (this.down) {
evt.xy = this.last.xy;
this.delayedCall(evt);
this.down = null;
}
return true;
},

/**
* Method: mousemove
* Called when the mouse moves on the map.
Expand Down

0 comments on commit 3cb2e53

Please sign in to comment.