From 0305b593fe7eb7adc4a34ccfac7445feccc18116 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Thu, 28 Nov 2013 01:45:28 +0200 Subject: [PATCH] clean up TileLayer.WMS --- src/layer/tile/GridLayer.js | 4 ++-- src/layer/tile/TileLayer.WMS.js | 42 +++++++++++++-------------------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/layer/tile/GridLayer.js b/src/layer/tile/GridLayer.js index 471db8b2..4b4457f5 100644 --- a/src/layer/tile/GridLayer.js +++ b/src/layer/tile/GridLayer.js @@ -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); }, diff --git a/src/layer/tile/TileLayer.WMS.js b/src/layer/tile/TileLayer.WMS.js index 7c895088..54200e11 100644 --- a/src/layer/tile/TileLayer.WMS.js +++ b/src/layer/tile/TileLayer.WMS.js @@ -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; },