Dynamic place label filtering

98 Views Asked by At

I’m working on a map that shows local names and translated place names (e.g., “Deutschland” and “Germany”) at the same time. A very rough Mapbox prototype is posted at http://www.svexit.com/realnameatlas.html, but I’m open to trying this using Mapzen, Google Maps, or others

I’m trying to figure out if it’s possible / the best way to dynamically filter out place labels when they’re the same (e.g., “United Kingdom” in English is still “United Kingdom” or “Hamburg”, which doesn’t have a separate English translation, but has translations in Russian, French, Spanish, and Chinese). The goal is to leverage the existing translations and not maintain my own separate data set.

Thanks!

2

There are 2 best solutions below

0
On BEST ANSWER

I believe this Mapzen blog post shows something similar here with Tangram:

https://mapzen.com/blog/languages-of-india/

Because the name data is processed as a JavaScript object, you should be able to filter out any duplicates before drawing the labels.

0
On

Thanks to meetar pointing me in the right direction (and some additional spelunking here to check for "undefined"), I was able to suppress undefined English-language labels using the following:

            text_source: |
                function() {
                    if (typeof feature["name:en"] === "undefined") {
                    return feature["name"]; 
                            }
                    else {
                    return feature["name"] + '\n(' + feature["name:en"] + ')'; 
                        }
                    }