简体   繁体   English

动态地点标签过滤

[英]Dynamic place label filtering

I'm working on a map that shows local names and translated place names (eg, “Deutschland” and “Germany”) at the same time. 我正在制作一张地图,同时显示本地名称和翻译的地名(例如“Deutschland”和“Germany”)。 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 一个非常粗略的Mapbox原型发布在http://www.svexit.com/realnameatlas.html ,但我愿意尝试使用Mapzen,Google Maps或其他

I'm trying to figure out if it's possible / the best way to dynamically filter out place labels when they're the same (eg, “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! 谢谢!

I believe this Mapzen blog post shows something similar here with Tangram: 我相信这个Mapzen博客文章在这里显示了与Tangram类似的东西:

https://mapzen.com/blog/languages-of-india/ 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. 由于名称数据是作为JavaScript对象处理的,因此您应该能够在绘制标签之前过滤掉任何重复项。

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: 感谢meetar指向我正确的方向(以及一些额外的洞察来检查“未定义”),我能够使用以下内容来抑制未定义的英语标签:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM