Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
initMap() {
mapboxgl.accessToken =
"pk.eyJ1Ijoid3VjYW5nZW8iLCJhIjoiY2oxNGQ1ZDdsMDA0djJxbzdzdGU4NWpqMiJ9.iaTLldYv7GNfxWhN42h__g";
const map = new mapboxgl.Map({
container: this.$refs.basicMapbox,
style: CONFIG.HOST + "/style.json",
center: [116.295, 39.945],
zoom: 16
});
// 设置语言
var language = new MapboxLanguage({ defaultLanguage: "zh" });
map.addControl(language);
// 地图导航
var nav = new mapboxgl.NavigationControl();
map.addControl(nav, "top-left");
// 比例尺
var scale = new mapboxgl.ScaleControl({
maxWidth: 80,
unit: "imperial"
});
map.addControl(scale);
scale.setUnit("metric");
// 全图
map.addControl(new mapboxgl.FullscreenControl());
// 定位
map.addControl(
const addMapControl = (map) => {
map.setLayoutProperty('country-label-lg', 'text-field', ['get', 'name_zh']);
map.addControl(new MapboxLanguage({
defaultLanguage: 'zh',
}));
}
componentDidMount() {
const map: MapboxMap = this._map;
const {
supportedLanguages,
languageTransform,
languageField,
getLanguageField,
languageSource,
defaultLanguage
} = this.props;
const control: MapboxLanguageControl = new MapboxLanguage({
supportedLanguages,
languageTransform,
languageField,
getLanguageField,
languageSource,
defaultLanguage
});
map.addControl(control);
this._control = control;
}