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

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/Layer/WMS.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/Layer/Grid.js
 
8
 * @requires OpenLayers/Tile/Image.js
 
9
 */
 
10
 
 
11
/**
 
12
 * Class: OpenLayers.Layer.WMS
 
13
 * Instances of OpenLayers.Layer.WMS are used to display data from OGC Web
 
14
 *     Mapping Services. Create a new WMS layer with the <OpenLayers.Layer.WMS>
 
15
 *     constructor.
 
16
 * 
 
17
 * Inherits from:
 
18
 *  - <OpenLayers.Layer.Grid>
 
19
 */
 
20
OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
 
21
 
 
22
    /**
 
23
     * Constant: DEFAULT_PARAMS
 
24
     * {Object} Hashtable of default parameter key/value pairs 
 
25
     */
 
26
    DEFAULT_PARAMS: { service: "WMS",
 
27
                      version: "1.1.1",
 
28
                      request: "GetMap",
 
29
                      styles: "",
 
30
                      exceptions: "application/vnd.ogc.se_inimage",
 
31
                      format: "image/jpeg"
 
32
                     },
 
33
    
 
34
    /**
 
35
     * Property: reproject
 
36
     * *Deprecated*. See http://trac.openlayers.org/wiki/SphericalMercator
 
37
     * for information on the replacement for this functionality. 
 
38
     * {Boolean} Try to reproject this layer if its coordinate reference system
 
39
     *           is different than that of the base layer.  Default is true.  
 
40
     *           Set this in the layer options.  Should be set to false in 
 
41
     *           most cases.
 
42
     */
 
43
    reproject: false,
 
44
 
 
45
    /**
 
46
     * APIProperty: isBaseLayer
 
47
     * {Boolean} Default is true for WMS layer
 
48
     */
 
49
    isBaseLayer: true,
 
50
    
 
51
    /**
 
52
     * APIProperty: encodeBBOX
 
53
     * {Boolean} Should the BBOX commas be encoded? The WMS spec says 'no', 
 
54
     * but some services want it that way. Default false.
 
55
     */
 
56
    encodeBBOX: false,
 
57
 
 
58
    /**
 
59
     * Constructor: OpenLayers.Layer.WMS
 
60
     * Create a new WMS layer object
 
61
     *
 
62
     * Example:
 
63
     * (code)
 
64
     * var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic",
 
65
     *                                    "http://wms.jpl.nasa.gov/wms.cgi", 
 
66
     *                                    {layers: "modis,global_mosaic"});
 
67
     * (end)
 
68
     *
 
69
     * Parameters:
 
70
     * name - {String} A name for the layer
 
71
     * url - {String} Base url for the WMS
 
72
     *                (e.g. http://wms.jpl.nasa.gov/wms.cgi)
 
73
     * params - {Object} An object with key/value pairs representing the
 
74
     *                   GetMap query string parameters and parameter values.
 
75
     * options - {Ojbect} Hashtable of extra options to tag onto the layer
 
76
     */
 
77
    initialize: function(name, url, params, options) {
 
78
        var newArguments = [];
 
79
        //uppercase params
 
80
        params = OpenLayers.Util.upperCaseObject(params);
 
81
        newArguments.push(name, url, params, options);
 
82
        OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
 
83
        OpenLayers.Util.applyDefaults(
 
84
                       this.params, 
 
85
                       OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS)
 
86
                       );
 
87
 
 
88
 
 
89
        //layer is transparent        
 
90
        if (this.params.TRANSPARENT && 
 
91
            this.params.TRANSPARENT.toString().toLowerCase() == "true") {
 
92
            
 
93
            // unless explicitly set in options, make layer an overlay
 
94
            if ( (options == null) || (!options.isBaseLayer) ) {
 
95
                this.isBaseLayer = false;
 
96
            } 
 
97
            
 
98
            // jpegs can never be transparent, so intelligently switch the 
 
99
            //  format, depending on teh browser's capabilities
 
100
            if (this.params.FORMAT == "image/jpeg") {
 
101
                this.params.FORMAT = OpenLayers.Util.alphaHack() ? "image/gif"
 
102
                                                                 : "image/png";
 
103
            }
 
104
        }
 
105
 
 
106
    },    
 
107
 
 
108
    /**
 
109
     * Method: destroy
 
110
     * Destroy this layer
 
111
     */
 
112
    destroy: function() {
 
113
        // for now, nothing special to do here. 
 
114
        OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments);  
 
115
    },
 
116
 
 
117
    
 
118
    /**
 
119
     * Method: clone
 
120
     * Create a clone of this layer
 
121
     *
 
122
     * Returns:
 
123
     * {<OpenLayers.Layer.WMS>} An exact clone of this layer
 
124
     */
 
125
    clone: function (obj) {
 
126
        
 
127
        if (obj == null) {
 
128
            obj = new OpenLayers.Layer.WMS(this.name,
 
129
                                           this.url,
 
130
                                           this.params,
 
131
                                           this.options);
 
132
        }
 
133
 
 
134
        //get all additions from superclasses
 
135
        obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
 
136
 
 
137
        // copy/set any non-init, non-simple values here
 
138
 
 
139
        return obj;
 
140
    },    
 
141
    
 
142
    /**
 
143
     * Method: getURL
 
144
     * Return a GetMap query string for this layer
 
145
     *
 
146
     * Parameters:
 
147
     * bounds - {<OpenLayers.Bounds>} A bounds representing the bbox for the
 
148
     *                                request.
 
149
     *
 
150
     * Returns:
 
151
     * {String} A string with the layer's url and parameters and also the
 
152
     *          passed-in bounds and appropriate tile size specified as 
 
153
     *          parameters.
 
154
     */
 
155
    getURL: function (bounds) {
 
156
        bounds = this.adjustBounds(bounds);
 
157
        
 
158
        var imageSize = this.getImageSize(); 
 
159
        var newParams = {
 
160
            'BBOX': this.encodeBBOX ?  bounds.toBBOX() : bounds.toArray(),
 
161
            'WIDTH': imageSize.w,
 
162
            'HEIGHT': imageSize.h
 
163
        };
 
164
        var requestString = this.getFullRequestString(newParams);
 
165
        return requestString;
 
166
    },
 
167
 
 
168
    /**
 
169
     * Method: addTile
 
170
     * addTile creates a tile, initializes it, and adds it to the layer div. 
 
171
     *
 
172
     * Parameters:
 
173
     * bounds - {<OpenLayers.Bounds>}
 
174
     * position - {<OpenLayers.Pixel>}
 
175
     * 
 
176
     * Returns:
 
177
     * {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image
 
178
     */
 
179
    addTile:function(bounds,position) {
 
180
        return new OpenLayers.Tile.Image(this, position, bounds, 
 
181
                                         null, this.tileSize);
 
182
    },
 
183
 
 
184
    /**
 
185
     * APIMethod: mergeNewParams
 
186
     * Catch changeParams and uppercase the new params to be merged in
 
187
     *     before calling changeParams on the super class.
 
188
     * 
 
189
     *     Once params have been changed, the tiles will be reloaded with
 
190
     *     the new parameters.
 
191
     * 
 
192
     * Parameters:
 
193
     * newParams - {Object} Hashtable of new params to use
 
194
     */
 
195
    mergeNewParams:function(newParams) {
 
196
        var upperParams = OpenLayers.Util.upperCaseObject(newParams);
 
197
        var newArguments = [upperParams];
 
198
        return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this, 
 
199
                                                             newArguments);
 
200
    },
 
201
 
 
202
    /** 
 
203
     * APIMethod: getFullRequestString
 
204
     * Combine the layer's url with its params and these newParams. 
 
205
     *   
 
206
     *     Add the SRS parameter from projection -- this is probably
 
207
     *     more eloquently done via a setProjection() method, but this 
 
208
     *     works for now and always.
 
209
     *
 
210
     * Parameters:
 
211
     * newParams - {Object}
 
212
     * altUrl - {String} Use this as the url instead of the layer's url
 
213
     * 
 
214
     * Returns:
 
215
     * {String} 
 
216
     */
 
217
    getFullRequestString:function(newParams, altUrl) {
 
218
        var projectionCode = this.map.getProjection();
 
219
        this.params.SRS = (projectionCode == "none") ? null : projectionCode;
 
220
 
 
221
        return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(
 
222
                                                    this, arguments);
 
223
    },
 
224
 
 
225
    CLASS_NAME: "OpenLayers.Layer.WMS"
 
226
});