UNPKG

maplair

Version:

JavaScript library for mobile-friendly interactive maps

68 lines (67 loc) • 2.13 kB
import Browser_default from "../../core/Browser.js"; import { Bounds } from "../../geometry/Bounds.js"; import { EPSG4326 } from "../../geo/crs/EPSG4326.js"; import { TileLayer } from "./TileLayer.js"; //#region src/layer/tile/WMSTileLayer.js var WMSTileLayer = class WMSTileLayer extends TileLayer { static { this.prototype.defaultWmsParams = { service: "WMS", request: "GetMap", layers: "", styles: "", format: "image/jpeg", transparent: false, version: "1.1.1" }; this.setDefaultOptions({ crs: null, uppercase: false }); } constructor(url, options) { super(url, options); const wmsParams = { ...this.defaultWmsParams }; for (const [key, value] of Object.entries(options)) if (!(key in WMSTileLayer.prototype.options)) wmsParams[key] = value; const realRetina = this.options.detectRetina && Browser_default.retina ? 2 : 1; const tileSize = this.getTileSize(); wmsParams.width = tileSize.x * realRetina; wmsParams.height = tileSize.y * realRetina; this.wmsParams = wmsParams; this.callInitHooks(WMSTileLayer); } onAdd(map) { this._crs = this.options.crs ?? map.options.crs; this._wmsVersion = parseFloat(this.wmsParams.version); const projectionKey = this._wmsVersion >= 1.3 ? "crs" : "srs"; this.wmsParams[projectionKey] = this._crs.code; super.onAdd(map); } getTileUrl(coords) { const tileBounds = this._tileCoordsToNwSe(coords), crs = this._crs, bounds = new Bounds(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(","); const url = new URL(super.getTileUrl(coords)); for (const [k, v] of Object.entries({ ...this.wmsParams, bbox })) url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, v); return url.toString(); } setParams(params, noRedraw) { Object.assign(this.wmsParams, params); if (!noRedraw) this.redraw(); return this; } }; //#endregion export { WMSTileLayer }; //# sourceMappingURL=WMSTileLayer.js.map