Rohan, Take a look at : http://www.quirksmode.org/js/events_order.html
And http://dev.openlayers.org/docs/files/OpenLayers/Events-js.html#OpenLayers.Event.stop This section from PanZoomBar.js looks like it is stopping propagation, which should stop it from bubbling over to your event. 284 divClick: function (evt) { 285 if (!OpenLayers.Event.isLeftClick(evt)) { 286 return; 287 } 288 var y = evt.xy.y; 289 var top = OpenLayers.Util.pagePosition(evt.object)[1]; 290 var levels = (y - top)/this.zoomStopHeight; 291 if(this.forceFixedZoomLevel || !this.map.fractionalZoom) { 292 levels = Math.floor(levels); 293 } 294 var zoom = (this.map.getNumZoomLevels() - 1) - levels; 295 zoom = Math.min(Math.max(zoom, 0), this.map.getNumZoomLevels() - 1); 296 this.map.zoomTo(zoom); 297 OpenLayers.Event.stop(evt); 298 }, ---- Jay Douillard ----- Original Message ----- From: "Rohan Parkes" <[email protected]> To: "Pierre Giraud" <[email protected]> Cc: [email protected] Sent: Sunday, August 8, 2010 4:13:16 PM GMT -08:00 US/Canada Pacific Subject: Re: [OpenLayers-Users] How to prevent PanZoomBar clicks from propagating to Click control Thanks for your reply. I didn’t post the code, because it's trivial, and straight out of one of the online demos. But here it is: OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { defaultHandlerOptions: { 'single': true, 'double': true, 'pixelTolerance': 0, 'stopSingle': true, '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: processMapClick }); processMapClick() just has a call to setCenter(), so the map re-centres to wherever the user clicks. The problem is that if the user clicks on the zoom bar, the map, as well as zooming, also pans. So presumably the click event is going through to the map as well. This doesn’t happen if they click on the end icons of the zoom bar, so presumably there is some way of preventing them from going through to other elements. I tried adding a handler to the PanZoomBar to try to filter the clicks, but my attempt was probably very naïve. Rohan Parkes Developer PelicanCorp 79 Rokeby Street, Collingwood 3066, VIC, AU (m) +61 (0)407 094 251 (p) +613 8413 5212 (f) +613 8413 5299 www.pelicancorp.com The information contained in this email communication may be confidential. You should only read, disclose, re-transmit, copy, distribute, act in reliance on or commercialise the information if you are authorised to do so. If you are not the intended recipient of this email communication, please notify us immediately by email at [email protected] or reply by email directly to the sender and then destroy any electronic or paper copy of this message. -----Original Message----- From: Pierre Giraud [mailto:[email protected]] Sent: Thursday, 5 August 2010 17:15 To: [email protected] Cc: [email protected] Subject: Re: [OpenLayers-Users] How to prevent PanZoomBar clicks from propagating to Click control I'm not sure I fully understand what your custom control is supposed to do. However, you can have a look at the fallThrough config option for the Map object. It may help. If not, please show us some code. Regards, Pierre On Thu, Aug 5, 2010 at 7:39 AM, Rohan Parkes <[email protected]> wrote: > My map has a click control that allows users to re-centre the map by > clicking on it. > > However, there is one drawback – it responds to clicks on the PanZoomBar > control, creating a strange blend of panning and zooming when the user > zooms. > > It doesn’t respond to the Zoom In or Zoom Out icons – just the bar element. > > Presumably I have to find a way to prevent clicks on the Zoom bar from > propagating to the map. > > If the user clicks on the map at least once, it works correctly, and the map > does not pan when the user zooms. But if they start by clicking on the zoom > bar, they get the unwanted behaviour. > > I’ve been messing around with the Handler.Click class, but I can’t get > anything to work. > > The code for the OpenLayers.Control.Click control is from the OL Click Event > example. The trigger member just calls a function that re-centres the map. > > Rohan Parkes > > _______________________________________________ > Users mailing list > [email protected] > http://openlayers.org/mailman/listinfo/users > > -- Pierre GIRAUD Géomaticien, Analyste Camptocamp France SAS Savoie Technolac, BP 352 73377 Le Bourget du Lac, Cedex Tel : 00 33 4 79 44 44 93 Mail : [email protected] http://www.camptocamp.com _______________________________________________ Users mailing list [email protected] http://openlayers.org/mailman/listinfo/users _______________________________________________ Users mailing list [email protected] http://openlayers.org/mailman/listinfo/users
