Code coverage report for src/layer/tile/TileLayer.WMS.js

Statements: 9.09% (2 / 22)      Branches: 0% (0 / 12)      Functions: 0% (0 / 5)      Lines: 9.09% (2 / 22)     

All files » src/layer/tile/ » TileLayer.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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84        1                                                                                                                                                       1      
/*
 * L.TileLayer.WMS is used for putting WMS tile layers on the map.
 */
 
L.TileLayer.WMS = L.TileLayer.extend({
 
	defaultWmsParams: {
		service: 'WMS',
		request: 'GetMap',
		version: '1.1.1',
		layers: '',
		styles: '',
		format: 'image/jpeg',
		transparent: false
	},
 
	initialize: function (url, options) { // (String, Object)
 
		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;
		}
 
		for (var i in options) {
			// all keys that are not TileLayer options go to WMS params
			if (!this.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.TileLayer.prototype.onAdd.call(this, map);
	},
 
	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)),
 
		    nw = crs.project(map.unproject(nwPoint, zoom)),
		    se = crs.project(map.unproject(sePoint, zoom)),
 
		    bbox = [nw.x, se.y, se.x, nw.y].join(','),
 
		    url = L.Util.template(this._url, {s: this._getSubdomain(tilePoint)});
 
		return url + L.Util.getParamString(this.wmsParams, url) + "&bbox=" + bbox;
	},
 
	setParams: function (params, noRedraw) {
 
		L.extend(this.wmsParams, params);
 
		if (!noRedraw) {
			this.redraw();
		}
 
		return this;
	}
});
 
L.tileLayer.wms = function (url, options) {
	return new L.TileLayer.WMS(url, options);
};