Skip to content

Commit cd27027

Browse files
hotfix: some symbol layers not showing up (v1.12.1) (#601)
Layers that don't have name properties do not need to be localized (e.g. highway numbers). Localizing them was overriding their properties, which caused them to not show up on the map. J= WAT-5275 TEST=manual verified on test-site that road shields and route markers now show up, and place names are still localized as expected. * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots * add parenthesis to make conditions clearer * Update snapshots * Update snapshots * Update snapshots --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 1c7946c commit cd27027

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

4.89 KB
Loading

src/components/MapboxMap.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,29 @@ export function MapboxMap<T>({
229229
// keep track of the previous value of mapboxOptions across renders
230230
const prevMapboxOptions = useRef(mapboxOptions);
231231

232+
/**
233+
* Localizes Mapbox label text to a specific locale.
234+
*
235+
* Updates symbol layers that are place names such that labels prefer `name_<lang>`
236+
* (e.g. `name_fr`) and fall back to `name` when unavailable.
237+
*
238+
* Note:
239+
* - Symbol layers that are place names would have `text-field` properties that includes 'name', which are localized.
240+
* - Other symbol layers (e.g. road shields, transit, icons) are left unchanged.
241+
*/
232242
const localizeMap = useCallback(() => {
233243
const mapbox = map.current;
234244
if (!mapbox || !locale) return;
235245

236246
const localizeLabels = () => {
237247
mapbox.getStyle().layers.forEach(layer => {
238-
if (layer.type === "symbol" && layer.layout?.["text-field"]) {
248+
if (layer.type !== "symbol") {
249+
return;
250+
}
251+
const textField = layer.layout?.["text-field"];
252+
if (typeof textField === "string"
253+
? textField.includes("name")
254+
: (Array.isArray(textField) && JSON.stringify(textField).includes("name"))) {
239255
mapbox.setLayoutProperty(
240256
layer.id,
241257
"text-field",

test-site/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)