-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
479 lines (462 loc) · 23.7 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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hidden Portland Map</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="title" content="Hidden Portland Map">
<meta name="description" content="Use this map to discover Portland's little treasures when you're out and about, or see how things looked in the past.">
<!-- Social Sharing -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://hiddenportlandmap.com">
<meta property="og:title" content="Hidden Portland Map">
<meta property="og:description" content="Use this map to discover Portland's little treasures when you're out and about, or see how things looked in the past.">
<meta property="og:image" content="https://hiddenportlandmap.com/images/meta.png">
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://hiddenportlandmap.com">
<meta property="twitter:title" content="Hidden Portland Map">
<meta property="twitter:description" content="Use this map to discover Portland's little treasures when you're out and about, or see how things looked in the past.">
<meta property="twitter:image" content="https://hiddenportlandmap.com/images/meta.png">
<!-- Icons -->
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="theme-color" content="#ffffff">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<!-- CSS -->
<link rel="stylesheet" href="leaflet/leaflet.css"/>
<link rel="stylesheet" href="leaflet/MarkerCluster/MarkerCluster.css" />
<link rel="stylesheet" href="leaflet/MarkerCluster/MarkerCluster.Default.css" />
<link rel="stylesheet" href="leaflet/Locate/L.Control.Locate.css" />
<!-- JavaScript -->
<script src="jquery-3.6.0.min.js"></script>
<script src="leaflet/leaflet.js"></script>
<script src='leaflet/MarkerCluster/leaflet.markercluster.js'></script>
<script src="leaflet/Locate/L.Control.Locate.min.js"></script>
<script src="https://stamen-maps.a.ssl.fastly.net/js/tile.stamen.js?v1.3.0"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-G1HN96YZ99"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-G1HN96YZ99');
</script>
<style>
html, body {
margin: 0;
height: 100%;
width: 100%;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
h1 {
font-size: 22px;
}
.center {
text-align: center;
}
/* Map */
#map {
height: 100%;
width: 100%;
}
.map-cluster-circle {
background: #2d83cb;
color: white;
width: 40px;
height: 40px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
/* Filters */
#filters {
position: absolute;
left: 0;
top: 0;
z-index: 500;
background-color: rgba(255,255,255,0.8);
padding: 10px 20px 20px 30px;
transform: translateX(-600px);
-webkit-transform: translateX(-600px);
}
#filters label {
display: block;
padding-bottom: 10px;
padding-left: 10px;
}
#filters label span {
display: inline-block;
text-align: right;
width: 130px;
padding-right: 10px;
}
#filters.slide-in {
animation: slide-in 0.5s forwards;
-webkit-animation: slide-in 0.5s forwards;
}
#filters.slide-out {
animation: slide-out 0.5s forwards;
-webkit-animation: slide-out 0.5s forwards;
}
@keyframes slide-in {
100% { transform: translateX(0%); }
}
@-webkit-keyframes slide-in {
100% { -webkit-transform: translateX(0%); }
}
@keyframes slide-out {
0% { transform: translateX(0%); }
100% { transform: translateX(-600px); }
}
@-webkit-keyframes slide-out {
0% { -webkit-transform: translateX(0%); }
100% { -webkit-transform: translateX(-600px); }
}
/* Filter and Info buttons */
.leaflet-control-filter a span, .leaflet-control-info a span {
display: inline-block;
width: 20px;
height: 20px;
margin: 5px;
background-color: black;
}
.leaflet-control-filter.active a span, .leaflet-control-info.active a span {
background-color: #2074b6;
}
.leaflet-control-filter a span {
-webkit-mask-image: url("./leaflet/gear.svg");
mask-image: url("./leaflet/gear.svg");
}
.leaflet-control-info a span {
-webkit-mask-image: url("./leaflet/info.svg");
mask-image: url("./leaflet/info.svg");
}
/* Info Modal */
#modal {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
transition: opacity 500ms;
z-index: 1100;
}
.modal-content {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
padding: 20px;
background: #fff;
border-radius: 5px;
max-width: 500px;
max-height: 90%;
overflow-y: auto;
}
@media screen and (max-width: 700px){
.modal-content {
width: 80%;
}
}
#modal-x {
position: absolute;
right: 30px;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: black;
}
#modal .note {
font-size: 14px;
font-style: italic;
}
#modal button {
border: 2px solid black;
background-color: white;
color: black;
padding: 14px 28px;
font-size: 16px;
cursor: pointer;
}
#modal button:hover {
background-color: black;
color: white;
}
</style>
</head>
<body>
<div id="modal">
<div class="modal-content">
<a href="#" id="modal-x">×</a>
<h1>Hidden Portland Map</h1>
<p>This map lets you explore the "hidden" Portland. Use it to discover little treasures in your neighborhood, or when you're out and about, to see how things around you looked in the past.</p>
<p>Most markers on this map are from the <a target="_blank" href="https://www.facebook.com/groups/Hiddenportlandforthecurious">Hidden Portland for the Curious</a> community. A wonderful group of people who find and share the creative, weird, and wonderful things around town.</p>
<p>The map also includes markers with historical photos from <a target="_blank" href="https://efiles.portlandoregon.gov/">the Portland Archives</a>.</p>
<p>I hope this map and the wonderful content provided by countless people within it brings a little joy to your day. If you like it, please feel free to share it with others.</p>
<div class="center">
<a href="https://www.facebook.com/sharer.php?u=https://hiddenportlandmap.com" target="_blank"><img width=40px height=40px alt="share to facebook" src="./images/facebook.svg"></a>
<a href="https://twitter.com/share?url=https://hiddenportlandmap.com" target="_blank"><img width=40px height=40px alt="share to twitter" src="./images/twitter.svg"></a>
<a href="https://reddit.com/submit?url=https://hiddenportlandmap.com&title=Explore%20Hidden%20Portland" target="_blank"><img width=40px height=40px alt="share to reddit" src="./images/reddit.svg"></a>
</div>
<p class="note">Note: about a quarter of the markers are in the wrong spot due to the technical difficulty of automatically finding the correct location from a piece of text. If you feel so inclined, you can fix a marker by using the "Fix location" link in each marker popup.</p>
<p class="note">Code for this map is available on <a target="_blank" href="https://github.com/olivierbouwman/hidden-portland">GitHub</a>.</p>
<p class="note">Map tiles by <a target="_blank" href="http://stamen.com">Stamen Design</a>, under <a target="_blank" href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Map data by <a target="_blank" href="http://openstreetmap.org">OpenStreetMap</a>, under <a target="_blank" href="http://www.openstreetmap.org/copyright">ODbL</a>.</p>
<div class="center">
<button id="modal-close">Close</button>
</div>
</div>
</div>
<div id="map"></div>
<div id="filters">
<h2 class="center">Filters</h2>
<label for="years" id="years-label"><span id="years-text">Years (> 0)</span><input name="years" id="years" type="range" min="0" max="0" onchange="updateYears();"></label>
<label for="likes" id="likes-label"><span id="likes-text">Likes (> 0)</span><input name="likes" id="likes" type="range" min="0" max="10" onchange="updateLikes();"></label>
<label for="sources-hidden-portland" id="sources-hidden-portland-label"><span>Sources</span><input type="checkbox" value="hidden-portland" id="sources-hidden-portland" checked onchange="updateSources();">Hidden Portland</label>
<label for="sources-portland-archives" id="sources-portland-archives-label"><span></span><input type="checkbox" value="portland-archives" id="sources-portland-archives" checked onchange="updateSources();">Portland Archives</label>
<label for="search"><span>Search</span><input name="search" id="search" type="text" size="20" onchange="updateSearch()"></label>
</div>
<script>
var mapData = [];
var map;
var markers = [];
var unclustered = new L.featureGroup();
var clustered = L.markerClusterGroup({
showCoverageOnHover: false,
zoomToBoundsOnClick: true,
spiderfyOnMaxZoom: true,
removeOutsideVisibleBounds: true,
iconCreateFunction: function(cluster) {
return L.divIcon({ html: cluster.getChildCount(), className: 'map-cluster-circle', iconSize: L.circle()});
}
});
var markerIconPink = L.Icon.extend({
options: {
iconUrl: 'leaflet/images/marker-icon-pink.png',
iconRetinaUrl: 'leaflet/images/marker-icon-pink-2x.png',
shadowUrl: 'leaflet/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
},
});
var pinkIcon = new markerIconPink();
var markerIconGold = L.Icon.extend({
options: {
iconUrl: 'leaflet/images/marker-icon-gold.png',
iconRetinaUrl: 'leaflet/images/marker-icon-gold-2x.png',
shadowUrl: 'leaflet/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
},
});
var goldIcon = new markerIconGold();
var markerIconGrey = L.Icon.extend({
options: {
iconUrl: 'leaflet/images/marker-icon-grey.png',
iconRetinaUrl: 'leaflet/images/marker-icon-grey-2x.png',
shadowUrl: 'leaflet/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
},
});
var greyIcon = new markerIconGrey();
$.getJSON("data.json", function(jsondata) {
mapData = jsondata
let likesMax = 0;
let years = [];
$.each(jsondata, function(index, source) {
let sourceId = index;
$.each(source, function(id, element) {
// Lots of items end up here that are not located properly, filter them out.
if ((element.lc == undefined && element.l == undefined) || (element.l == "0" && element.lc == undefined) || (element.l == "45.515232,-122.6783853" && element.lc == undefined)) {
// Todo: when we delete an item, do we skip over the next one? Might want to refactor this.
delete(mapData[sourceId][id]);
return true;
}
// Find all years.
if (Number.isInteger(Number(element.d.substring(0,4))) && years.indexOf(element.d.substring(0,4)) === -1) {
years.push(element.d.substring(0,4));
}
// Find highest number of likes.
if (!isNaN(Number(element.r))) {
likesMax = Math.max(likesMax, Number(element.r));
}
});
});
let yearMin = Math.min(...years);
let yearMax = Math.max(...years);
document.getElementById("likes").max = likesMax;
document.getElementById("likes").value = 0;
document.getElementById("years").max = yearMax;
document.getElementById("years").min = yearMin;
document.getElementById("years").value = yearMin;
updateYears();
});
const modal = document.getElementById("modal");
const modalX = document.getElementById("modal-x");
const modalClose = document.getElementById("modal-close");
modalX.addEventListener('click', function(e) { modal.style.opacity = '0'; e.preventDefault(); });
modalClose.addEventListener('click', () => modal.style.opacity = '0');
modal.addEventListener("click", function(e) { if($(e.target).is('#modal')) {document.getElementById("modal").style.opacity='0';} });
modal.addEventListener('transitionend', () => modal.style.display = "none");
function updateLikes() {
updateMarkers();
document.getElementById('likes-text').innerText = "Likes (> " + document.getElementById('likes').value + ")";
gtag('event', 'select_content', { 'content_type': 'likes', 'item_id': document.getElementById('likes').value });
}
function updateYears() {
updateMarkers();
document.getElementById('years-text').innerText = "Years (> " + document.getElementById('years').value + ")";
gtag('event', 'select_content', { 'content_type': 'years', 'item_id': document.getElementById('years').value });
}
function updateSources() {
updateMarkers();
gtag('event', 'select_content', { 'content_type': 'sources' });
}
function updateSearch() {
updateMarkers();
gtag('event', 'search', { 'search_term': document.getElementById('search').value });
}
function fixLocation(id) {
clustered.removeLayer(markers[id]);
unclustered.addLayer(markers[id]);
let popupContent = markers[id].getPopup().getContent();
popupContent = popupContent.replace(/<a href="#"(.*?\<\/a><\/br><\/br>)/, '<a href="#" onclick="event.preventDefault();fixLocationFinish(' + id + ')"></br></br><strong>Drag this marker to the correct location and click here to submit your correction.</strong></a></br></br>');
markers[id].getPopup().setContent(popupContent);
markers[id].dragging.enable();
markers[id].setIcon(pinkIcon);
markers[id].off('dragend');
markers[id].openPopup();
gtag('event', 'select_content', { 'content_type': 'fix-start' });
return false;
}
function fixLocationFinish(id) {
let popupContent = markers[id].getPopup().getContent();
popupContent = popupContent.replace(/<a href="#"(.*?\<\/a><\/br><\/br>)/, '<a href="#" onclick="event.preventDefault();fixLocation(' + id + ');"></br></br><strong>Thank you for your fix! It will take about 15 minutes before your update shows up for other people.</strong></a></br></br>');
markers[id].getPopup().setContent(popupContent);
let lat = markers[id].getLatLng().lat;
let lng = markers[id].getLatLng().lng;
let source;
if (mapData['hidden-portland'][id] !== undefined) {
source = "hidden-portland";
}
else if (mapData['portland-archives'][id] !== undefined) {
source = "portland-archives";
}
else {
return;
}
submitFixedLocation(source + "_" + id + "_" + lat + "_" + lng);
markers[id].dragging.disable();
markers[id].setIcon(goldIcon);
gtag('event', 'select_content', { 'content_type': 'fix-finish' });
}
function submitFixedLocation(data) {
fetch('https://docs.google.com/forms/u/0/d/e/1FAIpQLSfMNlzh3Al0m_Mj-qd11_ru5cBB-e0KbDsq6_fhtYUhgngSVw/formResponse', {
method: 'POST',
mode: 'no-cors', // we're using no-cors so we don't have access to the response (https://developer.mozilla.org/en-US/docs/Web/API/Request/mode).
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
},
body: "entry.74105857=" + data
}).then(function (response) {
// console.log('sent but no idea if things worked out because of no-cors');
return response.text();
}).catch(function (err) {
// console.warn('error, internet connection is probably down.', err);
});
}
function updateMarkers() {
// Clear all markers.
clustered.clearLayers();
var search = document.getElementById('search').value;
$.each(mapData, function(index, source) {
let sourceId = index;
$.each(source, function (id, element) {
if (document.getElementById('sources-' + sourceId).checked) {
// Only load markers for selected years.
if (Number(element.d.substring(0, 4)) >= document.getElementById('years').value) {
// Only load markers that match our search term.
if (search.length === 0 || (search.length > 0 && element.t.toLowerCase().includes(search.toLowerCase()))) {
// Only load markers that match our minimum number of likes.
if (!element.r || Number(element.r) >= document.getElementById('likes').value) {
// Get corrected location if it exists.
let location;
if (element.lc !== undefined) {
location = element.lc;
}
else {
location = element.l;
}
let lat = location.toString().split(",")[0];
let lng = location.toString().split(",")[1];
// Create marker.
if (sourceId == "portland-archives") {
var marker = L.marker([lat,lng]).bindPopup('Portland Archives / Date: ' + element.d + ' / <a href="#" onclick="event.preventDefault();fixLocation(' + id + ')"><strong>Fix location</strong></a></br></br><a target="_blank" href="https://efiles.portlandoregon.gov/Record/' + id + '"><img src="https://efiles.portlandoregon.gov/Record/' + id + '/File/Thumbnail"></br>' + element.t + '</a>');
marker.setIcon(greyIcon);
}
else {
var marker = L.marker([lat,lng]).bindPopup('Hidden Portland / Date: ' + element.d + ' / <a href="#" onclick="event.preventDefault();fixLocation(' + id + ')"><strong>Fix location</strong></a></br></br><a target="_blank" href="https://www.facebook.com/groups/Hiddenportlandforthecurious/posts/' + id + '">' + element.t + '</a>');
}
clustered.addLayer(marker);
markers[id] = marker;
}
}
}
}
});
});
clustered.addTo(map);
}
var layer = new L.StamenTileLayer("toner-hybrid");
map = new L.Map("map", {
minZoom: 11,
maxZoom: 18,
maxBounds: [[44.967039, -121.571015],[45.957886, -123.397505]],
renderer: L.canvas(),
preferCanvas: true,
zoomAnimation: false,
attributionControl: false,
}).setView([45.5230313, -122.6659288], 14);
map.addLayer(layer);
map.addLayer(unclustered);
map.on('popupopen', function() { gtag('event', 'click', { 'event_category': 'popup' }); });
// Locate button
let lc = L.control.locate({
position: 'topleft',
setView: 'once',
flyTo: true,
keepCurrentZoomLevel: true,
showPopup: false,
strings: {
title: "Show my location on the map.",
outsideMapBoundsMsg: "Your location is outside of Portland and can not be used.",
}
}).addTo(map);
// Filter and Info buttons
$(".leaflet-control-locate.leaflet-bar.leaflet-control").after('<div class="leaflet-control-filter leaflet-bar leaflet-control"><a class="leaflet-bar-part leaflet-bar-part-single" title="Filter" href="#" id="toggle-filter"><span></span></a></div>');
$(".leaflet-control-filter.leaflet-bar.leaflet-control").after('<div class="leaflet-control-info leaflet-bar leaflet-control"><a class="leaflet-bar-part leaflet-bar-part-single" title="Info" href="#" id="toggle-info"><span></span></a></div>');
document.getElementById('toggle-filter').addEventListener('click', function(e) {
var isOpen = document.getElementById('filters').classList.contains('slide-in');
document.getElementById('filters').setAttribute('class', isOpen ? 'slide-out' : 'slide-in');
e.preventDefault();
});
document.getElementById('toggle-info').addEventListener('click', function(e) {
document.getElementById("modal").style.display = "inherit"
document.getElementById("modal").style.opacity = "1";
$('#modal .modal-content').scrollTop(0);
e.preventDefault();
});
</script>
</body>
</html>