-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathlayers-swipe.html
More file actions
64 lines (62 loc) · 1.84 KB
/
layers-swipe.html
File metadata and controls
64 lines (62 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="./css/common.css">
<link rel="stylesheet" href="./css/ol.css">
<script src="./js/ol.js"></script>
<style>
.swipe {
position: absolute;
z-index: 9;
left: 50%;
height: 100%;
width: 2px;
background-color: #fff;
}
</style>
</head>
<body>
<div id="map" class="map">
<input id="swipe" type="range" style="width: 100%">
<div class="swipe"></div>
</div>
<script>
let osm = new ol.layer.Tile({
source: new ol.source.OSM()
});
let tiandituAnnotation = new ol.layer.Tile({
source: new ol.source.XYZ({
url: 'http://t3.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}'
})
});
let map = new ol.Map({
layers: [osm, tiandituAnnotation],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2
})
});
let swipe = document.getElementById('swipe');
tiandituAnnotation.on('precompose', (evt) => {
let ctx = evt.context;
let width = ctx.canvas.width * (swipe.value / 100);
ctx.save();
ctx.beginPath();
ctx.rect(width, 0, ctx.canvas.width - width, ctx.canvas.height);
ctx.clip();
});
tiandituAnnotation.on('postcompose', (evt) => {
let ctx = evt.context;
ctx.restore();
});
swipe.addEventListener('input', () => {
map.render();
}, false);
</script>
</body>
</html>