-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
241 lines (219 loc) · 7.75 KB
/
index.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<!DOCTYPE html>
<html>
<head>
<title>OSM tile access logs viewer</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet@0.7.7/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@0.7.7/dist/leaflet.js"></script>
<script src="leaflet-hash.js"></script>
<script src="spectrum.js"></script>
</head>
<body>
<!-- add and init leaflet map -->
<div id="map" style="position:absolute; top:0; left:0; right:0; bottom:0;"></div>
<script>
var map = L.map('map', {
maxZoom: 19-8
}).setView([46.5, 11.5], 4);
var hash = new L.Hash(map);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="www.openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}).addTo(map);
</script>
<!-- add and init file dropper, from http://html5demos.com/file-api -->
<style>
#map.hover {
opacity: 0.4;
}
#map img.leaflet-tile {
filter: grayscale(1);
-webkit-filter: grayscale(1);
}
#map canvas {
cursor: pointer;
opacity: 0.85;
}
#info {
position: absolute;
left: 60px;
top: 10px;
padding: 15px 25px;
background-color: rgba(200,200,0,0.5);
max-width: 20em;
}
#info h1 {
margin-top: 0.3em;
font-size: 1.42em;
}
#info .about {
text-align: right;
margin-top: -8px;
}
#intro.done {
display: none;
}
#intro label {
cursor: pointer;
}
#processing {
display: none;
}
#processing:before {
content: '» ';
}
#processing.started {
display: block;
}
#processing.done {
display: none;
}
#legend {
display: none;
}
#legend.done {
display: block;
}
#legend h2 {
margin-top: 0;
font-size: 1.25em;
}
#status {
padding: 5px;
color: #fff;
background: #ccc;
display: none;
}
#status.fail {
background: #c00;
display: block;
}
#status.success {
background: #0c0;
}
#legend a {
}
#legend a.disabled {
opacity: 0.6;
pointer-events: none;
cursor: default;
text-decoration: none;
}
#legend span.min, #legend span.max {
position: absolute;
line-height: 30px;
}
#legend span.min {
left: 10px;
}
#legend span.max {
right: 10px;
color: white;
}
#legend canvas#spectrum {
width: 100%;
height: 30px;
}
</style>
<div id="info">
<h1>OSM tile access logs viewer</h1>
<p class="about"><a href="https://www.openstreetmap.org/user/tyr_asd/diary/39434">about this tool</a></p>
<p id="status">File API & FileReader API not supported</p>
<div id="intro">Drag and drop an (unpacked) osm <a href="http://planet.openstreetmap.org/tile_logs/">tile access log</a> file onto the map or click <input type="file" id="fileElem" accept=".txt" style="display:none" onchange="handleFiles(event, this.files)"> <a href="#"><label for="fileElem">here to select</label></a> one.</div>
<div id="processing">please wait …</div>
<div id="legend">
<h2></h2>
<p>Displaying stats for zoom level <span id="zoomlevel">…</span> (<a href="#" id="overzoom-plus">coarser</a>/<a href="#" id="overzoom-minus" class="disabled">finer</a>)</p>
<div style="position:relative;">
<span class="min">10</span>
<span class="max" id="maxCount">10,000</span>
<canvas id="spectrum" width="300" height="30"></canvas>
</div>
</div>
</div>
<script>
var holder = document.getElementsByTagName('body')[0],
state = document.getElementById('status'),
intro = document.getElementById('intro'),
processing = document.getElementById('processing'),
legend = document.getElementById('legend');
var osmTileAccessLogLayer;
var overzoom = 0;
if (typeof window.FileReader === 'undefined') {
state.className = 'fail';
} else {
state.className = 'success';
state.innerHTML = 'File API & FileReader available';
}
holder.ondragover = function () { this.className = 'hover'; return false; };
holder.ondragend = function () { this.className = ''; return false; };
holder.ondrop = function(e) { handleFiles(e, e.dataTransfer.files) }
function handleFiles(e, files) {
this.className = '';
e.preventDefault();
intro.className = 'done';
processing.className = 'started';
var file = files[0],
reader = new FileReader();
if (!file.name.match(/\.txt$/)) {
intro.className = '';
processing.className = 'done';
alert("unpack the log file first!");
return;
} else {
legend.getElementsByTagName('h2')[0].textContent = file.name.match(/(.*)\.txt$/)[1]
}
reader.onload = function (event) {
console.timeEnd("read file");
osmTileAccessLogLayer = L.tileLayer.osmTileAccessLogLayer(event.target.result, function() {
processing.className = 'done';
legend.className = 'done';
}).addTo(map);
osmTileAccessLogLayer.overzoom(overzoom);
};
console.time("read file");
reader.readAsArrayBuffer(file);
// draw legend spectrum
var spectrum = document.querySelector('canvas#spectrum');
var context = spectrum.getContext('2d');
context.lineWidth = 1;
for (var x=0; x<spectrum.width; x++) {
context.beginPath();
context.moveTo(x, 0);
context.lineTo(x, spectrum.height);
context.strokeStyle = magma(1-x/spectrum.width);
context.stroke();
}
return false;
}
function updateZoom() {
document.getElementById('zoomlevel').textContent = map.getZoom()+8-overzoom
}
updateZoom();
map.on('zoomend', updateZoom);
document.getElementById('overzoom-plus').onclick = function(e) {
e.preventDefault();
if (overzoom >= 8) return
overzoom++
osmTileAccessLogLayer.overzoom(overzoom)
updateZoom()
if (overzoom > 0)
document.getElementById('overzoom-minus').className = ''
if (overzoom == 8)
document.getElementById('overzoom-plus').className = 'disabled'
}
document.getElementById('overzoom-minus').onclick = function(e) {
e.preventDefault();
if (overzoom <= 0) return
overzoom--
osmTileAccessLogLayer.overzoom(overzoom)
updateZoom()
if (overzoom == 0)
document.getElementById('overzoom-minus').className = 'disabled'
if (overzoom < 8)
document.getElementById('overzoom-plus').className = ''
}
</script>
<script src="index.js"></script>
</body>
</html>