add subdomains to WMS, closes #735

This commit is contained in:
Vladimir Agafonkin 2012-07-10 12:00:13 +03:00
parent 19974a84a1
commit cc60eb81c7
3 changed files with 19 additions and 14 deletions

View File

@ -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 `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) * 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` `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 `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 `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 `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 `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) * Added `contextmenu` event to vector layers (by [@ErrorProne](https://github.com/ErrorProne)). [#500](https://github.com/CloudMade/Leaflet/pull/500)

View File

@ -1,4 +1,5 @@
L.TileLayer.WMS = L.TileLayer.extend({ L.TileLayer.WMS = L.TileLayer.extend({
defaultWmsParams: { defaultWmsParams: {
service: 'WMS', service: 'WMS',
request: 'GetMap', request: 'GetMap',
@ -10,6 +11,7 @@ L.TileLayer.WMS = L.TileLayer.extend({
}, },
initialize: function (url, options) { // (String, Object) initialize: function (url, options) { // (String, Object)
this._url = url; this._url = url;
var wmsParams = L.Util.extend({}, this.defaultWmsParams); var wmsParams = L.Util.extend({}, this.defaultWmsParams);
@ -28,6 +30,7 @@ L.TileLayer.WMS = L.TileLayer.extend({
}, },
onAdd: function (map, insertAtTheBottom) { onAdd: function (map, insertAtTheBottom) {
var projectionKey = parseFloat(this.wmsParams.version) >= 1.3 ? 'crs' : 'srs'; var projectionKey = parseFloat(this.wmsParams.version) >= 1.3 ? 'crs' : 'srs';
this.wmsParams[projectionKey] = map.options.crs.code; this.wmsParams[projectionKey] = map.options.crs.code;
@ -35,26 +38,26 @@ L.TileLayer.WMS = L.TileLayer.extend({
}, },
getTileUrl: function (tilePoint, zoom) { // (Point, Number) -> String getTileUrl: function (tilePoint, zoom) { // (Point, Number) -> String
var map = this._map, var map = this._map,
crs = map.options.crs, crs = map.options.crs,
tileSize = this.options.tileSize, tileSize = this.options.tileSize,
nwPoint = tilePoint.multiplyBy(tileSize), nwPoint = tilePoint.multiplyBy(tileSize),
sePoint = nwPoint.add(new L.Point(tileSize, tileSize)), sePoint = nwPoint.add(new L.Point(tileSize, tileSize)),
nwMap = map.unproject(nwPoint, zoom), nw = crs.project(map.unproject(nwPoint, zoom)),
seMap = map.unproject(sePoint, zoom), se = crs.project(map.unproject(sePoint, zoom)),
nw = crs.project(nwMap), bbox = [nw.x, se.y, se.x, nw.y].join(','),
se = crs.project(seMap),
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) { setParams: function (params, noRedraw) {
L.Util.extend(this.wmsParams, params); L.Util.extend(this.wmsParams, params);
if (!noRedraw) { if (!noRedraw) {

View File

@ -346,18 +346,19 @@ L.TileLayer = L.Class.extend({
// image-specific code (override to implement e.g. Canvas or SVG tile layer) // image-specific code (override to implement e.g. Canvas or SVG tile layer)
getTileUrl: function (tilePoint, zoom) { 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({ return L.Util.template(this._url, L.Util.extend({
s: s, s: this._getSubdomain(tilePoint),
z: this._getOffsetZoom(zoom), z: this._getOffsetZoom(zoom),
x: tilePoint.x, x: tilePoint.x,
y: tilePoint.y y: tilePoint.y
}, this.options)); }, this.options));
}, },
_getSubdomain: function (tilePoint) {
var index = (tilePoint.x + tilePoint.y) % this.options.subdomains.length;
return this.options.subdomains[index];
},
_createTileProto: function () { _createTileProto: function () {
var img = this._tileImg = L.DomUtil.create('img', 'leaflet-tile'); var img = this._tileImg = L.DomUtil.create('img', 'leaflet-tile');
img.galleryimg = 'no'; img.galleryimg = 'no';