~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/ArgParser.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
/**
 
7
 * @requires OpenLayers/Control.js
 
8
 */
 
9
 
 
10
/**
 
11
 * Class: OpenLayers.Control.ArgParser
 
12
 * 
 
13
 * Inherits from:
 
14
 *  - <OpenLayers.Control>
 
15
 */
 
16
OpenLayers.Control.ArgParser = OpenLayers.Class(OpenLayers.Control, {
 
17
 
 
18
    /**
 
19
     * Parameter: center
 
20
     * {<OpenLayers.LonLat>}
 
21
     */
 
22
    center: null,
 
23
    
 
24
    /**
 
25
     * Parameter: zoom
 
26
     * {int}
 
27
     */
 
28
    zoom: null,
 
29
 
 
30
    /**
 
31
     * Parameter: layers 
 
32
     * {Array(<OpenLayers.Layer>)}
 
33
     */
 
34
    layers: null,
 
35
    
 
36
    /** 
 
37
     * APIProperty: displayProjection
 
38
     * {<OpenLayers.Projection>} Requires proj4js support. 
 
39
     *     Projection used when reading the coordinates from the URL. This will
 
40
     *     reproject the map coordinates from the URL into the map's
 
41
     *     projection.
 
42
     *
 
43
     *     If you are using this functionality, be aware that any permalink
 
44
     *     which is added to the map will determine the coordinate type which
 
45
     *     is read from the URL, which means you should not add permalinks with
 
46
     *     different displayProjections to the same map. 
 
47
     */
 
48
    displayProjection: null, 
 
49
 
 
50
    /**
 
51
     * Constructor: OpenLayers.Control.ArgParser
 
52
     *
 
53
     * Parameters:
 
54
     * options - {Object}
 
55
     */
 
56
    initialize: function(options) {
 
57
        OpenLayers.Control.prototype.initialize.apply(this, arguments);
 
58
    },
 
59
 
 
60
    /**
 
61
     * Method: setMap
 
62
     * Set the map property for the control. 
 
63
     * 
 
64
     * Parameters:
 
65
     * map - {<OpenLayers.Map>} 
 
66
     */
 
67
    setMap: function(map) {
 
68
        OpenLayers.Control.prototype.setMap.apply(this, arguments);
 
69
 
 
70
        //make sure we dont already have an arg parser attached
 
71
        for(var i=0, len=this.map.controls.length; i<len; i++) {
 
72
            var control = this.map.controls[i];
 
73
            if ( (control != this) &&
 
74
                 (control.CLASS_NAME == "OpenLayers.Control.ArgParser") ) {
 
75
                
 
76
                // If a second argparser is added to the map, then we 
 
77
                // override the displayProjection to be the one added to the
 
78
                // map. 
 
79
                if (control.displayProjection != this.displayProjection) {
 
80
                    this.displayProjection = control.displayProjection;
 
81
                }    
 
82
                
 
83
                break;
 
84
            }
 
85
        }
 
86
        if (i == this.map.controls.length) {
 
87
 
 
88
            var args = OpenLayers.Util.getParameters();
 
89
            // Be careful to set layer first, to not trigger unnecessary layer loads
 
90
            if (args.layers) {
 
91
                this.layers = args.layers;
 
92
    
 
93
                // when we add a new layer, set its visibility 
 
94
                this.map.events.register('addlayer', this, 
 
95
                                         this.configureLayers);
 
96
                this.configureLayers();
 
97
            }
 
98
            if (args.lat && args.lon) {
 
99
                this.center = new OpenLayers.LonLat(parseFloat(args.lon),
 
100
                                                    parseFloat(args.lat));
 
101
                if (args.zoom) {
 
102
                    this.zoom = parseInt(args.zoom);
 
103
                }
 
104
    
 
105
                // when we add a new baselayer to see when we can set the center
 
106
                this.map.events.register('changebaselayer', this, 
 
107
                                         this.setCenter);
 
108
                this.setCenter();
 
109
            }
 
110
        }
 
111
    },
 
112
   
 
113
    /** 
 
114
     * Method: setCenter
 
115
     * As soon as a baseLayer has been loaded, we center and zoom
 
116
     *   ...and remove the handler.
 
117
     */
 
118
    setCenter: function() {
 
119
        
 
120
        if (this.map.baseLayer) {
 
121
            //dont need to listen for this one anymore
 
122
            this.map.events.unregister('changebaselayer', this, 
 
123
                                       this.setCenter);
 
124
            
 
125
            if (this.displayProjection) {
 
126
                this.center.transform(this.displayProjection, 
 
127
                                      this.map.getProjectionObject()); 
 
128
            }      
 
129
 
 
130
            this.map.setCenter(this.center, this.zoom);
 
131
        }
 
132
    },
 
133
 
 
134
    /** 
 
135
     * Method: configureLayers
 
136
     * As soon as all the layers are loaded, cycle through them and 
 
137
     *   hide or show them. 
 
138
     */
 
139
    configureLayers: function() {
 
140
 
 
141
        if (this.layers.length == this.map.layers.length) { 
 
142
            this.map.events.unregister('addlayer', this, this.configureLayers);
 
143
 
 
144
            for(var i=0, len=this.layers.length; i<len; i++) {
 
145
                
 
146
                var layer = this.map.layers[i];
 
147
                var c = this.layers.charAt(i);
 
148
                
 
149
                if (c == "B") {
 
150
                    this.map.setBaseLayer(layer);
 
151
                } else if ( (c == "T") || (c == "F") ) {
 
152
                    layer.setVisibility(c == "T");
 
153
                }
 
154
            }
 
155
        }
 
156
    },     
 
157
 
 
158
    CLASS_NAME: "OpenLayers.Control.ArgParser"
 
159
});