forked from ryangriggs/GoogleTimelineMapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
411 lines (355 loc) · 16.4 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<!DOCTYPE html>
<!--
Google Timeline Mapper
Map Google Timeline data in an easy to view format
Copyright(c) 2024 Ryan Griggs (https://github.com/ryangriggs)
Additional features by MueJosh (https://github.com/MueJosh)
Licensed under Apache 2.0 License
-->
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.30.1/moment.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', sans-serif;
}
.map {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
.toolbar {
position: absolute;
top: 0; left: 0;
height: 30px;
opacity: 0.8;
right: 0;
background-color: white;
z-index: 999;
}
.toolbar:hover {
opacity: 1;
}
.locations {
z-index: 1000;
position: absolute;
top: 30px;
right: 0;
width: 800px;
height: 300px;
overflow-y: scroll;
background-color: white;
opacity: 0.8;
}
.locations:hover {
opacity: 1;
}
.location {
cursor: pointer;
border: 1px solid black;
}
.location.template {
display: none;
}
.location.highlighted {
background-color: rgb(255, 247, 0);
}
</style>
</head>
<body>
<div id="map" class="map"><!-- The map container --></div>
<div class="toolbar">
Version 1.11<br>
<button id="btnImport">Import Data...</button><br>
<input type="file" id="fileInput" text="Import file" style="display: none" multiple /><br>
<button id="btnClear">Clear all locations</button><br>
<button id="btnExportCSV" onclick="exportSelected('csv');">Export Selected Locations as CSV</button><br>
<button id="btnExportGPX" onclick="exportSelected('gpx');">Export Selected Locations as GPX</button><br>
<button id="btnExportKML" onclick="exportSelected('kml');">Export Selected Locations as KML</button><br>
<button id="btnSelectAll" onclick="selectAll(true);">Select All</button><br>
<button id="btnDeselectAll" onclick="selectAll(false);">Deselect All</button><br>
<button id="btnInvert" onclick="invertSelection();">Invert Selection</button><br>
<button id="btnList" onclick="toggleLocationList();">Show/Hide Locations</button><br>
<label><input type="checkbox" id="chkConnectSequentially"> Connect Sequentially</label><br>
<label><input type="checkbox" id="chkDisableMarkers"> Disable Markers</label><br>
</div>
<!-- List of visited locations-->
<div class="locations" id="locationListContainer">
<table class="table list" id="lstLocations">
<thead>
<tr>
<td onclick="sortTable(0)">Location</td>
<td onclick="sortTable(1)">Arrived</td>
<td onclick="sortTable(2)">Departed</td>
<td onclick="sortTable(3)">Duration</td>
<td onclick="sortTable(4)">Description</td>
<td onclick="sortTable(5)">Longitude</td>
<td onclick="sortTable(6)">Latitude</td>
<td>Selected</td>
</tr>
</thead>
<tbody>
<tr class="template location">
<td class="location-name"></td>
<td class="arrived"></td>
<td class="departed"></td>
<td class="duration"></td>
<td><input type="text" class="description"></td>
<td class="longitude"></td>
<td class="latitude"></td>
<td>
<input type="checkbox" class="selected">
</td>
</tr>
</tbody>
</table>
</div>
<script>
let markers;
let polylines = []; // Array to hold polylines
$("#fileInput").on('change', (event) => {
var files = $("#fileInput")[0].files;
for (let file of files) {
if (file) {
var reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = function (evt) { parseInput(evt.target.result); };
reader.onerror = function (evt) { alert("Unable to read file.") };
}
}
});
$("#btnImport").on('click', () => {
const fileBrowser = $("#fileInput");
fileBrowser.click();
console.log("Done");
});
$("#btnClear").on('click', () => {
$("#lstLocations .location").not('.template').remove();
markers.clearLayers();
clearConnections(); // Clear connections when clearing markers
});
var map = L.map('map', {
zoomControl: false
}).setView([37.445, -0.09], 13);
const osm = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
const googleSat = L.tileLayer('http://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}', {
maxZoom: 20,
subdomains: ['mt0', 'mt1', 'mt2', 'mt3']
}).addTo(map);
var baseLayers = {
"Satellite": googleSat,
"OpenStreetMap": osm
};
L.control.layers(baseLayers, false, { position: "bottomleft" }).addTo(map);
map.locate({ setView: true });
L.control.zoom({
position: 'bottomright'
}).addTo(map);
markers = L.layerGroup().addTo(map); // Create group of markers
function parseInput(rawInput) {
// Try to parse JSON:
let data = false;
try {
data = JSON.parse(rawInput);
} catch (e) {
alert("Invalid data. The data must be in JSON format.");
console.error(e);
return;
}
// With valid JSON, attempt to load waypoints and create list.
if (typeof data.timelineObjects == "undefined") {
alert("Invalid data: must contain 'timelineObjects' array.");
return;
}
// Iterate all objects inside timelineObjects, adding all 'placeVisit' objects as locations.
for (let d of data.timelineObjects) {
if (typeof d.placeVisit == "undefined") { continue; } // Skip this object.
const place = d.placeVisit;
// Load the object as a location:
let l = $("#lstLocations .location.template").clone(true);
$("#lstLocations").append(l);
l.removeClass('template');
l.prop('locationData', place); // Save the data structure with the object.
l.find('.location-name').text(place.location.address);
const start = moment(place.duration.startTimestamp);
const end = moment(place.duration.endTimestamp);
l.find('.arrived').text(start.format('Y-M-D H:m:s'));
l.find('.departed').text(end.format('Y-M-D H:m:s'));
l.find('.duration').text(end.diff(start, 'minutes') + " min");
l.find('.longitude').text(place.location.longitudeE7 / 10000000.0);
l.find('.latitude').text(place.location.latitudeE7 / 10000000.0);
// Add the placeholder to the map
let m = L.marker(
[place.location.latitudeE7 / 10000000.0, place.location.longitudeE7 / 10000000.0],
{ title: place.location.address }
)
.addTo(markers);
// Add popup to marker:
m.bindPopup(place.location.address);
// On click, highlight the location.
m.on('click', () => {
$("#lstLocations .location").removeClass('highlighted');
l.addClass('highlighted');
l[0].scrollIntoView({
behavior: 'smooth', // You can use 'auto' for instant scrolling
block: 'center', // You can use 'center' or 'end' to control the alignment
inline: 'nearest' // You can use 'start' or 'end' to control horizontal alignment
});
});
l.prop('marker', m); // Save pointer to marker
// If list item is clicked, scroll to the marker and open its tooltip.
l.on('click', () => {
map.flyTo(m.getLatLng());
m.openPopup();
$("#lstLocations .location").removeClass('highlighted');
l.addClass('highlighted');
});
}
if ($("#chkConnectSequentially").is(":checked")) {
connectSequentially();
}
}
function toggleLocationList() {
$("#locationListContainer").toggle();
}
function selectAll(flag) {
$("#lstLocations .location").not('.template').each(function() {
$(this).find('.selected').prop('checked', flag);
});
}
function invertSelection() {
$("#lstLocations .location").not('.template').each(function() {
let el = $(this).find('.selected');
el.prop('checked', !el.is(':checked'));
});
}
/** Export a CSV, GPX, or KML file of the selected locations. **/
function exportSelected(format) {
const includeCoordinates = true; // Always include coordinates
let results = "";
if (format === "csv") {
results = `"Address","Arrival","Departure","Duration","Description"`;
if (includeCoordinates) {
results += `,"Longitude","Latitude"`;
}
results += `\n`;
// Iterate location list, extracting all selected items.
$(".locations .location").not('.template').each(function() {
let el = $(this);
if (el.find('.selected').is(':checked')) {
results += `"${el.find('.location-name').text()}","${el.find('.arrived').text()}","${el.find('.departed').text()}","${el.find('.duration').text()}","${el.find('.description').val()}"`;
if (includeCoordinates) {
results += `,"${el.find('.longitude').text()}","${el.find('.latitude').text()}"`;
}
results += `\n`;
}
});
} else if (format === "gpx") {
results += `<?xml version="1.0" encoding="UTF-8"?>\n<gpx version="1.1" creator="Google Timeline Mapper">\n`;
$(".locations .location").not('.template').each(function() {
let el = $(this);
if (el.find('.selected').is(':checked')) {
results += `<wpt lat="${el.find('.latitude').text()}" lon="${el.find('.longitude').text()}">\n`;
results += `<name>${el.find('.location-name').text()}</name>\n`;
results += `<desc>${el.find('.description').val()}</desc>\n`;
results += `</wpt>\n`;
}
});
results += `</gpx>`;
} else if (format === "kml") {
results += `<?xml version="1.0" encoding="UTF-8"?>\n<kml xmlns="http://www.opengis.net/kml/2.2">\n<Document>\n`;
$(".locations .location").not('.template').each(function() {
let el = $(this);
if (el.find('.selected').is(':checked')) {
results += `<Placemark>\n`;
results += `<name>${el.find('.location-name').text()}</name>\n`;
results += `<description>${el.find('.description').val()}</description>\n`;
results += `<Point><coordinates>${el.find('.longitude').text()},${el.find('.latitude').text()}</coordinates></Point>\n`;
results += `</Placemark>\n`;
}
});
results += `</Document>\n</kml>`;
}
// Return file:
const blob = new Blob([results], { type: format === "csv" ? "text/csv": "application/xml" });
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = `results.${format}`; // Corrected syntax for setting filename
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function connectSequentially() {
clearConnections(); // Clear any existing connections
let locations = $(".locations .location").not('.template').toArray().map(el => {
let $el = $(el);
return {
lat: parseFloat($el.find('.latitude').text()),
lng: parseFloat($el.find('.longitude').text()),
timestamp: new Date($el.find('.arrived').text()).getTime()
};
});
locations.sort((a, b) => a.timestamp - b.timestamp);
let latlngs = locations.map(loc => [loc.lat, loc.lng]);
let polyline = L.polyline(latlngs, {color: 'blue'}).addTo(map);
polylines.push(polyline);
}
function clearConnections() {
for (let polyline of polylines) {
map.removeLayer(polyline);
}
polylines = [];
}
$("#chkConnectSequentially").on('change', function() {
if (this.checked) {
connectSequentially();
} else {
clearConnections();
}
});
// Sorting function
function sortTable(columnIndex) {
const table = document.getElementById("lstLocations");
const rows = Array.from(table.rows).slice(1); // Exclude header row
const sortOrder = rows[0].classList.contains("sorted-asc") ? -1 : 1;
rows.sort((a, b) => {
const aValue = a.cells[columnIndex].innerText.trim();
const bValue = b.cells[columnIndex].innerText.trim();
if (aValue < bValue) return -sortOrder;
if (aValue > bValue) return sortOrder;
return 0;
});
// Remove sorting indicators from all columns
table.querySelectorAll("th").forEach(th => th.classList.remove("sorted-asc", "sorted-desc"));
// Add sorting indicator to the current column
const sortIndicatorClass = sortOrder === 1 ? "sorted-asc" : "sorted-desc";
table.rows[0].cells[columnIndex].classList.add(sortIndicatorClass);
// Reorder rows
rows.forEach(row => table.appendChild(row));
}
// Function to toggle marker view on the map
function toggleMarkers(disable) {
if (disable) {
map.removeLayer(markers); // Remove markers layer from the map
} else {
markers.addTo(map); // Add markers layer to the map
}
}
// Event listener for the checkbox
$("#chkDisableMarkers").on('change', function() {
toggleMarkers(this.checked); // Toggle marker view based on checkbox state
});
</script>
</body>
</html>