我正在尝试将所有标签的语言设置为德语。到目前为止,我尝试了一些方法,但都导致了一张空白的地图。我尝试了一些事情,包括:
var language = "de";
var map = L.mapbox.map('map', 'mapbox.places', {worldCopyJump: true})
.setView([51.163375,10.447683], 6)
.addControl(L.mapbox.geocoderControl('mapbox.places', {
autocomplete: true,
keepOpen: true
}));
map.setLayoutProperty('country-label-lg', 'text-field', '{name_' + language + '}');
map.setLayoutProperty('country-label-md', 'text-field', '{name_' + language + '}');
map.setLayoutProperty('country-label-sm', 'text-field', '{name_' + language + '}');
和:
var language = "de";
var map = L.mapbox.map('map', 'mapbox.places', {worldCopyJump: true})
.setView([51.163375,10.447683], 6)
.setLayoutProperty('country-label-lg', 'text-field', '{name_' + language + '}')
.setLayoutProperty('country-label-md', 'text-field', '{name_' + language + '}')
.setLayoutProperty('country-label-sm', 'text-field', '{name_' + language + '}')
.addControl(L.mapbox.geocoderControl('mapbox.places', {
autocomplete: true,
keepOpen: true
}));
还自定义了样式和图层,但它们都破坏了地图。
在 gl 的文档中有一个示例(https://www.mapbox.com/mapbox-gl-js/example/language-switch/(关于如何使用一些按钮更改语言,我认为它与我的代码没有什么不同。
document.getElementById('buttons').addEventListener('click', function(event) {
var language = event.target.id.substr('button-'.length);
// Use setLayoutProperty to set the value of a layout property in a style layer.
// The three arguments are the id of the layer, the name of the layout property,
// and the new property value.
map.setLayoutProperty('country-label-lg', 'text-field', '{name_' + language + '}');
});
你使用的是mapbox-js而不是mapbox-gl-js。所以你应该使用正确的文档:https://www.mapbox.com/mapbox.js/api/v3.1.1/在那里你可以看到mapbox-js没有像mapbox-gl-js这样的setLayoutProperty
方法。所以你正在尝试的永远不会奏效。