在官网没有找到加载加载TMS地图的代码,在百度大概搜一下也没有看到,这里就展示一下代码,比加载WMSd地图服务更简单一点,直接把url替换了就可以了。代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MapBox加载TMS地图服务</title>
<script src='https://api.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.css' rel='stylesheet'/>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
/*隐藏logo*/
.mapboxgl-ctrl.mapboxgl-ctrl-attrib {
display: none !important;
}
.mapboxgl-ctrl-logo {
display: none !important;
}
</style>
</head>
<body>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiaGFtYnVnZXJkZXZlbG9wIiwiYSI6ImNqNXJtZjF4ZzB3em4yd21pZmVqbHlleDAifQ.I9eqVjtotz7jaU7XcJm9pQ';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v10',
center: [108.438, 34.431],
zoom: 7
});
map.on("load", function () {
map.addLayer({
"id":"tms-test",
"type": "raster",
'source': {
'type': 'raster',
'tiles': [
"http://localhost:63342/MapBox/test/{z}/{x}/{y}.png"
]
}
});
})
</script>
</body>
</html>
最后运行如下图所示: