Skip to content

Commit

Permalink
LOCAL now working and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlurie committed Nov 5, 2024
1 parent 7e9e7bc commit f540106
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 2 additions & 3 deletions src/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -260,6 +266,5 @@ export function changeFirstLanguage(
};

exploreNode(expr);

return expr;
}

0 comments on commit f540106

Please sign in to comment.