From f3894e026da861f92962087547707d1343d71261 Mon Sep 17 00:00:00 2001 From: "Matteo V." Date: Wed, 18 Sep 2024 16:55:13 +0200 Subject: [PATCH] Fix #10508 fix tileprovider crash when using {-y} (#10509) (#10555) --- .../components/map/cesium/plugins/TileProviderLayer.js | 7 +++++++ web/client/utils/TileProviderUtils.js | 2 +- web/client/utils/__tests__/TileProviderUtils-test.js | 9 +++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/web/client/components/map/cesium/plugins/TileProviderLayer.js b/web/client/components/map/cesium/plugins/TileProviderLayer.js index 5af82c0493..cdd0ddb7e0 100644 --- a/web/client/components/map/cesium/plugins/TileProviderLayer.js +++ b/web/client/components/map/cesium/plugins/TileProviderLayer.js @@ -55,6 +55,13 @@ export function template(str, data) { if (['x', 'y', 'z', 's'].includes(key)) { return textMatched; } + if (key === '-x') { + return "{reverseX}"; + } + if (key === '-y') { + return "{reverseY}"; + } + let value = data[key]; if (value === undefined) { diff --git a/web/client/utils/TileProviderUtils.js b/web/client/utils/TileProviderUtils.js index d1c18a916e..b60370b578 100644 --- a/web/client/utils/TileProviderUtils.js +++ b/web/client/utils/TileProviderUtils.js @@ -11,7 +11,7 @@ export function template(str = "", data = {}) { return str.replace(/(\{(.*?)\})/g, function() { let st = arguments[0]; let key = arguments[2] ? arguments[2] : arguments[1]; - if (["x", "y", "z"].includes(key)) { + if (["x", "-x", "y", "-y", "z"].includes(key)) { return arguments[0]; } let value = data[key]; diff --git a/web/client/utils/__tests__/TileProviderUtils-test.js b/web/client/utils/__tests__/TileProviderUtils-test.js index 1e862af46b..dd300301ba 100644 --- a/web/client/utils/__tests__/TileProviderUtils-test.js +++ b/web/client/utils/__tests__/TileProviderUtils-test.js @@ -57,8 +57,13 @@ describe('Test the TileProviderUtils', () => { expect( template("https://test.com/6510a8722129af6954196fbb26dfadc/1.0.0/topowebb/default/3857/{z}/{y}/{x}.png", optArray)) .toEqual("https://test.com/6510a8722129af6954196fbb26dfadc/1.0.0/topowebb/default/3857/{z}/{y}/{x}.png"); - // expect().toBe(); + // test negative y (-y in template) + expect( + template("https://test.com/default/3857/{z}/{-y}/{x}.png", optArray)) + .toEqual("https://test.com/default/3857/{z}/{-y}/{x}.png"); + expect( + template("https://test.com/default/3857/{z}/{-y}/{-x}.png", optArray)) + .toEqual("https://test.com/default/3857/{z}/{-y}/{-x}.png"); }); - });