/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the * full text of the license. *//** * @requires OpenLayers/Control.js *//** * Class: OpenLayers.Control.PanZoom *  * Inherits from: *  - <OpenLayers.Control> */OpenLayers.Control.PanZoom = OpenLayers.Class(OpenLayers.Control, {    /**      * APIProperty: slideFactor     * {Integer} Number of pixels by which we'll pan the map in any direction      *     on clicking the arrow buttons.      */    slideFactor: 50,    /**      * Property: buttons     * {Array(DOMElement)} Array of Button Divs      */    buttons: null,    /**      * Property: position     * {<OpenLayers.Pixel>}      */    position: null,    /**     * Constructor: OpenLayers.Control.PanZoom     *      * Parameters:     * options - {Object}     */    initialize: function(options) {        this.position = new OpenLayers.Pixel(OpenLayers.Control.PanZoom.X, OpenLayers.Control.PanZoom.Y);        OpenLayers.Control.prototype.initialize.apply(this, arguments);    },    /**    * APIMethod: destroy     */    destroy: function() {        OpenLayers.Control.prototype.destroy.apply(this, arguments);        while(this.buttons.length) {            var btn = this.buttons.shift();            btn.map = null;            OpenLayers.Event.stopObservingElement(btn);        }        this.buttons = null;        this.position = null;    },    /**     * Method: draw     *     * Parameters:     * px - {<OpenLayers.Pixel>}      *      * Returns:     * {DOMElement} A reference to the container div for the PanZoom control.     */    draw: function(px) {        // initialize our internal div        OpenLayers.Control.prototype.draw.apply(this, arguments);                this.buttons = [];                        var offset = new OpenLayers.Pixel(20, 20);        //var mapSize = new OpenLayers.Size(map.viewPortDiv.clientWidth, map.viewPortDiv.clientHeight);        var mapSize = this.map.size;        var buttonSize = new OpenLayers.Size(18,18);                //Add the pan buttons        var buttonPosition = new OpenLayers.Pixel(mapSize.w - offset.x - 1.5*buttonSize.w, mapSize.h - offset.y - 3*buttonSize.h);                this._addButton("panup", "north-mini-black.png", buttonPosition, buttonSize);        buttonPosition = new OpenLayers.Pixel(mapSize.w - offset.x - buttonSize.w, mapSize.h - offset.y - 2*buttonSize.h);        this._addButton("panright", "east-mini-black.png", buttonPosition, buttonSize);        buttonPosition = new OpenLayers.Pixel(mapSize.w - offset.x - 1.5*buttonSize.w, mapSize.h - offset.y - buttonSize.h);        this._addButton("pandown", "south-mini-black.png", buttonPosition, buttonSize);        buttonPosition = new OpenLayers.Pixel(mapSize.w - offset.x - 2*buttonSize.w, mapSize.h - offset.y - 2*buttonSize.h);        this._addButton("panleft", "west-mini-black.png", buttonPosition, buttonSize);                return this.div;            },        /**     * Method: _addButton     *      * Parameters:     * id - {String}      * img - {String}      * xy - {<OpenLayers.Pixel>}      * sz - {<OpenLayers.Size>}      *      * Returns:     * {DOMElement} A Div (an alphaImageDiv, to be precise) that contains the     *     image of the button, and has all the proper event handlers set.     */    _addButton:function(id, img, xy, sz) {        var imgLocation = OpenLayers.Util.getImagesLocation() + img;//        var imgLocation = "./img/" + img;        var btn = OpenLayers.Util.createAlphaImageDiv("OpenLayers_Control_PanZoom_" + id, xy, sz, imgLocation, "absolute");        //we want to add the outer div        this.div.appendChild(btn);        OpenLayers.Event.observe(btn, "mousedown", OpenLayers.Function.bindAsEventListener(this.buttonDown, btn));        OpenLayers.Event.observe(btn, "dblclick", OpenLayers.Function.bindAsEventListener(this.doubleClick, btn));        OpenLayers.Event.observe(btn, "click", OpenLayers.Function.bindAsEventListener(this.doubleClick, btn));        btn.action = id;        btn.map = this.map;        btn.slideFactor = this.slideFactor;        //we want to remember/reference the outer div        this.buttons.push(btn);        return btn;    },        /**     * Method: doubleClick     *     * Parameters:     * evt - {Event}      *     * Returns:     * {Boolean}     */    doubleClick: function (evt) {        OpenLayers.Event.stop(evt);        return false;    },        /**     * Method: buttonDown     *     * Parameters:     * evt - {Event}      */    buttonDown: function (evt) {        if (!OpenLayers.Event.isLeftClick(evt)) {            return;        }        switch (this.action) {            case "panup":                 this.map.pan(0, -this.slideFactor);                break;            case "pandown":                 this.map.pan(0, this.slideFactor);                break;            case "panleft":                 this.map.pan(-this.slideFactor, 0);                break;            case "panright":                 this.map.pan(this.slideFactor, 0);                break;            case "zoomin":                 this.map.zoomIn();                 break;            case "zoomout":                 this.map.zoomOut();                 break;            case "zoomworld":                 this.map.zoomToMaxExtent();                 break;        }        OpenLayers.Event.stop(evt);    },    CLASS_NAME: "OpenLayers.Control.PanZoom"});/** * Constant: X * {Integer} */OpenLayers.Control.PanZoom.X = 4;/** * Constant: Y * {Integer} */OpenLayers.Control.PanZoom.Y = 4;
