mapbox-gl JS 设置中文语言

本文由花朝网原创首发,授权转载请以链接形式注明出处,本文唯一永久链接:http://www.huazhaox.com/article/16

mapbox-gl JS 设置语言为中文,先上代码和设置后的效果:

import mapboxgl from 'mapbox-gl'
import 'mapbox-gl/dist/mapbox-gl.css'
import MapboxLanguage from '@mapbox/mapbox-gl-language'

const glmap = new mapboxgl.Map({
	container: 'glmap',
	style: 'mapbox://styles/mapbox/streets-v11',

	attributionControl: false,
	bounds: [[68.366455, 13.085811], [140.021727, 58.685321]]
})

glmap.addControl(new MapboxLanguage({defaultLanguage: 'zh-Hans'}))

需要注意的是,如果要成功设置地图显示语言,Style 样式需满足要求,否则报错:Error: If using MapboxLanguage with a Mapbox style, the style must be based on vector tile version 8, e.g. "streets-v11",只能是矢量瓦片的,根据官方文档提供的 Styles 测试了下,好像只有这一个可以:mapbox://styles/mapbox/streets-v11,┓( ´∀` )┏

0 条评论
请不要发布违法违规有害信息,如发现请及时举报或反馈
还没有人评论呢,速度抢占沙发!
相关文章