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

OpenLayers Zoom Pan Control has a Zoom World Icon. When it is clicked the map zooms all the way out. Is it possible to override this behavior and define a center and zoom level to which the map should be reset? If yes how?

PS: My Base Map is Bing Map

Thanks Shaunak

share|improve this question
up vote 3 down vote accepted

In order to do this without modifying the actual source code for openlayers (which you won't be doing if you're using a minified version, which by default you probably are), look at this answer.

However, I had to change it slightly for my code, which is using OpenLayers 2.11

OpenLayers.Control.PanZoom.prototype.buttonDown = function(evt) {
            var btn = evt.currentTarget ? evt.currentTarget : this;
            switch (btn.action) {
                case "panup": 
          , -this.getSlideFactor("h"));
                case "pandown": 
          , this.getSlideFactor("h"));
                case "panleft": 
          "w"), 0);
                case "panright": 
          "w"), 0);
                case "zoomin": 
                case "zoomout": 
                case "zoomworld": 
                    alert("Hello world!");

The only difference between this code and the one in the answer linked is that instead of onButtonClick, we're using buttonDown, and rather than evt.buttonElement, we're using evt.currentTarget

EDIT: Internet Explorer has no currentTarget property in their event handling. Luckily, we can use this instead. I have modified the code above accordingly. For an explanation of this, please see this article. A relevant stackoverflow question is here.

share|improve this answer

yes u can override this behavior with changing orginal code of openlayers... in openlayers folders find ../lib/OpenLayers/Control/PanZoom.js

then u must search "zoomworld" case in .js and then u cand change

to OpenLayers.LonLat(x,y), zoomLevel)

May it be easy!

share|improve this answer

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.