Project

General

Profile

1
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
2
 * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
3
 * text of the license. */
4

    
5
/**
6
 * @class
7
 * 
8
 * @requires OpenLayers/Layer/Grid.js
9
 */
10
OpenLayers.Layer.WMS = Class.create();
11
OpenLayers.Layer.WMS.prototype = 
12
  Object.extend( new OpenLayers.Layer.Grid(), {
13

    
14
    /** Hashtable of default parameter key/value pairs 
15
     * @final @type Object */
16
    DEFAULT_PARAMS: { service: "WMS",
17
                      version: "1.1.1",
18
                      request: "GetMap",
19
                      styles: "",
20
                      exceptions: "application/vnd.ogc.se_inimage",
21
                      format: "image/jpeg"
22
                     },
23

    
24
    /** @type Boolean */
25
    isBaseLayer: null,
26

    
27
    /**
28
    * @constructor
29
    *
30
    * @param {String} name
31
    * @param {String} url
32
    * @param {Object} params
33
    * @param {Object} options Hashtable of extra options to tag onto the layer
34
    */
35
    initialize: function(name, url, params, options) {
36
        var newArguments = new Array();
37
        if (arguments.length > 0) {
38
            //uppercase params
39
            params = OpenLayers.Util.upperCaseObject(params);
40
            newArguments.push(name, url, params, options);
41
        }
42
        OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
43

    
44
        if (arguments.length > 0) {
45
            OpenLayers.Util.applyDefaults(
46
                           this.params, 
47
                           OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS)
48
                           );
49
        }
50

    
51
        // if the layer is transparent, it will be an overlay        
52
        this.isBaseLayer = ((this.params.TRANSPARENT != "true") && 
53
                            (this.params.TRANSPARENT != true));
54
    },    
55

    
56
    /**
57
     * 
58
     */
59
    destroy: function() {
60
        // for now, nothing special to do here. 
61
        OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments);  
62
    },
63

    
64
    
65
    /**
66
     * @param {Object} obj
67
     * 
68
     * @returns An exact clone of this OpenLayers.Layer.WMS
69
     * @type OpenLayers.Layer.WMS
70
     */
71
    clone: function (obj) {
72
        
73
        if (obj == null) {
74
            obj = new OpenLayers.Layer.WMS(this.name,
75
                                           this.url,
76
                                           this.params,
77
                                           this.options);
78
        }
79

    
80
        //get all additions from superclasses
81
        obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
82

    
83
        // copy/set any non-init, non-simple values here
84

    
85
        return obj;
86
    },    
87
    
88
    /**
89
     * @param {OpenLayers.Bounds} bounds
90
     * 
91
     * @returns A string with the layer's url and parameters and also the 
92
     *           passed-in bounds and appropriate tile size specified as 
93
     *           parameters
94
     * @type String
95
     */
96
    getURL: function (bounds) {
97
        return this.getFullRequestString(
98
                     {BBOX:bounds.toBBOX(),
99
                      WIDTH:this.tileSize.w,
100
                      HEIGHT:this.tileSize.h});
101
    },
102

    
103
    /**
104
    * addTile creates a tile, initializes it, and 
105
    * adds it to the layer div. 
106
    *
107
    * @param {OpenLayers.Bounds} bounds
108
    *
109
    * @returns The added OpenLayers.Tile.Image
110
    * @type OpenLayers.Tile.Image
111
    */
112
    addTile:function(bounds,position) {
113
        url = this.getURL(bounds);
114
        return new OpenLayers.Tile.Image(this, position, bounds, 
115
                                             url, this.tileSize);
116
    },
117

    
118
    /**
119
     * Catch changeParams and uppercase the new params to be merged in
120
     *  before calling changeParams on the super class.
121
     * 
122
     * Once params have been changed, we will need to re-init our tiles
123
     * 
124
     * @param {Object} newParams Hashtable of new params to use
125
     */
126
    mergeNewParams:function(newParams) {
127
        var upperParams = OpenLayers.Util.upperCaseObject(newParams);
128
        var newArguments = [upperParams];
129
        OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this, 
130
                                                             newArguments);
131

    
132
        if (this.map != null) {
133
            this._initTiles();
134
        }
135
    },
136

    
137
    /** combine the layer's url with its params and these newParams. 
138
    *   
139
    *    Add the SRS parameter from getProjection() -- this is probably
140
    *     more eloquently done via a setProjection() method, but this 
141
    *     works for now and always.
142
    * 
143
    * @param {Object} newParams
144
    * 
145
    * @type String
146
    */
147
    getFullRequestString:function(newParams) {
148
        var projection = this.map.getProjection();
149
        this.params.SRS = (projection == "none") ? null : projection;
150

    
151
        return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(
152
                                                    this, arguments);
153
    },
154
    
155
    /** @final @type String */
156
    CLASS_NAME: "OpenLayers.Layer.WMS"
157
});
(12-12/14)