Skip to content

Instantly share code, notes, and snippets.

@cspanring
Created July 19, 2011 02:43
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cspanring/1091204 to your computer and use it in GitHub Desktop.
Save cspanring/1091204 to your computer and use it in GitHub Desktop.
custom openlayers click handler compatible with touch events
// Create click handler
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': false,
'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, {
'click': this.trigger
}, this.handlerOptions
);
}
});
// Create click control
var clickControl = new OpenLayers.Control.Click( {
trigger: function(e) {
/* do your thing */
}
});
map.addControl(clickControl);
clickControl.activate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment