Bienvenue sur PostGIS.fr

Bienvenue sur PostGIS.fr , le site de la communauté des utilisateurs francophones de PostGIS.

PostGIS ajoute le support d'objets géographique à la base de données PostgreSQL. En effet, PostGIS "spatialise" le serverur PostgreSQL, ce qui permet de l'utiliser comme une base de données SIG.

Maintenu à jour, en fonction de nos disponibilités et des diverses sorties des outils que nous testons, nous vous proposons l'ensemble de nos travaux publiés en langue française.

source: trunk/workshop-routing-foss4g/web/OpenLayers/lib/OpenLayers/Layer/WMS.js @ 76

Revision 76, 9.0 KB checked in by djay, 12 years ago (diff)

Ajout du répertoire web

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