ThinkGeo.com    |     Documentation    |     Premium Support

How to override the behavior of Globe button click on server/client?

Hi Thinkgeo,


On globe button click of the Zoom bar I want to override the behavior to zoom to features of a dynamic layer.


Is it possible to do from the server code when there is no such event defined for it?


How to do that using the Javascript function handler?


Regards,


Anil



 


Hi, Anil
 
Currently, we don’t provide server-side event support for the world icon. But you can easily get what you want on the client-side using the Javascript event handler for the globe button. If you are using the PanZoomBar control by default, please add the codes below to your ASP.NET page.
    <script type="text/javascript">
        var OnMapCreating = function (map) {
            OpenLayers.Control.PanZoomBar.prototype.buttonDown = function (evt) {
                if (!OpenLayers.Event.isLeftClick(evt)) {
                    return;
                }
 
                switch (this.action) {
                    case "panup":
                        this.map.pan(0, -this.getSlideFactor("h"));
                        break;
                    case "pandown":
                        this.map.pan(0, this.getSlideFactor("h"));
                        break;
                    case "panleft":
                        this.map.pan(-this.getSlideFactor("w"), 0);
                        break;
                    case "panright":
                        this.map.pan(this.getSlideFactor("w"), 0);
                        break;
                    case "zoomin":
                        this.map.zoomIn();
                        break;
                    case "zoomout":
                        this.map.zoomOut();
                        break;
                    case "zoomworld":
                        // Here, you can customize the behavior depent on your requirements. By default, it zooms to the max extent.
                        this.map.zoomToMaxExtent();
                        break;
                }
 
                OpenLayers.Event.stop(evt);
            }
        }
    </script>
 
Here is some information about the client-side API for OpenLayers, and I guess it may help you.
dev.openlayers.org/releases/OpenLayers-2.10/doc/devdocs/files/OpenLayers/Map-js.html
For example, if you just want to zoom to a specific extent and you can call like the code below:
this.map.zoomToExtent(new OpenLayers.Bounds(-125, -46, 50, 72));
 
Please let us know if you have any problems about it.
 
Thanks,
 
Khalil