index.html
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>地图 - 同步地图</title>
<style type="text/css">
html,body{margin:0px;height:100%;width:100%}
#map0{width:calc(50% - 2px);height:calc(100% - 2px);float:left;border:1px solid}
#map1{width:calc(50% - 2px);height:calc(100% - 2px);float:right;border:1px solid}
.attr{background-color:#34495e;color:#fff;padding:0px 4px;font:16px sans-serif}
</style>
<link rel="stylesheet" href="https://unpkg.com/maptalks/dist/maptalks.css">
<script type="text/javascript" src="https://unpkg.com/maptalks/dist/maptalks.min.js"></script>
<body>
<div id="map0"></div>
<div id="map1"></div>
<script>
var map0 = new maptalks.Map('map0', {
center: [-0.113049,51.498568],
zoom: 14,
zoomControl : true,
baseLayer: new maptalks.TileLayer('base', {
urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
subdomains: ['a','b','c','d'],
attribution: '© <a href="http://osm.org">OpenStreetMap</a> contributors, © <a href="https://carto.com/">CARTO</a>'
})
});
var map1 = new maptalks.Map('map1', {
center: map0.getCenter(),
zoom: map0.getZoom(),
draggable : false, // disable draggble
scrollWheelZoom : false, // disable scroll wheel zoom
dblClickZoom : false, // disable doubleclick
baseLayer: new maptalks.TileLayer('base1', {
urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
subdomains: ['a','b','c','d'],
attribution: '© <a href="http://osm.org">OpenStreetMap</a> contributors, © <a href="https://carto.com/">CARTO</a>'
})
});
map0.on('moving moveend', function (e) {
map1.setCenter(e.target.getCenter());
});
map0.on('zooming zoomend', function (e) {
map1.setCenterAndZoom(e.target.getCenter(), e.target.getZoom());
});
map0.on('pitch', function (e) {
map1.setPitch(e.target.getPitch());
});
map0.on('rotate', function (e) {
map1.setBearing(e.target.getBearing());
});
new maptalks.control.Toolbar({
'position': 'top-right',
'items': [{
item: 'move me',
click: function () {}
}]
})
.addTo(map0);
</script>
</body>
</html>