Hi! the way OpenLayers handles click events is more complicated than I was expecting.
So I ask someone to comment this code: (based on http://openlayers.org/dev/examples/click.html ) (and how it relates to class OpenLayers.Event? ) MyClick = 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 ); }, trigger: function(e) { var lonlat = map.getLonLatFromViewPortPx(e.xy); alert("You clicked near " + lonlat.lat + " N, " + + lonlat.lon + " E"); } }); var map; function init(){ map = new OpenLayers.Map('map'); var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'} ); map.addLayers([ol_wms]); map.zoomToMaxExtent(); var click = new MyClick(); map.addControl(click); click.activate(); }
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Users mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/openlayers-users
