Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to zoom into a location on a single click. How can I zoom towards the point on single click? I have tried using OpenLayers.Control.ZoomIn and adding a click handler, but for some reason its not registering the "click".

Here is a rundown of my code:

map = ...; // map initialization 
... // added layers

// list of tools for map/feature manipulation
tools = 
  // ... tools
  // Tool In question :
  zoomIn : new OpenLayers.Control.ZoomIn({
                // zoom_in needs a click handler, otherwise, its just button on the map
                handler : new OpenLayers.Handler.Click(
                    this, // control
                    {'click' : this.trigger}, // callbacks
                    {'single' : true, 'double' : false, 'pixelTolerance' : 0} // options
                // overriding ZoomIn.trigger so I can call console.log and alert
                trigger : function(e) {
                    alert("Zoom in, please!");
          }) // end zoomIn
} // end tools

for(key in tools) {

// I only made zoomIn active for testing...

So, the alert doesn't happen and neither does the console.log(e)... How come the callback function is not getting called when I click?


P.S. Sorry if its something silly, I'm brand new to js...

share|improve this question
up vote 5 down vote accepted

You shouldn't need to use the ZoomIn control. Have a look at the examples to see how to implement a custom handler.

share|improve this answer

To complete geographika's answer, this example could also help you handling click event :

share|improve this answer
+1 That example is simpler – geographika Jul 27 '11 at 12:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.