From f5401066de2ebc1272f88ae81fc905a0a2de0456 Mon Sep 17 00:00:00 2001 From: Jonathan Lurie Date: Tue, 5 Nov 2024 14:58:22 +0100 Subject: [PATCH] LOCAL now working and changelog --- CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- src/Map.ts | 5 ++--- src/tools.ts | 7 ++++++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61ab3ed..e420ec1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # MapTiler SDK Changelog +## 2.4.2 +### Bug Fixes +- The language switching is now more robust and preserves the original formatting from the style (`Map.setPrimareyLangage()`) + ## 2.4.1 ### Bug Fixes - The class `AJAXError` is now imported as part of the `maplibregl` namespace (CommonJS limitation from Maplibre GL JS) (https://github.com/maptiler/maptiler-sdk-js/pull/129) diff --git a/package-lock.json b/package-lock.json index 59674ff..2b2469f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@maptiler/sdk", - "version": "2.4.1", + "version": "2.4.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@maptiler/sdk", - "version": "2.3.1", + "version": "2.4.2", "license": "BSD-3-Clause", "dependencies": { "@maplibre/maplibre-gl-style-spec": "^20.3.1", diff --git a/package.json b/package.json index 3169cda..3c5e49d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@maptiler/sdk", - "version": "2.4.1", + "version": "2.4.2", "description": "The Javascript & TypeScript map SDK tailored for MapTiler Cloud", "module": "dist/maptiler-sdk.mjs", "types": "dist/maptiler-sdk.d.ts", diff --git a/src/Map.ts b/src/Map.ts index eda67dc..7485251 100644 --- a/src/Map.ts +++ b/src/Map.ts @@ -1010,7 +1010,7 @@ export class Map extends maplibregl.Map { let langStr = Language.LOCAL.flag; // will be overwritten below - let replacer: ExpressionSpecification | string = `{${langStr}}`; + let replacer: ExpressionSpecification | string = ["get", langStr]; if (languageNonStyle.flag === Language.VISITOR.flag) { langStr = getBrowserLanguage().flag; @@ -1062,7 +1062,7 @@ export class Map extends maplibregl.Map { // This is for using the regular names as {name} else if (languageNonStyle === Language.LOCAL) { langStr = Language.LOCAL.flag; - replacer = `{${langStr}}`; + replacer = ["get", langStr]; } // This section is for the regular language ISO codes @@ -1145,7 +1145,6 @@ export class Map extends maplibregl.Map { // The value of text-field is an object else { const newReplacer = changeFirstLanguage(textFieldLayoutProp, replacer); - console.log("New replacer:", newReplacer); this.setLayoutProperty(id, "text-field", newReplacer); } } diff --git a/src/tools.ts b/src/tools.ts index 7d7be3c..8f7be33 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -241,6 +241,12 @@ function isGetNameLanguage(subExpr: unknown): boolean { return true; } +/** + * In a text-field style property (as an object, not a string) the langages that are specified as + * ["get", "name:XX"] are replaced by the proved replacer (also an object). + * This replacement happened regardless of how deep in the object the flag is. + * Note that it does not replace the occurences of ["get", "name"] (local names) + */ export function changeFirstLanguage( origExpr: maplibregl.ExpressionSpecification, replacer: maplibregl.ExpressionSpecification | string, @@ -260,6 +266,5 @@ export function changeFirstLanguage( }; exploreNode(expr); - return expr; }