/* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for * full list of contributors). Published under the Clear BSD license. * See http://svn.openlayers.org/trunk/openlayers/license.txt for the * full text of the license. */ /** * @requires OpenLayers/Handler.js */ /** * Class: OpenLayers.Handler.MouseWheel * Handler for wheel up/down events. * * Inherits from: * - */ OpenLayers.Handler.MouseWheel = OpenLayers.Class(OpenLayers.Handler, { /** * Property: wheelListener * {function} */ wheelListener: null, /** * Property: mousePosition * {} mousePosition is necessary because * evt.clientX/Y is buggy in Moz on wheel events, so we cache and use the * value from the last mousemove. */ mousePosition: null, /** * Property: interval * {Integer} In order to increase server performance, an interval (in * milliseconds) can be set to reduce the number of up/down events * called. If set, a new up/down event will not be set until the * interval has passed. * Defaults to 0, meaning no interval. */ interval: 0, /** * Property: delta * {Integer} When interval is set, delta collects the mousewheel z-deltas * of the events that occur within the interval. * See also the cumulative option */ delta: 0, /** * Property: cumulative * {Boolean} When interval is set: true to collect all the mousewheel * z-deltas, false to only record the delta direction (positive or * negative) */ cumulative: true, /** * Constructor: OpenLayers.Handler.MouseWheel * * Parameters: * control - {} * callbacks - {Object} An object containing a single function to be * called when the drag operation is finished. * The callback should expect to recieve a single * argument, the point geometry. * options - {Object} */ initialize: function(control, callbacks, options) { OpenLayers.Handler.prototype.initialize.apply(this, arguments); this.wheelListener = OpenLayers.Function.bindAsEventListener( this.onWheelEvent, this ); }, /** * Method: destroy */ destroy: function() { OpenLayers.Handler.prototype.destroy.apply(this, arguments); this.wheelListener = null; }, /** * Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/ */ /** * Method: onWheelEvent * Catch the wheel event and handle it xbrowserly * * Parameters: * e - {Event} */ onWheelEvent: function(e){ // make sure we have a map and check keyboard modifiers if (!this.map || !this.checkModifiers(e)) { return; } // Ride up the element's DOM hierarchy to determine if it or any of // its ancestors was: // * specifically marked as scrollable // * one of our layer divs // * the map div // var overScrollableDiv = false; var overLayerDiv = false; var overMapDiv = false; var elem = OpenLayers.Event.element(e); while((elem != null) && !overMapDiv && !overScrollableDiv) { if (!overScrollableDiv) { try { if (elem.currentStyle) { overflow = elem.currentStyle["overflow"]; } else { var style = document.defaultView.getComputedStyle(elem, null); var overflow = style.getPropertyValue("overflow"); } overScrollableDiv = ( overflow && (overflow == "auto") || (overflow == "scroll") ); } catch(err) { //sometimes when scrolling in a popup, this causes // obscure browser error } } if (!overLayerDiv) { for(var i=0, len=this.map.layers.length; i