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 * APIProperty: noMagic
60 * {Boolean} If true, the image format will not be automagicaly switched
61 * from image/jpeg to image/png or image/gif when using
62 * TRANSPARENT=TRUE. Also isBaseLayer will not changed by the
63 * constructor. Default false.
68 * Constructor: OpenLayers.Layer.WMS
69 * Create a new WMS layer object
73 * var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic",
74 * "http://wms.jpl.nasa.gov/wms.cgi",
75 * {layers: "modis,global_mosaic"});
79 * name - {String} A name for the layer
80 * url - {String} Base url for the WMS
81 * (e.g. http://wms.jpl.nasa.gov/wms.cgi)
82 * params - {Object} An object with key/value pairs representing the
83 * GetMap query string parameters and parameter values.
84 * options - {Ojbect} Hashtable of extra options to tag onto the layer
86 initialize: function(name, url, params, options) {
87 var newArguments = [];
89 params = OpenLayers.Util.upperCaseObject(params);
90 newArguments.push(name, url, params, options);
91 OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
92 OpenLayers.Util.applyDefaults(
94 OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS)
98 //layer is transparent
99 if (!this.noMagic && this.params.TRANSPARENT &&
100 this.params.TRANSPARENT.toString().toLowerCase() == "true") {
102 // unless explicitly set in options, make layer an overlay
103 if ( (options == null) || (!options.isBaseLayer) ) {
104 this.isBaseLayer = false;
107 // jpegs can never be transparent, so intelligently switch the
108 // format, depending on teh browser's capabilities
109 if (this.params.FORMAT == "image/jpeg") {
110 this.params.FORMAT = OpenLayers.Util.alphaHack() ? "image/gif"
121 destroy: function() {
122 // for now, nothing special to do here.
123 OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments);
129 * Create a clone of this layer
132 * {<OpenLayers.Layer.WMS>} An exact clone of this layer
134 clone: function (obj) {
137 obj = new OpenLayers.Layer.WMS(this.name,
143 //get all additions from superclasses
144 obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
146 // copy/set any non-init, non-simple values here
153 * Return a GetMap query string for this layer
156 * bounds - {<OpenLayers.Bounds>} A bounds representing the bbox for the
160 * {String} A string with the layer's url and parameters and also the
161 * passed-in bounds and appropriate tile size specified as
164 getURL: function (bounds) {
165 bounds = this.adjustBounds(bounds);
167 var imageSize = this.getImageSize();
169 'BBOX': this.encodeBBOX ? bounds.toBBOX() : bounds.toArray(),
170 'WIDTH': imageSize.w,
171 'HEIGHT': imageSize.h
173 var requestString = this.getFullRequestString(newParams);
174 return requestString;
179 * addTile creates a tile, initializes it, and adds it to the layer div.
182 * bounds - {<OpenLayers.Bounds>}
183 * position - {<OpenLayers.Pixel>}
186 * {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image
188 addTile:function(bounds,position) {
189 return new OpenLayers.Tile.Image(this, position, bounds,
190 null, this.tileSize);
194 * APIMethod: mergeNewParams
195 * Catch changeParams and uppercase the new params to be merged in
196 * before calling changeParams on the super class.
198 * Once params have been changed, the tiles will be reloaded with
199 * the new parameters.
202 * newParams - {Object} Hashtable of new params to use
204 mergeNewParams:function(newParams) {
205 var upperParams = OpenLayers.Util.upperCaseObject(newParams);
206 var newArguments = [upperParams];
207 return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this,
212 * APIMethod: getFullRequestString
213 * Combine the layer's url with its params and these newParams.
215 * Add the SRS parameter from projection -- this is probably
216 * more eloquently done via a setProjection() method, but this
217 * works for now and always.
220 * newParams - {Object}
221 * altUrl - {String} Use this as the url instead of the layer's url
226 getFullRequestString:function(newParams, altUrl) {
227 var projectionCode = this.map.getProjection();
228 this.params.SRS = (projectionCode == "none") ? null : projectionCode;
230 return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(
234 CLASS_NAME: "OpenLayers.Layer.WMS"