commit b3d417164256c2d42507a659787744419fdb7bbb
parent 86c7f840199c43307116de69e6a0906b39d58a3f
Author: Sergej Orlov <wladimirych@gmail.com>
Date: Tue, 28 Oct 2025 19:16:12 +0100
bing[GB Topo]: request new session key when showing layer
Fixes: #1354
Diffstat:
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/lib/leaflet.layer.bing/index.js b/src/lib/leaflet.layer.bing/index.js
@@ -2,6 +2,8 @@ import L from 'leaflet';
import {fetch} from '~/lib/xhr-promise';
+import {urlViaCorsProxy} from '../CORSProxy';
+
function tile2quad(x, y, z) {
let quad = '';
for (let i = z; i > 0; i--) {
@@ -70,11 +72,16 @@ const BingSatLayer = BingBaseLayerWithDynamicUrl.extend({
});
const BingOrdnanceSurveyLayer = BingBaseLayerWithDynamicUrl.extend({
- options: {
- credentials: 'AuVxPHY_dRlWTHjKmQ-pjqsKKN3RQ8KjF7sPqpFzS-4A-W1-7JxLorxHoJxpLz8o',
+ getSessionKey: async function () {
+ const xhr = await fetch(urlViaCorsProxy('https://www.bing.com/maps/'), {timeout: 5000});
+ const match = xhr.responseText.match(/"sessionKey"\s*:\s*"([^"]+)"/u);
+ if (!match || !match[1]) {
+ throw new Error('Bing session key not found');
+ }
+ return match[1];
},
- getLayerUrl: async function () {
+ getLayerUrlWithoutKey: async function () {
const xhr = await fetch('https://www.bing.com/maps/style?styleid=ordnancesurvey', {
responseType: 'json',
headers: [['accept-language', 'en-GB']],
@@ -82,6 +89,11 @@ const BingOrdnanceSurveyLayer = BingBaseLayerWithDynamicUrl.extend({
});
return xhr.response['sources']['osMaps1']['tiles'][0].replace(/^raster/u, 'https');
},
+
+ getLayerUrl: async function () {
+ const [url, key] = await Promise.all([this.getLayerUrlWithoutKey(), this.getSessionKey()]);
+ return url.replace('{credentials}', key);
+ },
});
// eslint-disable-next-line import/no-unused-modules