- 问题情景:矢量图层层级4-8,地图缩放到9,矢量地图数据不显示了。如何保留上一层级数据在地图上呢?
- 解决:添加Source时设置maxzoom或minzoom属性。如矢量图层层级4-8设置为:
map.on('load', function() {
// 添加数据源
map.addSource('aero_navdata', {
"type": "vector",
'tiles': [
'https://d116.foht.com/tileserver/resources/aero_navdata_2404/tiles/{z}/{x}/{y}?v=1713028420.2392&Key-Pair-Id=K3B6LIRZIHY0OC&Policy=eyJTdGF0'
],
maxzoom: 8, //必须设置并且最大或最小需不得大于或小于矢量图层,否则地图层级超出矢量图层层级时,地图上不会显示。
minzoom: 4,
});
map.addLayer({
"id": "Airway Airspace - World",
"layout": {},
"metadata": {
"group": "TMA/TCA"
},
maxzoom: 22,
minzoom: 4,
"paint": {
"line-color": "hsla(206, 97%, 34%, 0.3)",
"line-offset": {
"base": 1,
"stops": [
[
0,
0
],
[
22,
7.5
]
]
},
"line-opacity": {
"base": 1,
"stops": [
[
5,
0
],
[
6,
1
]
]
},
"line-width": {
"base": 1,
"stops": [
[
6,
1.5
],
[
9,
10
]
]
}
},
"source": "aero_navdata",
"source-layer": "airspaces",
"type": "line"
})
map.addLayer({
"id": "TRSA",
"layout": {
"symbol-placement": "line",
"symbol-spacing": {
"base": 1,
"stops": [
[
0,
600
],
[
12,
1000
]
]
},
"text-field": "{ac}-{res}-{t}-{ll_raw}",
"text-font": [
"Open Sans Bold"
],
"text-letter-spacing": 0.05,
"text-offset": [
0,
0.75
],
"text-size": {
"base": 1,
"stops": [
[
8,
14
],
[
12,
16
]
]
},
"line-cap": "round",
"line-join": "round",
"visibility": "visible",
},
"metadata": {
"group": "Airspace Labels - Controlled"
},
"minzoom": 8,
"paint": {
"text-color": "#fff",
"text-halo-color": "#0362aa",
"text-halo-width": 2
},
"source": "aero_navdata",
"source-layer": "airspaces",
"type": "symbol"
})
});
后续使用补充Source 中属性。