From 4d1ba63e545a6bf5aa6766158f5064966c110364 Mon Sep 17 00:00:00 2001 From: e-halinen <54105602+e-halinen@users.noreply.github.com> Date: Wed, 5 Mar 2025 15:59:01 +0200 Subject: [PATCH 1/3] AB#38162: Allow full replacement of the source URL --- index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 94e79e6..5c83f89 100644 --- a/index.js +++ b/index.js @@ -253,8 +253,17 @@ function replaceInStyle(style, options) { forEach(values, (value) => { if (value.replacement) { - const replaceableRegexp = new RegExp(value.default, "g"); - replacedStyle = replacedStyle.replace(replaceableRegexp, value.replacement); + if (Array.isArray(value.replacement)) { + /* Full replacement of a selected source URL. + This condition expects replacements like this: [fullReplacementUrl, fullReplacementTarget] in order to fully replace the source url instead of using RegExp */ + const parsedReplacedStyle = JSON.parse(replacedStyle); + const [fullReplacementUrl, fullReplacementTarget] = value.replacement; + parsedReplacedStyle.sources[fullReplacementTarget].url = fullReplacementUrl; + replacedStyle = JSON.stringify(parsedReplacedStyle); + } else { + const replaceableRegexp = new RegExp(value.default, "g"); + replacedStyle = replacedStyle.replace(replaceableRegexp, value.replacement); + } } }); From 10a6a540dac7952a1bc80362b5b802c56ff30d0f Mon Sep 17 00:00:00 2001 From: e-halinen <54105602+e-halinen@users.noreply.github.com> Date: Mon, 10 Mar 2025 15:37:15 +0200 Subject: [PATCH 2/3] AB#38162: Update documentation on source URL replacement --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f9fa3cc..b9ae752 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ import { generateStyle } from "hsl-map-style"; const style = generateStyle({ sourcesUrl: "https://cdn.digitransit.fi/", // <-- You can override the default sources URL. The default is https://api.digitransit.fi/ + // OR sourcesUrl: ["https://cdn.digitransit.fi/", "vector"], // <---- [{ HOST_URL }, { SOURCE_NAME }] Use this to replace the specified source URL as a whole instead of only the hostname glyphsUrl: "", // Possibility to overwrite fonts url, an empty string does nothing spriteUrl: "", // Possibility to overwrite sprite url queryParams: [ // It's possible to add query parameters to urls, for example apikeys. From a4f7964de0e65de3cf2b62892733248194b4dbf1 Mon Sep 17 00:00:00 2001 From: e-halinen <54105602+e-halinen@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:57:27 +0200 Subject: [PATCH 3/3] v1.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4dcebc4..21217ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hsl-map-style", - "version": "1.2.1", + "version": "1.2.2", "description": "", "main": "index.js", "bin": {