diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a97f1c9..5f28b9ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,9 +69,10 @@ Icon API was improved to be more flexible, but one of the changes is backwards-i * Improved `on` and `off` methods to also accept `(eventHash[, context])`, as well as multiple space-separated events (by [@Guiswa](https://github.com/Guiswa)). [#770](https://github.com/CloudMade/Leaflet/pull/770) * Improved `off` to remove all listeners of the event if no function was specified (by [@Guiswa](https://github.com/Guiswa)). [#770](https://github.com/CloudMade/Leaflet/pull/770) [#691](https://github.com/CloudMade/Leaflet/issues/691) * Added `TileLayer` `redraw` method for re-requesting tiles (by [@greeninfo](https://github.com/greeninfo)). [#719](https://github.com/CloudMade/Leaflet/issues/719) - * Added `TileLayer.WMS` `setParams` method for setting WMS parameters at runtime (by [@greeninfo](https://github.com/greeninfo)). [#719](https://github.com/CloudMade/Leaflet/issues/719) * Added `TileLayer` `setUrl` method for dynamically changing the tile URL template. * Added `bringToFront` and `bringToBack` methods to `TileLayer` and vector layers. [#185](https://github.com/CloudMade/Leaflet/issues/185) [#505](https://github.com/CloudMade/Leaflet/issues/505) + * Added `TileLayer.WMS` `setParams` method for setting WMS parameters at runtime (by [@greeninfo](https://github.com/greeninfo)). [#719](https://github.com/CloudMade/Leaflet/issues/719) + * Added `TileLayer.WMS` subdomain support (`{s}` in the url) (by [@greeninfo](https://github.com/greeninfo)). [#735](https://github.com/CloudMade/Leaflet/issues/735) * Added `originalEvent` property to `MouseEvent` (by [@k4](https://github.com/k4)). [#521](https://github.com/CloudMade/Leaflet/pull/521) * Added `containerPoint` property to `MouseEvent`. [#413](https://github.com/CloudMade/Leaflet/issues/413) * Added `contextmenu` event to vector layers (by [@ErrorProne](https://github.com/ErrorProne)). [#500](https://github.com/CloudMade/Leaflet/pull/500) diff --git a/src/layer/tile/TileLayer.WMS.js b/src/layer/tile/TileLayer.WMS.js index f6990289..756e123e 100644 --- a/src/layer/tile/TileLayer.WMS.js +++ b/src/layer/tile/TileLayer.WMS.js @@ -1,4 +1,5 @@ L.TileLayer.WMS = L.TileLayer.extend({ + defaultWmsParams: { service: 'WMS', request: 'GetMap', @@ -10,6 +11,7 @@ L.TileLayer.WMS = L.TileLayer.extend({ }, initialize: function (url, options) { // (String, Object) + this._url = url; var wmsParams = L.Util.extend({}, this.defaultWmsParams); @@ -28,6 +30,7 @@ L.TileLayer.WMS = L.TileLayer.extend({ }, onAdd: function (map, insertAtTheBottom) { + var projectionKey = parseFloat(this.wmsParams.version) >= 1.3 ? 'crs' : 'srs'; this.wmsParams[projectionKey] = map.options.crs.code; @@ -35,26 +38,26 @@ L.TileLayer.WMS = L.TileLayer.extend({ }, getTileUrl: function (tilePoint, zoom) { // (Point, Number) -> String + var map = this._map, crs = map.options.crs, - tileSize = this.options.tileSize, - + nwPoint = tilePoint.multiplyBy(tileSize), sePoint = nwPoint.add(new L.Point(tileSize, tileSize)), - nwMap = map.unproject(nwPoint, zoom), - seMap = map.unproject(sePoint, zoom), + nw = crs.project(map.unproject(nwPoint, zoom)), + se = crs.project(map.unproject(sePoint, zoom)), - nw = crs.project(nwMap), - se = crs.project(seMap), + bbox = [nw.x, se.y, se.x, nw.y].join(','), - bbox = [nw.x, se.y, se.x, nw.y].join(','); + url = L.Util.template(this._url, {s: this._getSubdomain(tilePoint)}); - return this._url + L.Util.getParamString(this.wmsParams) + "&bbox=" + bbox; + return url + L.Util.getParamString(this.wmsParams) + "&bbox=" + bbox; }, setParams: function (params, noRedraw) { + L.Util.extend(this.wmsParams, params); if (!noRedraw) { diff --git a/src/layer/tile/TileLayer.js b/src/layer/tile/TileLayer.js index af3ad857..343738cd 100644 --- a/src/layer/tile/TileLayer.js +++ b/src/layer/tile/TileLayer.js @@ -346,18 +346,19 @@ L.TileLayer = L.Class.extend({ // image-specific code (override to implement e.g. Canvas or SVG tile layer) getTileUrl: function (tilePoint, zoom) { - var subdomains = this.options.subdomains, - index = (tilePoint.x + tilePoint.y) % subdomains.length, - s = this.options.subdomains[index]; - return L.Util.template(this._url, L.Util.extend({ - s: s, + s: this._getSubdomain(tilePoint), z: this._getOffsetZoom(zoom), x: tilePoint.x, y: tilePoint.y }, this.options)); }, + _getSubdomain: function (tilePoint) { + var index = (tilePoint.x + tilePoint.y) % this.options.subdomains.length; + return this.options.subdomains[index]; + }, + _createTileProto: function () { var img = this._tileImg = L.DomUtil.create('img', 'leaflet-tile'); img.galleryimg = 'no';