-
Notifications
You must be signed in to change notification settings - Fork 0
/
NonTiledLayer.WMS.js
68 lines (51 loc) · 1.71 KB
/
NonTiledLayer.WMS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* L.NonTiledLayer.WMS is used for putting WMS non tiled layers on the map.
*/
L.NonTiledLayer.WMS = L.NonTiledLayer.extend({
defaultWmsParams: {
service: 'WMS',
request: 'GetMap',
version: '1.1.1',
layers: '',
styles: '',
format: 'image/jpeg',
transparent: false
},
initialize: function (url, options) { // (String, Object)
this._wmsUrl = url;
var wmsParams = L.extend({}, this.defaultWmsParams);
// all keys that are not NonTiledLayer options go to WMS params
for (var i in options) {
if (!L.NonTiledLayer.prototype.options.hasOwnProperty(i)) {
wmsParams[i] = options[i];
}
}
this.wmsParams = wmsParams;
L.setOptions(this, options);
},
onAdd: function (map) {
var projectionKey = parseFloat(this.wmsParams.version) >= 1.3 ? 'crs' : 'srs';
this.wmsParams[projectionKey] = map.options.crs.code;
L.NonTiledLayer.prototype.onAdd.call(this, map);
},
getImageUrl: function (world1, world2, width, height) {
var wmsParams = this.wmsParams;
wmsParams.width = width;
wmsParams.height = height;
var crs = this._map.options.crs;
var p1 = crs.project(world1);
var p2 = crs.project(world2);
var url = this._wmsUrl + L.Util.getParamString(wmsParams, this._wmsUrl) + '&bbox=' + p1.x + ',' + p2.y + ',' + p2.x + ',' + p1.y;
return url;
},
setParams: function (params, noRedraw) {
L.extend(this.wmsParams, params);
if (!noRedraw) {
this.redraw();
}
return this;
}
});
L.nonTiledLayer.wms = function (url, options) {
return new L.NonTiledLayer.WMS(url, options);
};