diff --git a/css/adminSettings.css b/css/adminSettings.css
index fa69871e..e31b1279 100644
--- a/css/adminSettings.css
+++ b/css/adminSettings.css
@@ -4,7 +4,8 @@
#graphhopperURL,
#graphhopperAPIKEY,
#mapboxAPIKEY,
-#maplibreStreetStyleURL
+#maplibreStreetStyleURL,
+#maplibreStreetStyleAuth
{
width: 400px;
}
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index bd65c91f..3e3aa390 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -122,7 +122,8 @@ class PageController extends Controller {
'osrmCarURL',
'osrmFootURL',
'graphhopperURL',
- 'maplibreStreetStyleURL'
+ 'maplibreStreetStyleURL',
+ 'maplibreStreetStyleAuth'
];
foreach ($urlKeys as $key) {
$url = $this->config->getAppValue('maps', $key);
diff --git a/lib/Controller/PublicUtilsController.php b/lib/Controller/PublicUtilsController.php
index 2c5bc78e..be5319e5 100644
--- a/lib/Controller/PublicUtilsController.php
+++ b/lib/Controller/PublicUtilsController.php
@@ -210,6 +210,7 @@ class PublicUtilsController extends PublicPageController {
'graphhopperAPIKEY',
'mapboxAPIKEY',
'maplibreStreetStyleURL',
+ 'maplibreStreetStyleAuth',
'graphhopperURL'
];
foreach ($settingsKeys as $k) {
diff --git a/lib/Controller/UtilsController.php b/lib/Controller/UtilsController.php
index 4a7260a5..c7285acb 100644
--- a/lib/Controller/UtilsController.php
+++ b/lib/Controller/UtilsController.php
@@ -151,6 +151,7 @@ class UtilsController extends Controller {
'graphhopperAPIKEY',
'mapboxAPIKEY',
'maplibreStreetStyleURL',
+ 'maplibreStreetStyleAuth',
'graphhopperURL'
];
foreach ($settingsKeys as $k) {
@@ -175,6 +176,7 @@ class UtilsController extends Controller {
'graphhopperAPIKEY',
'mapboxAPIKEY',
'maplibreStreetStyleURL',
+ 'maplibreStreetStyleAuth',
'graphhopperURL'
];
foreach ($values as $k=>$v) {
diff --git a/lib/Settings/AdminSettings.php b/lib/Settings/AdminSettings.php
index d7302cc0..f4410c82 100644
--- a/lib/Settings/AdminSettings.php
+++ b/lib/Settings/AdminSettings.php
@@ -47,6 +47,7 @@ class AdminSettings implements ISettings {
'graphhopperAPIKEY',
'mapboxAPIKEY',
'maplibreStreetStyleURL',
+ 'maplibreStreetStyleAuth',
'graphhopperURL'
];
$parameters = [];
diff --git a/src/adminSettings.js b/src/adminSettings.js
index 53101c76..88d2fffd 100644
--- a/src/adminSettings.js
+++ b/src/adminSettings.js
@@ -39,10 +39,12 @@ $(document).ready(function() {
'input#graphhopperAPIKEY, ' +
'#osrmDEMO, ' +
'input#mapboxAPIKEY, ' +
- 'input#maplibreStreetStyleURL', function(e) {
- var value = $(this).val();
- setMapsRoutingSettings($(this).attr('id'), value);
- });
+ 'input#maplibreStreetStyleURL, ' +
+ 'input#maplibreStreetStyleAuth',
+ function(e) {
+ var value = $(this).val();
+ setMapsRoutingSettings($(this).attr('id'), value);
+ });
$('body').on('change', '#osrmDEMO', function(e) {
var value = $(this).is(':checked') ? '1' : '0';
setMapsRoutingSettings($(this).attr('id'), value);
diff --git a/src/components/Map.vue b/src/components/Map.vue
index 9df681ec..12a29d5f 100644
--- a/src/components/Map.vue
+++ b/src/components/Map.vue
@@ -175,6 +175,7 @@ import 'mapbox-gl/dist/mapbox-gl'
import 'mapbox-gl/dist/mapbox-gl.css'
import 'mapbox-gl-leaflet/leaflet-mapbox-gl'
import '@maplibre/maplibre-gl-leaflet'
+import ResourceType from 'maplibre-gl'
import {
baseLayersByName,
overlayLayersByName,
@@ -784,18 +785,37 @@ export default {
if ((gl !== null) &&
('maplibreStreetStyleURL' in this.optionValues && this.optionValues.maplibreStreetStyleURL !== '')) {
+ let token = null
+ if ('maplibreStreetStyleAuth' in this.optionValues && this.optionValues.maplibreStreetStyleAuth !== '') {
+ token = this.optionValues.maplibreStreetStyleAuth
+ }
+
// wrapper to make tile layer component correctly pass arguments
L.myMaplibreGL = (url, options) => {
+ if (token !== null) {
+ token = 'Basic ' + btoa(token)
+ const oldTransform = options.transformRequest
+ options.transformRequest = (url, resourceType) => {
+ const param = oldTransform?.() || {}
+ param.url = param.url || url
+ if (resourceType === ResourceType.Tile) {
+ param.type = 'arrayBuffer'
+ }
+ param.headers = param.headers || {}
+ param.headers.Authorization = token
+ return param
+ }
+ }
return new L.maplibreGL(options)
}
this.allBaseLayers = {}
Object.keys(baseLayersByName).forEach(id => {
if (id === 'Open Street Map') {
- let layer = Object.assign({}, baseLayersByName[id]);
+ const layer = Object.assign({}, baseLayersByName[id])
delete layer.url
layer.tileLayerClass = L.myMaplibreGL
- layer.options = Object.assign({}, layer.options);
+ layer.options = Object.assign({}, layer.options)
layer.options.style = this.optionValues.maplibreStreetStyleURL
layer.options.minZoom = 0
layer.options.maxZoom = 22
diff --git a/templates/adminSettings.php b/templates/adminSettings.php
index 196fab3a..0f1d8a2f 100644
--- a/templates/adminSettings.php
+++ b/templates/adminSettings.php
@@ -48,10 +48,12 @@ if (!isset($_['osrmDEMO']) || $_['osrmDEMO'] === '1') {
t('Set the URL of style.json for OpenStreetMap Vector Tiles with MapLibre-GL-JS')); ?>
+t('Set the URL and Basic Authorization of style.json for OpenStreetMap Vector Tiles with MapLibre-GL-JS.')); ?>
t('Leave empty to disable.')); ?>