加载高德底图和自定义瓦片
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<title>高德瓦片</title>
<link rel="stylesheet" href="./dist/zyzc.css">
<script type="text/javascript" src="dist/maptalks.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
#map {
width: 100vw;
height: 100vh;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
const config = {
tileGD: "http://www.zyzcgis.xyz/tile/wg/mobile/gaode/",
tileGDBZ: 'https://www.zyzcgis.xyz/tile/wg/mobile/gaodeBiaoZhu/',
}
var map = new maptalks.Map('map', {
center: [114.426383, 30.62696],
zoom: 14,
minZoom: 10,
maxZoom: 19,
attribution: false
baseLayer: new maptalks.TileLayer('base', {
urlTemplate: 'http://wprd{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&z={z}&x={x}&y={y}&scl=1<ype=11',
subdomains: ['01', '02', '03', '04']
}),
layers: [
new maptalks.TileLayer('wg', {
urlTemplate: (x, y, z) => {
return `${config.tileGD}${z}/${y}/${x}.png`;
}
}),
new maptalks.TileLayer('wgbz', {
urlTemplate: (x, y, z) => {
return `${config.tileGDBZ}${z}/${y}/${x}.png`;
}
}),
]
});
</script>
</body>
</html>
加载百度底图和自定义瓦片
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<title>百度瓦片</title>
<link rel="stylesheet" href="./dist/zyzc.css">
<script type="text/javascript" src="dist/maptalks.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
#map {
width: 100vw;
height: 100vh;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
const config = {
tileBZ: "http://www.zyzcgis.xyz/tile/wg/pc/baidu/"
}
var map = new maptalks.Map('map', {
center: [114.426383, 30.62696],
zoom: 14,
minZoom: 10,
maxZoom: 19,
attribution: false,
spatialReference: {
projection: 'baidu'
},
baseLayer: new maptalks.TileLayer('base', {
urlTemplate: 'http://online{s}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&scaler=1&p=1',
subdomains: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
}),
layers: [
new maptalks.TileLayer('wg', {
urlTemplate: (x, y, z) => {
let diff = Math.pow(2, z - 1);
return config.tileBZ + 'L' + z + '/R' + toHex(diff - 1 - y, 8) + '/C' + toHex(x + diff, 8) +
'.png';
},
subdomains: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
}),
]
});
function toHex(num, length) {
let zero = "";
for (let i = 0; i < length; i++) {
zero += "0";
}
let temp = num.toString(16);
let result = zero + temp;
result = result.substr(temp.length, length);
return result;
}
</script>
</body>
</html>