~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/Control/ZoomBox.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
 
2
 * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
 
3
 * full text of the license. */
 
4
 
 
5
/**
 
6
 * @requires OpenLayers/Control.js
 
7
 * @requires OpenLayers/Handler/Box.js
 
8
 */
 
9
 
 
10
/**
 
11
 * Class: OpenLayers.Control.ZoomBox
 
12
 *
 
13
 * Inherits from:
 
14
 *  - <OpenLayers.Control>
 
15
 */
 
16
OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
 
17
    /**
 
18
     * Property: type
 
19
     * {OpenLayers.Control.TYPE}
 
20
     */
 
21
    type: OpenLayers.Control.TYPE_TOOL,
 
22
 
 
23
    /**
 
24
     * Property: out
 
25
     * {Boolean} Should the control be used for zooming out?
 
26
     */
 
27
    out: false,
 
28
 
 
29
    /**
 
30
     * Method: draw
 
31
     */    
 
32
    draw: function() {
 
33
        this.handler = new OpenLayers.Handler.Box( this,
 
34
                            {done: this.zoomBox}, {keyMask: this.keyMask} );
 
35
    },
 
36
 
 
37
    /**
 
38
     * Method: zoomBox
 
39
     *
 
40
     * Parameters:
 
41
     * position - {<OpenLayers.Bounds>} or {<OpenLayers.Pixel>}
 
42
     */
 
43
    zoomBox: function (position) {
 
44
        if (position instanceof OpenLayers.Bounds) {
 
45
            if (!this.out) {
 
46
                var minXY = this.map.getLonLatFromPixel(
 
47
                            new OpenLayers.Pixel(position.left, position.bottom));
 
48
                var maxXY = this.map.getLonLatFromPixel(
 
49
                            new OpenLayers.Pixel(position.right, position.top));
 
50
                var bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat,
 
51
                                               maxXY.lon, maxXY.lat);
 
52
            } else {
 
53
                var pixWidth = Math.abs(position.right-position.left);
 
54
                var pixHeight = Math.abs(position.top-position.bottom);
 
55
                var zoomFactor = Math.min((this.map.size.h / pixHeight),
 
56
                    (this.map.size.w / pixWidth));
 
57
                var extent = this.map.getExtent();
 
58
                var center = this.map.getLonLatFromPixel(
 
59
                    position.getCenterPixel());
 
60
                var xmin = center.lon - (extent.getWidth()/2)*zoomFactor;
 
61
                var xmax = center.lon + (extent.getWidth()/2)*zoomFactor;
 
62
                var ymin = center.lat - (extent.getHeight()/2)*zoomFactor;
 
63
                var ymax = center.lat + (extent.getHeight()/2)*zoomFactor;
 
64
                var bounds = new OpenLayers.Bounds(xmin, ymin, xmax, ymax);
 
65
            }
 
66
            this.map.zoomToExtent(bounds);
 
67
        } else { // it's a pixel
 
68
            if (!this.out) {
 
69
                this.map.setCenter(this.map.getLonLatFromPixel(position),
 
70
                               this.map.getZoom() + 1);
 
71
            } else {
 
72
                this.map.setCenter(this.map.getLonLatFromPixel(position),
 
73
                               this.map.getZoom() - 1);
 
74
            }
 
75
        }
 
76
    },
 
77
 
 
78
    CLASS_NAME: "OpenLayers.Control.ZoomBox"
 
79
});