Openlayers之加载Stamen地图
1、Stamen地图瓦片构成
我们使用浏览器打开Stamen地图,按下F12查看网络资源,可以发现其瓦片URL非常直观明了,与OpenStreetMap的地图瓦片URL差不多,最终可以得到其通用URL:http://{a-d}.tile.stamen.com/toner/{z}/{x}/{y}.png,下面我们就来使用Openlayers加载Stamen地图;
2、代码实现
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="../lib/ol/ol.js"></script>
<link href="../css/ol.css" rel="stylesheet" />
<script type="text/javascript">
window.onload = function () {
var stamenMapLayer = new ol.layer.Tile({
source: new ol.source.XYZ({
url: 'http://{a-d}.tile.stamen.com/toner/{z}/{x}/{y}.png'
})
});
var map = new ol.Map({
layers: [stamenMapLayer],
view: new ol.View({
center: [106.51, 29.55],
projection: 'EPSG:4326',
zoom: 10
}),
target: 'map'
});
};
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
3、结果展示
转载自:https://blog.csdn.net/SmileCoffin/article/details/72864069