/
test.html
162 lines (144 loc) · 5.59 KB
/
test.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
<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Wildfires in the U.S.</title>
<meta charset="utf-8">
<meta name="robots" content="noindex,follow">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Condensed:700|Roboto+Mono" rel="stylesheet">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin="" />
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js" integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw==" crossorigin=""></script>
<script src="//extras.denverpost.com/app/homicide-report/js/leaflet-grouped-layer-control.js"></script>
<script src="moment.js"></script>
<script src="./leaflet.ajax.min.js"></script>
<style>
html,
body {
height: 100%;
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
}
#map {
width: 100%;
height: 100%;
}
#lapseDate {
display:block;
position: absolute;
top:0;
right:0;
width:125px;
height:30px;
padding-top: 10px;
padding-left: 15px;
background:rgba(255,255,255,0.5);
border-left:2px solid rgba(0,0,0,0.5);
border-bottom:2px solid rgba(0,0,0,0.5);
font-family: 'Roboto', sans-serif;
font-weight: bold;
font-size:1.1em;
color:#222;
z-index: 9999999;
}
.leaflet-popup-content-wrapper {
border-radius: 0;
}
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
background: #fafafa;
}
.leaflet-popup-content {
font-size: .9rem;
}
.credit {
font-size: .8rem;
color: #9b9b9b;
font-style: italic;
text-align: right;
margin-top: 5px;
}
</style>
</head>
<body>
<div id="lapseDate"></div>
<div id="map"></div>
<script>
var terrainMap = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}.{ext}', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: 'abcd',
minZoom: 5,
maxZoom: 13,
ext: 'png'
});
var map = L.map('map', {
center: [37.60, -106.99],
zoom: 10,
layers: [terrainMap]
});
var geojsonLayers = [];
var layerGroup = L.layerGroup().addTo(map);
function swapLayer(datafile) {
var returnId = false;
$.getJSON(datafile, function(data) {
var geojsonLayer = L.geoJson(data, {
style: function(feature) {
return {
weight: 3,
fillOpacity: 0.3,
fillColor: '#bf0000',
color: '#bf0000'
};
},
}).addTo(layerGroup);
returnId = geojsonLayer._leaflet_id;
console.log(geojsonLayer._leaflet_id);
});
return returnId;
}
function sleepFor( sleepDuration ){
var now = new Date().getTime();
while(new Date().getTime() < now + sleepDuration){ /* do nothing */ }
}
function setDate(dateString) {
$('#lapseDate').html(dateString);
}
var dataFiles = [
['June 15, 2013','./timelapse-west-fork-20130615.json'],
['June 16, 2013','./timelapse-west-fork-20130616.json'],
['June 17, 2013','./timelapse-west-fork-20130617.json'],
['June 18, 2013','./timelapse-west-fork-20130618.json'],
['June 19, 2013','./timelapse-west-fork-20130619.json'],
['June 20, 2013','./timelapse-west-fork-20130620.json'],
['June 21, 2013','./timelapse-west-fork-20130621.json'],
['June 22, 2013','./timelapse-west-fork-20130622.json'],
['June 23, 2013','./timelapse-west-fork-20130623.json'],
['June 24, 2013','./timelapse-west-fork-20130624.json'],
['June 25, 2013','./timelapse-west-fork-20130625.json'],
['June 26, 2013','./timelapse-west-fork-20130626.json'],
['June 28, 2013','./timelapse-west-fork-20130628.json'],
['June 30, 2013','./timelapse-west-fork-20130630.json'],
['July 1, 2013','./timelapse-west-fork-20130701.json'],
['July 3, 2013','./timelapse-west-fork-20130703.json'],
['July 4, 2013','./timelapse-west-fork-20130704.json'],
['July 5, 2013','./timelapse-west-fork-20130705.json'],
['July 7, 2013','./timelapse-west-fork-20130707.json'],
['July 8, 2013','./timelapse-west-fork-20130708.json']
];
$(document).ready(function() {
var startMap = setTimeout(function() {
for (var i=0;i<dataFiles.length;i++) {
var delay = (i+1 == dataFiles.length) ? 5000 : 1500;
console.log(dataFiles[i][0]);
setDate(dataFiles[i][0]);
geojsonLayers[i] = swapLayer(dataFiles[i][1]);
sleepFor(250);
if (typeof geojsonLayers[i-1] != 'undefined') layerGroup.removeLayer(geojsonLayers[i-1]);
sleepFor(delay);
}
},2000);
});
</script>
</body>
</html>