From 1923fe5b6ecdf185038de0ee55da8a9ca1b1e37a Mon Sep 17 00:00:00 2001 From: Tariq Soliman Date: Wed, 27 Mar 2024 12:13:07 -0700 Subject: [PATCH] #518 time={starttime} in a WMS URL is filled with endtime (#522) * ts-518 Inject time tile params better * #518 Stop wms layer options for override wms parameters --- .../Layers_/leaflet-tilelayer-middleware.js | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/essence/Basics/Layers_/leaflet-tilelayer-middleware.js b/src/essence/Basics/Layers_/leaflet-tilelayer-middleware.js index 51975941..f8cc407c 100644 --- a/src/essence/Basics/Layers_/leaflet-tilelayer-middleware.js +++ b/src/essence/Basics/Layers_/leaflet-tilelayer-middleware.js @@ -25,8 +25,25 @@ var colorFilterExtension = { .replace(/{starttime}/g, this.options.starttime) .replace(/{endtime}/g, this.options.endtime) if (this.options.time && this.options.tileFormat === 'tms') { - url += `?starttime=${this.options.starttime}&time=${this.options.endtime}` - if (this.options.compositeTile === true) url += `&composite=true` + let paramDelimiter = '?' + let urlParams = false + if (url.indexOf('?') !== -1) { + urlParams = new URLSearchParams(url.split('?')[1]) + paramDelimiter = '&' + } + + if (urlParams == false || !urlParams.has('starttime')) { + url += `${paramDelimiter}starttime=${this.options.starttime}` + paramDelimiter = '&' + } + if (urlParams == false || !urlParams.has('time')) { + url += `${paramDelimiter}time=${this.options.endtime}` + paramDelimiter = '&' + } + if (urlParams == false || !urlParams.has('composite')) { + if (this.options.compositeTile === true) + url += `${paramDelimiter}composite=true` + } } return url }, @@ -172,15 +189,15 @@ var wmsExtension = { uppercase: true, }, - initialize: function (url, options) { + initialize: function (url, options, wmsOptions) { this._url = url var wmsParams = L.extend({}, this.defaultWmsParams) // all keys that are not TileLayer options go to WMS params - for (var i in options) { + for (var i in wmsOptions) { if (!(i in this.extensionOptions)) { - wmsParams[i] = options[i] + wmsParams[i] = wmsOptions[i] } } options = L.setOptions(this, options) @@ -293,10 +310,11 @@ L.tileLayer.colorFilter = function (url, options) { `WARNING: WMS layer has no "layers" parameter in the url - ${url}` ) - return new L.TileLayer.WMSColorFilter(urlBaseString, { - ...options, - ...wmsOptions, - }) + return new L.TileLayer.WMSColorFilter( + urlBaseString, + options, + wmsOptions + ) } url = url.replace(/{t}/g, '_time_')