clean up TileLayer.WMS

This commit is contained in:
Vladimir Agafonkin 2013-11-28 01:45:28 +02:00
parent 8c9a513857
commit 0305b593fe
2 changed files with 19 additions and 27 deletions

View File

@ -314,8 +314,8 @@ L.GridLayer = L.Class.extend({
nwPoint = coords.multiplyBy(tileSize),
sePoint = nwPoint.add([tileSize, tileSize]),
nw = this._map.unproject(nwPoint),
se = this._map.unproject(sePoint);
nw = this._map.unproject(nwPoint, coords.z),
se = this._map.unproject(sePoint, coords.z);
return new L.LatLngBounds(nw, se);
},

View File

@ -1,5 +1,5 @@
/*
* L.TileLayer.WMS is used for putting WMS tile layers on the map.
* L.TileLayer.WMS is used for WMS tile layers.
*/
L.TileLayer.WMS = L.TileLayer.extend({
@ -14,29 +14,25 @@ L.TileLayer.WMS = L.TileLayer.extend({
transparent: false
},
initialize: function (url, options) { // (String, Object)
initialize: function (url, options) {
this._url = url;
var wmsParams = L.extend({}, this.defaultWmsParams),
tileSize = options.tileSize || this.options.tileSize;
if (options.detectRetina && L.Browser.retina) {
wmsParams.width = wmsParams.height = tileSize * 2;
} else {
wmsParams.width = wmsParams.height = tileSize;
}
var wmsParams = L.extend({}, this.defaultWmsParams);
// all keys that are not TileLayer options go to WMS params
for (var i in options) {
// all keys that are not TileLayer options go to WMS params
if (!this.options.hasOwnProperty(i) && i !== 'crs') {
wmsParams[i] = options[i];
}
}
this.wmsParams = wmsParams;
options = L.setOptions(this, options);
L.setOptions(this, options);
wmsParams.width = wmsParams.height =
options.tileSize * (options.detectRetina && L.Browser.retina ? 2 : 1);
this.wmsParams = wmsParams;
},
onAdd: function (map) {
@ -51,21 +47,17 @@ L.TileLayer.WMS = L.TileLayer.extend({
L.TileLayer.prototype.onAdd.call(this, map);
},
getTileUrl: function (tilePoint) { // (Point, Number) -> String
getTileUrl: function (coords) {
var map = this._map,
tileSize = this.options.tileSize,
var tileBounds = this._tileCoordsToBounds(coords),
nw = this._crs.project(tileBounds.getNorthWest()),
se = this._crs.project(tileBounds.getSouthEast()),
nwPoint = tilePoint.multiplyBy(tileSize),
sePoint = nwPoint.add([tileSize, tileSize]),
bbox = (this._wmsVersion >= 1.3 && this._crs === L.CRS.EPSG4326 ?
[se.y, nw.x, nw.y, se.x] :
[nw.x, se.y, se.x, nw.y]).join(','),
nw = this._crs.project(map.unproject(nwPoint, tilePoint.z)),
se = this._crs.project(map.unproject(sePoint, tilePoint.z)),
bbox = this._wmsVersion >= 1.3 && this._crs === L.CRS.EPSG4326 ?
[se.y, nw.x, nw.y, se.x].join(',') :
[nw.x, se.y, se.x, nw.y].join(','),
url = L.Util.template(this._url, {s: this._getSubdomain(tilePoint)});
url = L.Util.template(this._url, {s: this._getSubdomain(coords)});
return url + L.Util.getParamString(this.wmsParams, url, true) + '&BBOX=' + bbox;
},