1
|
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
|
2
|
* full list of contributors). Published under the 2-clause BSD license.
|
3
|
* See license.txt in the OpenLayers distribution or repository for the
|
4
|
* full text of the license. */
|
5
|
|
6
|
|
7
|
/**
|
8
|
* @requires OpenLayers/Layer/Grid.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
|
format: "image/jpeg"
|
31
|
},
|
32
|
|
33
|
/**
|
34
|
* APIProperty: isBaseLayer
|
35
|
* {Boolean} Default is true for WMS layer
|
36
|
*/
|
37
|
isBaseLayer: true,
|
38
|
|
39
|
/**
|
40
|
* APIProperty: encodeBBOX
|
41
|
* {Boolean} Should the BBOX commas be encoded? The WMS spec says 'no',
|
42
|
* but some services want it that way. Default false.
|
43
|
*/
|
44
|
encodeBBOX: false,
|
45
|
|
46
|
/**
|
47
|
* APIProperty: noMagic
|
48
|
* {Boolean} If true, the image format will not be automagicaly switched
|
49
|
* from image/jpeg to image/png or image/gif when using
|
50
|
* TRANSPARENT=TRUE. Also isBaseLayer will not changed by the
|
51
|
* constructor. Default false.
|
52
|
*/
|
53
|
noMagic: false,
|
54
|
|
55
|
/**
|
56
|
* Property: yx
|
57
|
* {Object} Keys in this object are EPSG codes for which the axis order
|
58
|
* is to be reversed (yx instead of xy, LatLon instead of LonLat), with
|
59
|
* true as value. This is only relevant for WMS versions >= 1.3.0, and
|
60
|
* only if yx is not set in <OpenLayers.Projection.defaults> for the
|
61
|
* used projection.
|
62
|
*/
|
63
|
yx: {},
|
64
|
|
65
|
/**
|
66
|
* Constructor: OpenLayers.Layer.WMS
|
67
|
* Create a new WMS layer object
|
68
|
*
|
69
|
* Examples:
|
70
|
*
|
71
|
* The code below creates a simple WMS layer using the image/jpeg format.
|
72
|
* (code)
|
73
|
* var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic",
|
74
|
* "http://wms.jpl.nasa.gov/wms.cgi",
|
75
|
* {layers: "modis,global_mosaic"});
|
76
|
* (end)
|
77
|
* Note the 3rd argument (params). Properties added to this object will be
|
78
|
* added to the WMS GetMap requests used for this layer's tiles. The only
|
79
|
* mandatory parameter is "layers". Other common WMS params include
|
80
|
* "transparent", "styles" and "format". Note that the "srs" param will
|
81
|
* always be ignored. Instead, it will be derived from the baseLayer's or
|
82
|
* map's projection.
|
83
|
*
|
84
|
* The code below creates a transparent WMS layer with additional options.
|
85
|
* (code)
|
86
|
* var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic",
|
87
|
* "http://wms.jpl.nasa.gov/wms.cgi",
|
88
|
* {
|
89
|
* layers: "modis,global_mosaic",
|
90
|
* transparent: true
|
91
|
* }, {
|
92
|
* opacity: 0.5,
|
93
|
* singleTile: true
|
94
|
* });
|
95
|
* (end)
|
96
|
* Note that by default, a WMS layer is configured as baseLayer. Setting
|
97
|
* the "transparent" param to true will apply some magic (see <noMagic>).
|
98
|
* The default image format changes from image/jpeg to image/png, and the
|
99
|
* layer is not configured as baseLayer.
|
100
|
*
|
101
|
* Parameters:
|
102
|
* name - {String} A name for the layer
|
103
|
* url - {String} Base url for the WMS
|
104
|
* (e.g. http://wms.jpl.nasa.gov/wms.cgi)
|
105
|
* params - {Object} An object with key/value pairs representing the
|
106
|
* GetMap query string parameters and parameter values.
|
107
|
* options - {Object} Hashtable of extra options to tag onto the layer.
|
108
|
* These options include all properties listed above, plus the ones
|
109
|
* inherited from superclasses.
|
110
|
*/
|
111
|
initialize: function(name, url, params, options) {
|
112
|
var newArguments = [];
|
113
|
//uppercase params
|
114
|
params = OpenLayers.Util.upperCaseObject(params);
|
115
|
if (parseFloat(params.VERSION) >= 1.3 && !params.EXCEPTIONS) {
|
116
|
params.EXCEPTIONS = "INIMAGE";
|
117
|
}
|
118
|
newArguments.push(name, url, params, options);
|
119
|
OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
|
120
|
OpenLayers.Util.applyDefaults(
|
121
|
this.params,
|
122
|
OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS)
|
123
|
);
|
124
|
|
125
|
|
126
|
//layer is transparent
|
127
|
if (!this.noMagic && this.params.TRANSPARENT &&
|
128
|
this.params.TRANSPARENT.toString().toLowerCase() == "true") {
|
129
|
|
130
|
// unless explicitly set in options, make layer an overlay
|
131
|
if ( (options == null) || (!options.isBaseLayer) ) {
|
132
|
this.isBaseLayer = false;
|
133
|
}
|
134
|
|
135
|
// jpegs can never be transparent, so intelligently switch the
|
136
|
// format, depending on the browser's capabilities
|
137
|
if (this.params.FORMAT == "image/jpeg") {
|
138
|
this.params.FORMAT = OpenLayers.Util.alphaHack() ? "image/gif"
|
139
|
: "image/png";
|
140
|
}
|
141
|
}
|
142
|
|
143
|
},
|
144
|
|
145
|
/**
|
146
|
* Method: clone
|
147
|
* Create a clone of this layer
|
148
|
*
|
149
|
* Returns:
|
150
|
* {<OpenLayers.Layer.WMS>} An exact clone of this layer
|
151
|
*/
|
152
|
clone: function (obj) {
|
153
|
|
154
|
if (obj == null) {
|
155
|
obj = new OpenLayers.Layer.WMS(this.name,
|
156
|
this.url,
|
157
|
this.params,
|
158
|
this.getOptions());
|
159
|
}
|
160
|
|
161
|
//get all additions from superclasses
|
162
|
obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
|
163
|
|
164
|
// copy/set any non-init, non-simple values here
|
165
|
|
166
|
return obj;
|
167
|
},
|
168
|
|
169
|
/**
|
170
|
* APIMethod: reverseAxisOrder
|
171
|
* Returns true if the axis order is reversed for the WMS version and
|
172
|
* projection of the layer.
|
173
|
*
|
174
|
* Returns:
|
175
|
* {Boolean} true if the axis order is reversed, false otherwise.
|
176
|
*/
|
177
|
reverseAxisOrder: function() {
|
178
|
var projCode = this.projection.getCode();
|
179
|
return parseFloat(this.params.VERSION) >= 1.3 &&
|
180
|
!!(this.yx[projCode] || (OpenLayers.Projection.defaults[projCode] &&
|
181
|
OpenLayers.Projection.defaults[projCode].yx));
|
182
|
},
|
183
|
|
184
|
/**
|
185
|
* Method: getURL
|
186
|
* Return a GetMap query string for this layer
|
187
|
*
|
188
|
* Parameters:
|
189
|
* bounds - {<OpenLayers.Bounds>} A bounds representing the bbox for the
|
190
|
* request.
|
191
|
*
|
192
|
* Returns:
|
193
|
* {String} A string with the layer's url and parameters and also the
|
194
|
* passed-in bounds and appropriate tile size specified as
|
195
|
* parameters.
|
196
|
*/
|
197
|
getURL: function (bounds) {
|
198
|
bounds = this.adjustBounds(bounds);
|
199
|
|
200
|
var imageSize = this.getImageSize();
|
201
|
var newParams = {};
|
202
|
// WMS 1.3 introduced axis order
|
203
|
var reverseAxisOrder = this.reverseAxisOrder();
|
204
|
newParams.BBOX = this.encodeBBOX ?
|
205
|
bounds.toBBOX(null, reverseAxisOrder) :
|
206
|
bounds.toArray(reverseAxisOrder);
|
207
|
newParams.WIDTH = imageSize.w;
|
208
|
newParams.HEIGHT = imageSize.h;
|
209
|
var requestString = this.getFullRequestString(newParams);
|
210
|
return requestString;
|
211
|
},
|
212
|
|
213
|
/**
|
214
|
* APIMethod: mergeNewParams
|
215
|
* Catch changeParams and uppercase the new params to be merged in
|
216
|
* before calling changeParams on the super class.
|
217
|
*
|
218
|
* Once params have been changed, the tiles will be reloaded with
|
219
|
* the new parameters.
|
220
|
*
|
221
|
* Parameters:
|
222
|
* newParams - {Object} Hashtable of new params to use
|
223
|
*/
|
224
|
mergeNewParams:function(newParams) {
|
225
|
var upperParams = OpenLayers.Util.upperCaseObject(newParams);
|
226
|
var newArguments = [upperParams];
|
227
|
return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this,
|
228
|
newArguments);
|
229
|
},
|
230
|
|
231
|
/**
|
232
|
* APIMethod: getFullRequestString
|
233
|
* Combine the layer's url with its params and these newParams.
|
234
|
*
|
235
|
* Add the SRS parameter from projection -- this is probably
|
236
|
* more eloquently done via a setProjection() method, but this
|
237
|
* works for now and always.
|
238
|
*
|
239
|
* Parameters:
|
240
|
* newParams - {Object}
|
241
|
* altUrl - {String} Use this as the url instead of the layer's url
|
242
|
*
|
243
|
* Returns:
|
244
|
* {String}
|
245
|
*/
|
246
|
getFullRequestString:function(newParams, altUrl) {
|
247
|
var mapProjection = this.map.getProjectionObject();
|
248
|
var projectionCode = this.projection && this.projection.equals(mapProjection) ?
|
249
|
this.projection.getCode() :
|
250
|
mapProjection.getCode();
|
251
|
var value = (projectionCode == "none") ? null : projectionCode;
|
252
|
if (parseFloat(this.params.VERSION) >= 1.3) {
|
253
|
this.params.CRS = value;
|
254
|
} else {
|
255
|
this.params.SRS = value;
|
256
|
}
|
257
|
|
258
|
if (typeof this.params.TRANSPARENT == "boolean") {
|
259
|
newParams.TRANSPARENT = this.params.TRANSPARENT ? "TRUE" : "FALSE";
|
260
|
}
|
261
|
|
262
|
return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(
|
263
|
this, arguments);
|
264
|
},
|
265
|
|
266
|
CLASS_NAME: "OpenLayers.Layer.WMS"
|
267
|
});
|