Support access tokens for Maplibre (mvt) tile urls
This commit is contained in:
parent
ad68d0023b
commit
c585b5aa62
1 changed files with 20 additions and 2 deletions
|
|
@ -245,10 +245,14 @@ BR.LayersConfig = L.Class.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
createMvtLayer: function (props, options) {
|
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'),
|
// url is key to style in local layers bundle (file name without '.json'),
|
||||||
// suggested file naming convention: `<layer id>-style.json`
|
// suggested file naming convention: `<layer id>-style.json`
|
||||||
options.style = BR.layerIndex[props.url];
|
options.style = BR.layerIndex[styleId];
|
||||||
|
|
||||||
|
this._replaceMvtTileKey(options.style);
|
||||||
} else {
|
} else {
|
||||||
// external URL to style.json
|
// external URL to style.json
|
||||||
options.style = props.url;
|
options.style = props.url;
|
||||||
|
|
@ -257,6 +261,20 @@ BR.LayersConfig = L.Class.extend({
|
||||||
return BR.maplibreGlLazyLoader(options);
|
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) {
|
createLayer: function (layerData) {
|
||||||
var props = layerData.properties;
|
var props = layerData.properties;
|
||||||
var url = props.url;
|
var url = props.url;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue