1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the clear BSD license.
2 * See http://svn.openlayers.org/trunk/openlayers/license.txt
3 * for the full text of the license. */
6 * @requires OpenLayers/Handler.js
10 * Class: OpenLayers.Handler.Hover
11 * The hover handler is to be used to emulate mouseovers on objects
12 * on the map that aren't DOM elements. For example one can use
13 * this handler to send WMS/GetFeatureInfo requests as the user
14 * moves the mouve over the map.
17 * - <OpenLayers.Handler>
19 OpenLayers.Handler.Hover = OpenLayers.Class(OpenLayers.Handler, {
23 * {Integer} - Number of milliseconds between mousemoves before
24 * the event is considered a hover. Default is 500.
29 * APIProperty: pixelTolerance
30 * {Integer} - Maximum number of pixels between mousemoves for
31 * an event to be considered a hover. Default is null.
36 * APIProperty: stopMove
37 * {Boolean} - Stop other listeners from being notified on mousemoves.
44 * {<OpenLayers.Pixel>} - The location of the last mousemove, expressed
51 * {Number} - The id of the timer.
56 * Constructor: OpenLayers.Handler.Hover
57 * Construct a hover handler.
60 * control - {<OpenLayers.Control>} The control that initialized this
61 * handler. The control is assumed to have a valid map property; that
62 * map is used in the handler's own setMap method.
63 * callbacks - {Object} An object with keys corresponding to callbacks
64 * that will be called by the handler. The callbacks should
65 * expect to receive a single argument, the event. Callbacks for
66 * 'move', the mouse is moving, and 'pause', the mouse is pausing,
68 * options - {Object} An optional object whose properties will be set on
71 initialize: function(control, callbacks, options) {
72 OpenLayers.Handler.prototype.initialize.apply(this, arguments);
77 * Called when the mouse moves on the map.
80 * evt - {<OpenLayers.Event>}
83 * {Boolean} Continue propagating this event.
85 mousemove: function(evt) {
86 if(this.passesTolerance(evt.xy)) {
88 this.callback('move', [evt]);
90 // clone the evt so original properties can be accessed even
91 // if the browser deletes them during the delay
92 evt = OpenLayers.Util.extend({}, evt);
93 this.timerId = window.setTimeout(
94 OpenLayers.Function.bind(this.delayedCall, this, evt),
98 return !this.stopMove;
103 * Called when the mouse goes out of the map.
106 * evt - {<OpenLayers.Event>}
109 * {Boolean} Continue propagating this event.
111 mouseout: function(evt) {
112 if (OpenLayers.Util.mouseLeft(evt, this.map.div)) {
114 this.callback('move', [evt]);
120 * Method: passesTolerance
121 * Determine whether the mouse move is within the optional pixel tolerance.
124 * px - {<OpenLayers.Pixel>}
127 * {Boolean} The mouse move is within the pixel tolerance.
129 passesTolerance: function(px) {
131 if(this.pixelTolerance && this.px) {
133 Math.pow(this.px.x - px.x, 2) +
134 Math.pow(this.px.y - px.y, 2)
136 if(dpx < this.pixelTolerance) {
145 * Clear the timer and set <timerId> to null.
147 clearTimer: function() {
148 if(this.timerId != null) {
149 window.clearTimeout(this.timerId);
155 * Method: delayedCall
156 * Triggers pause callback.
159 * evt - {<OpenLayers.Event>}
161 delayedCall: function(evt) {
162 this.callback('pause', [evt]);
166 * APIMethod: deactivate
167 * Deactivate the handler.
170 * {Boolean} The handler was successfully deactivated.
172 deactivate: function() {
173 var deactivated = false;
174 if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
181 CLASS_NAME: "OpenLayers.Handler.Hover"