This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
leafletSwipe.html
115 lines (108 loc) · 2.99 KB
/
leafletSwipe.html
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Example</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>
<style>
body { margin:0; padding:0; }
#map {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
height: 800px;
}
</style>
</head>
<body>
<style type='text/css'>
#swipe {
background:#fff;
position:absolute;
bottom:0;
left:0;
right:0;
z-index:1000;
padding:10px;
height:30px;
}
#swipe #handle {
position:absolute;
height:20px;
padding:5px;
background:#aaa;
font-weight:bold;
border:1px solid #333;
cursor:pointer;
-webkit-user-select: none;
}
</style>
<div id='swipe'>
<div id='handle'>drag</div>
</div>
<div id='map'></div>
<script>
var center = new L.LatLng(-42.8232,147.2555);
var map = new L.Map('map', { center: center, zoom: 18, attributionControl:true, zoomControl:false});
var gccAtt = '© Glenorchy City Council'
var pits = new L.TileLayer.WMS("http://maps.gcc.tas.gov.au:8080/geoserver/ows", {
layers: 'GCC_cc:Stormwaterpits',
format: 'image/png',
transparent: true,
maxZoom: 20,
attribution: gccAtt
}).addTo(map);
var pipes = new L.TileLayer.WMS("http://maps.gcc.tas.gov.au:8080/geoserver/ows", {
layers: 'GCC_cc:Stormwaterpipes',
format: 'image/png',
transparent: true,
maxZoom: 20,
attribution: gccAtt
}).addTo(map);
var l_parent = getLayer(map._layers)._container,
handle = document.getElementById('handle'),
dragging = false;
handle.onmousedown = function() { dragging = true; return false;}
document.onmouseup = function() { dragging = false; }
document.onmousemove = function(e) {
if (!dragging) return;
setDivide(e.x);
}
map.on( "zoomend", function( e ) {
l_parent = getLayer(map._layers)._container;
setDivide(parseInt(handle.style.left));
});
map.on( "moveend", function( e ) {
l_parent = getLayer(map._layers)._container;
setDivide(parseInt(handle.style.left));
});
map.on( "drag", function( e ) {
l_parent = getLayer(map._layers)._container;
setDivide(parseInt(handle.style.left));
});
map.on( "mousemove", function( e ) {
l_parent = getLayer(map._layers)._container;
setDivide(e.containerPoint.x);
});
function setDivide(x) {
x = Math.max(0, Math.min(x, map.getSize()['x']));
handle.style.left = (x) + 'px';
var layerX = map.containerPointToLayerPoint(x,0).x
l_parent.style.clip = 'rect(-99999px ' + layerX + 'px 999999px -99999px)';
}
function getLayer(obj) {
var last;
for (var i in obj) {
if (obj.hasOwnProperty(i) && typeof(i) !== 'function') {
last = obj[i];
}
}
return last;
}
setDivide(300);
</script>
</body>
</html