Project

General

Profile

1
/*
2
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
3
$Id: ZoomOut.js 3894 2008-02-29 18:37:09Z ahocevar $
4
*/
5

    
6
// Ensure this object's dependancies are loaded.
7
mapbuilder.loadScript(baseDir+"/widget/ButtonBase.js");
8
mapbuilder.loadScript(baseDir+"/util/openlayers/OpenLayers.js");
9

    
10
/**
11
 * Zoom Out button.
12
 * @base ButtonBase
13
 * @author Andreas Hocevar andreas.hocevarATgmail.com
14
 * @param widgetNode      The tool node from the Config XML file.
15
 * @param model  The ButtonBar widget.
16
 */
17
function ZoomOut(widgetNode, model) {
18
   ButtonBase.apply(this, new Array(widgetNode, model));
19

    
20
  this.cursor = 'crosshair';
21

    
22
  /**
23
   * Interactive ZoomOut control.
24
   * @param objRef reference to this object.
25
   * @return {OpenLayers.Control} class of the OL control.
26
   */
27
  this.createControl = function(objRef) {
28
    var Control = OpenLayers.Class( OpenLayers.Control, {
29
      CLASS_NAME: 'mbControl.ZoomOut',
30
      type: OpenLayers.Control.TYPE_TOOL,
31

    
32
      draw: function() {
33
        this.handler = new OpenLayers.Handler.Box( this,
34
          {done: this.zoomBox}, {keyMask: this.keyMask} );
35
      },
36

    
37
      zoomBox: function (position) {
38
        if (position instanceof OpenLayers.Bounds) {
39
          var minXY = new OpenLayers.Pixel(position.left, position.bottom);
40
          var maxXY = new OpenLayers.Pixel(position.right, position.top);
41
          var bounds = new OpenLayers.Bounds(minXY.x, minXY.y,
42
            maxXY.x, maxXY.y);
43
          var mapSize = (this.map.getSize().w+this.map.getSize().h)/2;
44
          var boxSize = (Math.abs(bounds.getWidth())+Math.abs(bounds.getHeight()))/2;
45
          var newScale = this.map.getScale()*(mapSize/boxSize);
46
          this.map.setCenter(bounds.getCenterLonLat());
47
          this.map.zoomToScale(newScale);
48
        } else { // it's a pixel
49
          this.map.setCenter(this.map.getLonLatFromPixel(position),
50
            parseInt(this.map.getZoom() - 1));
51
        }
52
      }
53
    });
54
    return Control;
55
  }
56
}
57

    
58

    
(144-144/145)