|
|
import {TileLayer} from './TileLayer';
|
|
|
import {extend, setOptions, getParamString} from '../../core/Util';
|
|
|
import Browser from '../../core/Browser';
|
|
|
import {EPSG4326} from '../../geo/crs/CRS.EPSG4326';
|
|
|
import {toBounds} from '../../geometry/Bounds';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export var TileLayerWMS = TileLayer.extend({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defaultWmsParams: {
|
|
|
service: 'WMS',
|
|
|
request: 'GetMap',
|
|
|
|
|
|
|
|
|
|
|
|
layers: '',
|
|
|
|
|
|
|
|
|
|
|
|
styles: '',
|
|
|
|
|
|
|
|
|
|
|
|
format: 'image/jpeg',
|
|
|
|
|
|
|
|
|
|
|
|
transparent: false,
|
|
|
|
|
|
|
|
|
|
|
|
version: '1.1.1'
|
|
|
},
|
|
|
|
|
|
options: {
|
|
|
|
|
|
|
|
|
|
|
|
crs: null,
|
|
|
|
|
|
|
|
|
|
|
|
uppercase: false
|
|
|
},
|
|
|
|
|
|
initialize: function (url, options) {
|
|
|
|
|
|
this._url = url;
|
|
|
|
|
|
var wmsParams = extend({}, this.defaultWmsParams);
|
|
|
|
|
|
|
|
|
for (var i in options) {
|
|
|
if (!(i in this.options)) {
|
|
|
wmsParams[i] = options[i];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
options = setOptions(this, options);
|
|
|
|
|
|
var realRetina = options.detectRetina && Browser.retina ? 2 : 1;
|
|
|
var tileSize = this.getTileSize();
|
|
|
wmsParams.width = tileSize.x * realRetina;
|
|
|
wmsParams.height = tileSize.y * realRetina;
|
|
|
|
|
|
this.wmsParams = wmsParams;
|
|
|
},
|
|
|
|
|
|
onAdd: function (map) {
|
|
|
|
|
|
this._crs = this.options.crs || map.options.crs;
|
|
|
this._wmsVersion = parseFloat(this.wmsParams.version);
|
|
|
|
|
|
var projectionKey = this._wmsVersion >= 1.3 ? 'crs' : 'srs';
|
|
|
this.wmsParams[projectionKey] = this._crs.code;
|
|
|
|
|
|
TileLayer.prototype.onAdd.call(this, map);
|
|
|
},
|
|
|
|
|
|
getTileUrl: function (coords) {
|
|
|
|
|
|
var tileBounds = this._tileCoordsToNwSe(coords),
|
|
|
crs = this._crs,
|
|
|
bounds = toBounds(crs.project(tileBounds[0]), crs.project(tileBounds[1])),
|
|
|
min = bounds.min,
|
|
|
max = bounds.max,
|
|
|
bbox = (this._wmsVersion >= 1.3 && this._crs === EPSG4326 ?
|
|
|
[min.y, min.x, max.y, max.x] :
|
|
|
[min.x, min.y, max.x, max.y]).join(','),
|
|
|
url = TileLayer.prototype.getTileUrl.call(this, coords);
|
|
|
return url +
|
|
|
getParamString(this.wmsParams, url, this.options.uppercase) +
|
|
|
(this.options.uppercase ? '&BBOX=' : '&bbox=') + bbox;
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
setParams: function (params, noRedraw) {
|
|
|
|
|
|
extend(this.wmsParams, params);
|
|
|
|
|
|
if (!noRedraw) {
|
|
|
this.redraw();
|
|
|
}
|
|
|
|
|
|
return this;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function tileLayerWMS(url, options) {
|
|
|
return new TileLayerWMS(url, options);
|
|
|
}
|
|
|
|