1 /* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
 
   2  * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
 
   3  * text of the license. */
 
   4 // @require: OpenLayers/Control.js
 
   9  * default zoom/pan controls
 
  11 OpenLayers.Control.PanZoom = Class.create();
 
  12 OpenLayers.Control.PanZoom.X = 4;
 
  13 OpenLayers.Control.PanZoom.Y = 4;
 
  14 OpenLayers.Control.PanZoom.prototype = 
 
  15   Object.extend( new OpenLayers.Control(), {
 
  20     /** @type Array of Button Divs */
 
  23     /** @type OpenLayers.Pixel */
 
  29     initialize: function() {
 
  30         OpenLayers.Control.prototype.initialize.apply(this, arguments);
 
  31         this.position = new OpenLayers.Pixel(OpenLayers.Control.PanZoom.X,
 
  32                                              OpenLayers.Control.PanZoom.Y);
 
  36     * @param {OpenLayers.Pixel} px
 
  38     * @returns A reference to the container div for the PanZoom control
 
  42         // initialize our internal div
 
  43         OpenLayers.Control.prototype.draw.apply(this, arguments);
 
  47         this.buttons = new Array();
 
  49         var sz = new OpenLayers.Size(18,18);
 
  50         var centered = new OpenLayers.Pixel(px.x+sz.w/2, px.y);
 
  52         this._addButton("panup", "north-mini.png", centered, sz);
 
  53         px.y = centered.y+sz.h;
 
  54         this._addButton("panleft", "west-mini.png", px, sz);
 
  55         this._addButton("panright", "east-mini.png", px.add(sz.w, 0), sz);
 
  56         this._addButton("pandown", "south-mini.png", 
 
  57                         centered.add(0, sz.h*2), sz);
 
  58         this._addButton("zoomin", "zoom-plus-mini.png", 
 
  59                         centered.add(0, sz.h*3+5), sz);
 
  60         this._addButton("zoomworld", "zoom-world-mini.png", 
 
  61                         centered.add(0, sz.h*4+5), sz);
 
  62         this._addButton("zoomout", "zoom-minus-mini.png", 
 
  63                         centered.add(0, sz.h*5+5), sz);
 
  70      * @param {OpenLayers.Pixel} xy
 
  71      * @param {OpenLayers.Size} sz
 
  73      * @returns A Div (an alphaImageDiv, to be precise) that contains the 
 
  74      *          image of the button, and has all the proper event handlers
 
  78     _addButton:function(id, img, xy, sz) {
 
  79         var imgLocation = OpenLayers.Util.getImagesLocation() + img;
 
  80         // var btn = new ol.AlphaImage("_"+id, imgLocation, xy, sz);
 
  81         var btn = OpenLayers.Util.createAlphaImageDiv(
 
  82                                     "OpenLayers_Control_PanZoom_" + id, 
 
  83                                     xy, sz, imgLocation, "absolute");
 
  85         //we want to add the outer div
 
  86         this.div.appendChild(btn);
 
  88         btn.onmousedown = this.buttonDown.bindAsEventListener(btn);
 
  89         btn.ondblclick  = this.doubleClick.bindAsEventListener(btn);
 
  90         btn.onclick  = this.doubleClick.bindAsEventListener(btn);
 
  93         btn.slideFactor = this.slideFactor;
 
  95         //we want to remember/reference the outer div
 
  96         this.buttons.push(btn);
 
 105     doubleClick: function (evt) {
 
 113     buttonDown: function (evt) {
 
 114         if (!Event.isLeftClick(evt)) return;
 
 116         var slide = this.map.getResolution() * this.slideFactor;
 
 117         var center = this.map.getCenter();
 
 119         var newCenter = center.copyOf();
 
 121         switch (this.action) {
 
 123                 newCenter = newCenter.add( 0, slide);
 
 126                 newCenter = newCenter.add( 0, -slide);
 
 129                 newCenter = newCenter.add( -slide, 0);
 
 132                 newCenter = newCenter.add( slide, 0);
 
 141                 this.map.zoomToFullExtent(); 
 
 145         if (!newCenter.equals(center)) {
 
 146             this.map.setCenter(newCenter);
 
 155     destroy: function() {
 
 156         OpenLayers.Control.prototype.destroy.apply(this, arguments);
 
 157         for(i=0; i<this.buttons.length; i++) {
 
 158             this.buttons[i].map = null;
 
 162     /** @final @type String */
 
 163     CLASS_NAME: "OpenLayers.Control.PanZoom"