-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslider-fullscreen.html
177 lines (152 loc) · 5.89 KB
/
slider-fullscreen.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Full Screen Historical Delta Slider</title>
<!-- Setup Before-After Plugin dependencies -->
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.10.3.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.ui.touch-punch.min.js"></script>
<script type="text/javascript" src="js/jquery.beforeafter-map-0.11.js"></script>
<!-- Setup Leaflet -->
<script type="text/javascript" src="js/leaflet.js"></script>
<link rel="stylesheet" type="text/css" href="css/leaflet.css"/>
<!-- ESRI-leaflet plugin-->
<script type="text/javascript" src="js/esri-leaflet.js"></script>
<!-- Font awesome icons -->
<link rel="stylesheet" href="css/font-awesome-4.3.0/css/font-awesome.min.css">
<style>
body {
padding: 0;
margin: 0;
}
html, body, #map-container{
height: 100%;
width: 100%;
}
#basemaps-wrapper {
position: absolute;
top: 15px;
left: 75px;
z-index: 10;
background: white;
padding: 10px;
}
#basemaps {
margin-bottom: 5px;
}
#slide{
-webkit-appearance: none;
position: absolute;
width: 200px;
bottom: 10px;
left: 10px;
z-index: 10;
border-radius: 15px;
background: white;
height: 7px;
border: 1px solid black;
}
#before{
height:100vh;
width:100vw;
}
#after{
height:100vh;
width:100vw;
}
#fullicon {
position: absolute;
top: 15px;
right: 15px;
z-index: 10;
}
</style>
</head>
<body>
<!-- Create a map container div and divs for your two maps -->
<div id="map-container">
<!-- Make sure to give the map divs height and width -->
<div id="before"></div>
<div id="after"></div>
<div id="basemaps-wrapper" class="leaflet-bar">
<select name="basemaps" id="basemaps">
<option value="Oceans">Oceans<options>
<option value="Topographic">Topographic<options>
<option value="Streets">Streets</option>
<option value="NationalGeographic">National Geographic<options>
<option value="Gray">Gray<options>
<option value="DarkGray">Dark Gray<options>
<option value="Imagery">Imagery<options>
<option value="ShadedRelief">Shaded Relief<options>
</select>
</div>
<div id="fullicon">
<a href="deltademslider.html"><i class="fa fa-compress fa-3x" style="color:grey"></i></a>
</div>
<div>
<input id="slide" type="range" min="0" max="1" step="0.05" value="0.75" onchange="updateOpacity(this.value)">
</div>
</div>
<script type="text/javascript">
$(function() {
// create a map in the "before" and "after" divs, set the view to a given place and zoom
// You may want to turn attributionControl off so that the Leaflet attribution doesn't slide with the slider. Place all attribution on the after map.
// You may also want to turn off inertia, which in some cases can cause the maps to go out of sync
// inital map state
var center = [38.2,-121.8];
var zoom = 9;
var start_opacity = 0.75
// create before and after maps
before = L.map('before', {attributionControl: false, inertia: false, minZoom: 8}).setView(center, zoom);
after = L.map('after', {attributionControl: false, inertia: false, minZoom: 8}).setView(center, zoom);
// before layer
var before_layer = new L.esri.Layers.DynamicMapLayer("http://atlas.cws.ucdavis.edu/arcgis/rest/services/HistoricalDelta/HistoricalDelta_v6r4/MapServer", {opacity:start_opacity}).addTo(before);
// after layer;
var after_layer = new L.esri.Layers.DynamicMapLayer("http://atlas.cws.ucdavis.edu/arcgis/rest/services/HistoricalDelta/Modern_Delta/MapServer", {opacity:start_opacity}).addTo(after);
// initial state of the basemaps for both maps (default is oceans)
var base_before = L.esri.basemapLayer('Oceans').addTo(before);
var base_after = L.esri.basemapLayer('Oceans').addTo(after);
// Base map selector function to change basemap styles
var layerLabels; // layer for basemap layers
//for each map change the layer to a new ESRI basemap style
function setBasemap(map, layer, basemap) {
// remove current style
if (layer) {
map.removeLayer(layer);
}
// change layer to desired basemap style
layer = L.esri.basemapLayer(basemap);
// adds new style to map
map.addLayer(layer);
// removes layer labels
if (layerLabels) {
map.removeLayer(layerLabels);
}
// basemap options with labels
if (basemap === 'ShadedRelief' || basemap === 'Oceans' || basemap === 'Gray' || basemap === 'DarkGray' || basemap === 'Imagery' || basemap === 'Terrain') {
layerLabels = L.esri.basemapLayer(basemap + 'Labels');
map.addLayer(layerLabels);
}};
// event listener to change basemaps
var basemaps = document.getElementById('basemaps');
basemaps.addEventListener('change', function(){
setBasemap(after, base_after, basemaps.value);
setBasemap(before, base_before, basemaps.value);
});
// opacity controls
function updateOpacity(value) {
before_layer.setOpacity(value);
after_layer.setOpacity(value);
}
// event listener to change opacity
var slide = document.getElementById('slide');
slide.addEventListener('change', function(){
updateOpacity(slide.value);
$("#legend").css("opacity", slide.value); // changes opacity of legend
});
// Call the Before-After plugin
$('#map-container').beforeAfter(before,after, {showFullLinks: false});});
</script>
</body>
</html>