So I've created a map in openlayers and I am setting it up so that there are only certain zoom levels a user can see. I have the code created to handle forcing a user to the next acceptable zoom level when they attempt to zoom in/out. I have been able to create listener for handling double-clicks (see code below) but for the life of me I cannot figure out how to capture mousewheel events.
The documentation makes it seem like it should be straightforward but I've been banging my head against a wall for more than a day trying to figure this out. All my googling has turned up plenty of results for disabling the mousewheel but nothing for capturing wheel events.
function init() {
map = new OpenLayers.Map('map_canvas',mapSettings);
....
....
);
var click = new OpenLayers.Control.Click();
map.addControl(click);
click.activate();
}
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': false,
'double': true,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this, {
'dblclick': this.trigger
}, this.handlerOptions
);
},
trigger: function(e) {
var lonlat = map.getLonLatFromViewPortPx(e.xy);
curZoom = map.getZoom();
var newZoom = stepZoomIn(map.getZoom());
updateMapZoom(newZoom);
map.setCenter(event.lonlat);
}
});
Best Answer
I was able to accomplish this by defining my own control derived from Navigation control.
This of course will work only as long as Navigation control defines wheelDown - function. If Navigation control is modified in later OpenLayers version then this will brake as well.