代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="./css/common.css">
<link rel="stylesheet" href="./css/ol.css">
</head>
<body>
<div id="map" class="map fullsize"></div>
<script src="./js/ol.js" charset="utf-8"></script>
<script type="text/javascript">
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile ({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.transform([116.5, 39.9], 'EPSG:4326', 'EPSG:3857'),
zoom: 4
})
});
// 全国道路图层
var resolutions = [];
for (var i = 0; i <= 8; ++i) {
resolutions.push(156543.03392804097 / Math.pow(2, i * 2));
}
let url = `http://cheerfun.xyz/vt/tile/{z}/{x}/{y}?`;
url += `table=(select * from cn_pg where admin_level = '4') as subquery`;
url += `&`;
url += `geometry_field=way`;
var vectortileLayer = new ol.layer.VectorTile({
source: new ol.source.VectorTile({
format: new ol.format.MVT(),
tileGrid: new ol.tilegrid.TileGrid({
extent: ol.proj.get('EPSG:3857').getExtent(),
resolutions: resolutions,
tileSize: 512
}),
tilePixelRatio: 1,
tileUrlFunction: (tileCoord) => {
return (url)
.replace('{z}', String(tileCoord[0] * 2 - 1))
.replace('{x}', String(tileCoord[1]))
.replace('{y}', String(-tileCoord[2] - 1))
.replace('{a-d}', 'abcd'.substr(
((tileCoord[1] << tileCoord[0]) + tileCoord[2]) % 4, 1));
}
})
});
map.addLayer(vectortileLayer);
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。