forked from ryangriggs/GoogleTimelineMapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_old.html
312 lines (272 loc) · 12.8 KB
/
index_old.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
<!doctype html>
<!--
Google Timeline Mapper
Map Google Timeline data in an easy to view format
Copyright(c) 2024 Ryan Griggs (https://github.com/ryangriggs)
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.06
<button id="btnImport">Import Data...</button>
<input type="file" id="fileInput" text="Import file" style="display: none" multiple />
<button id="btnClear">Clear all locations</button>
<button id="btnExport" onclick="exportSelected();">Export Selected Locations</button>
<button id="btnSelectAll" onclick="selectAll(true);">Select All</button>
<button id="btnDeselectAll" onclick="selectAll(false);">Deselect All</button>
<button id="btnInvert" onclick="invertSelection();">Invert Selection</button>
<button id="btnList" onclick="toggleLocationList();">Show/Hide Locations</button>
</div>
<!-- List of visited locations-->
<div class="locations" id="locationListContainer">
<table class="table list" id="lstLocations">
<thead>
<tr>
<td><a href="javascript:sortTable('location');" title="Click to sort">Location</a></td>
<td><a href="javascript:sortTable('date')" title="Click to sort">Arrived</a></td>
<td>Departed</td>
<td><a href="javascript:sortTable('duration')" title="Click to sort">Duration</a></td>
<td>Description</td>
<td>Longitude</td>
<td>Latitude</td>
<td><a href="javascript:sortTable('selected')" title="Click to sort">Selected</a></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;
$("#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();
});
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 sat = 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": sat,
"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');
});
}
}
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 file of the selected locations. **/
function exportSelected() {
const includeCoordinates = true; // Always include coordinates
let 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`;
}
});
// Return file:
const blob = new Blob([ results ], { type: "text/csv" });
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = "results.csv";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
/** Sort a given table by the specified column **/
function sortTable(col) {
let tbl = $("#lstLocations tbody");
let items = tbl.find("tr").not('.template').get();
items.sort(function(a, b) {
let one = $(a).find("." + col).text().toUpperCase();
let two = $(b).find("." + col).text().toUpperCase();
if (one < two) return -1;
if (one > two) return 1;
return 0;
});
$.each(items, function(index, row) {
tbl.append(row);
});
}
</script>
</body>
</html>