4

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 run-down 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!");
                    console.log(e);
                    this.map.zoomIn();
                }
          }) // end zoomIn
} // end tools

for(key in tools) {
   map.addControl(tools[key]);
}

// I only made zoomIn active for testing...
tools.zoomIn.activate();

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?

0

2 Answers 2

5

You shouldn't need to use the ZoomIn control. Have a look at the http://openlayers.org/dev/examples/click-handler.html examples to see how to implement a custom handler.

3

To complete geographika's answer, this example could also help you handling click event : http://openlayers.org/dev/examples/click.html

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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