<!DOCTYPE html>
<html>
<head>
<title>地图联动</title>
<link rel="stylesheet" href="https://openlayers.org/en/v5.3.0/css/ol.css" />
<script type="text/javascript" src="https://openlayers.org/en/v5.3.0/build/ol.js"></script>
<style>
body{
overflow: hidden;
}
html,body{
100%;
height: 100%;
position:absolute;
box-sizing: border-box;
padding: 0;
margin: 0;
}
.map{
50%;
float: left;
height: 100%;
}
</style>
</head>
<body>
<div id="map_1" class="map">
</div>
<div id="map_2" class="map ">
</div>
<script>
var map_1 = new ol.Map({
target:"map_1",
view:new ol.View({
projection: "EPSG:4326",
center:[115.7555794477557, 22.6070466884657],
zoom:7
}),
layers:[
new ol.layer.Tile({source:new ol.source.OSM()})
]
});
var map_2 = new ol.Map({
target:"map_2",
view:map_1.getView(),
layers:[
new ol.layer.Tile({
source: new ol.source.XYZ({
url:'http://t3.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=d0cf74b31931aab68af181d23fa23d8d'
}),
projection: "EPSG:4326",
id:"影像"
})
]
});
</script>
</body>
</html>