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. */
7
* @requires OpenLayers/Layer/Grid.js
8
* @requires OpenLayers/Tile/Image.js
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>
18
* - <OpenLayers.Layer.Grid>
20
OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
23
* Constant: DEFAULT_PARAMS
24
* {Object} Hashtable of default parameter key/value pairs
26
DEFAULT_PARAMS: { service: "WMS",
30
exceptions: "application/vnd.ogc.se_inimage",
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
46
* APIProperty: isBaseLayer
47
* {Boolean} Default is true for WMS layer
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.
59
* Constructor: OpenLayers.Layer.WMS
60
* Create a new WMS layer object
64
* var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic",
65
* "http://wms.jpl.nasa.gov/wms.cgi",
66
* {layers: "modis,global_mosaic"});
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
77
initialize: function(name, url, params, options) {
78
var newArguments = [];
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(
85
OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS)
89
//layer is transparent
90
if (this.params.TRANSPARENT &&
91
this.params.TRANSPARENT.toString().toLowerCase() == "true") {
93
// unless explicitly set in options, make layer an overlay
94
if ( (options == null) || (!options.isBaseLayer) ) {
95
this.isBaseLayer = false;
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"
112
destroy: function() {
113
// for now, nothing special to do here.
114
OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments);
120
* Create a clone of this layer
123
* {<OpenLayers.Layer.WMS>} An exact clone of this layer
125
clone: function (obj) {
128
obj = new OpenLayers.Layer.WMS(this.name,
134
//get all additions from superclasses
135
obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
137
// copy/set any non-init, non-simple values here
144
* Return a GetMap query string for this layer
147
* bounds - {<OpenLayers.Bounds>} A bounds representing the bbox for the
151
* {String} A string with the layer's url and parameters and also the
152
* passed-in bounds and appropriate tile size specified as
155
getURL: function (bounds) {
156
bounds = this.adjustBounds(bounds);
158
var imageSize = this.getImageSize();
160
'BBOX': this.encodeBBOX ? bounds.toBBOX() : bounds.toArray(),
161
'WIDTH': imageSize.w,
162
'HEIGHT': imageSize.h
164
var requestString = this.getFullRequestString(newParams);
165
return requestString;
170
* addTile creates a tile, initializes it, and adds it to the layer div.
173
* bounds - {<OpenLayers.Bounds>}
174
* position - {<OpenLayers.Pixel>}
177
* {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image
179
addTile:function(bounds,position) {
180
return new OpenLayers.Tile.Image(this, position, bounds,
181
null, this.tileSize);
185
* APIMethod: mergeNewParams
186
* Catch changeParams and uppercase the new params to be merged in
187
* before calling changeParams on the super class.
189
* Once params have been changed, the tiles will be reloaded with
190
* the new parameters.
193
* newParams - {Object} Hashtable of new params to use
195
mergeNewParams:function(newParams) {
196
var upperParams = OpenLayers.Util.upperCaseObject(newParams);
197
var newArguments = [upperParams];
198
return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this,
203
* APIMethod: getFullRequestString
204
* Combine the layer's url with its params and these newParams.
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.
211
* newParams - {Object}
212
* altUrl - {String} Use this as the url instead of the layer's url
217
getFullRequestString:function(newParams, altUrl) {
218
var projectionCode = this.map.getProjection();
219
this.params.SRS = (projectionCode == "none") ? null : projectionCode;
221
return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(
225
CLASS_NAME: "OpenLayers.Layer.WMS"