文本编辑工具
环境搭建
GeoServer支持矢量瓦片
https://blog.csdn.net/qq_56781426/article/details/137233690
GeoServer配置跨域访问
MapBox GL加载矢量瓦片
加载面状图层
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>mapbox添加geoserver发布的矢量瓦片</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v1.0.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.0.0/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiamFuZ2xlIiwiYSI6ImNqdmtjcXUxMTBlYTEzenBodHZiZG5kOWkifQ.GPYsVamvlFm5N_OioA9fwQ';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v10',
zoom: 12,
center: [121.9, 42.3]
});
map.on('load', function() {
// 加载面状
map.addLayer({
"id": "ln_city_a",
"type": "fill",
"source": {
"type": "vector",
"scheme":"tms",
"tiles": ["http://localhost:8082/geoserver/gwc/service/tms/1.0.0/ne%3Aln_city_a@EPSG%3A900913@pbf/{z}/{x}/{y}.pbf"],
"minzoom": 1,
"maxzoom": 14
},
"source-layer": "ln_city_a", // 必须与GeoServer图层名称一致
"paint": {
"fill-color":"#088",
"fill-opacity":0.8
}
});
//加载线状
map.addLayer({
id: 'roads-layer',
type: 'line',
"source": {
"type": "vector",
"scheme":"tms",
"tiles": ["http://localhost:8082/geoserver/gwc/service/tms/1.0.0/ne%3Ahighways@EPSG%3A900913@pbf/{z}/{x}/{y}.pbf"],
"minzoom": 1,
"maxzoom": 14
},
'source-layer': 'highways', // 必须与GeoServer图层名称一致
paint: {
'line-color': '#FF0000',
'line-width': 2
}
});
});
map.addControl(new mapboxgl.NavigationControl());
</script>
</body>
</html>
加载线状图层