diff --git a/js/LayersConfig.js b/js/LayersConfig.js index 35d4b1b..55a24cf 100644 --- a/js/LayersConfig.js +++ b/js/LayersConfig.js @@ -245,10 +245,14 @@ BR.LayersConfig = L.Class.extend({ }, createMvtLayer: function (props, options) { - if (props.url in BR.layerIndex) { + // remove key, only provided with local style to not add layer when not configured, see _getLayers + const styleId = props.url?.split('?')[0]; + if (styleId in BR.layerIndex) { // url is key to style in local layers bundle (file name without '.json'), // suggested file naming convention: `-style.json` - options.style = BR.layerIndex[props.url]; + options.style = BR.layerIndex[styleId]; + + this._replaceMvtTileKey(options.style); } else { // external URL to style.json options.style = props.url; @@ -257,6 +261,20 @@ BR.LayersConfig = L.Class.extend({ return BR.maplibreGlLazyLoader(options); }, + _replaceMvtTileKey: function (style) { + if (!style) return; + + for (const source of Object.values(style.sources)) { + const tiles = source.tiles; + for (const [i, url] of tiles?.entries()) { + var keyObj = this.getKeyName(url); + if (keyObj && BR.keys[keyObj.name]) { + tiles[i] = url.replace(`{${keyObj.urlVar}}`, BR.keys[keyObj.name]); + } + } + } + }, + createLayer: function (layerData) { var props = layerData.properties; var url = props.url;