-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
142 lines (113 loc) · 4.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OpenHistoricalMap :: Leaflet MBGL TimeSlider Control Demo</title>
<!-- Leaflet and Mapbox GL JS API, the the adapter for using MB within L -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/@maplibre/[email protected]/leaflet-maplibre-gl.min.js"></script>
<!-- the timeslider control and suporting DecimalDate library -->
<!-- pick either the minified or full-length version -->
<script src="decimaldate.js"></script>
<script src="leaflet-ohm-timeslider.js"></script>
<link href="leaflet-ohm-timeslider.css" rel="stylesheet" />
<!--
<script src="decimaldate.min.js"></script>
<script src="leaflet-ohm-timeslider.min.js"></script>
<link href="leaflet-ohm-timeslider.min.css" rel="stylesheet" />
-->
<!-- a map style-->
<script src="mapstyle.js"></script>
</head>
<body>
<div id="map"></div>
<div id="languagepicker"></div>
<style>
body, html {
margin: 0;
padding: 0;
}
#map {
background-color: #ccc;
width: 100vw;
height: 100vh;
}
#languagepicker {
position: absolute;
top: 0;
right: 0;
border-bottom-left-radius: 5px;
background: white;
color: black;
z-index: 1000;
padding: 0 0 0.5em 0.5em;
}
#languagepicker label {
display: block;
}
</style>
<script>
const START_ZOOM = 14.0;
const START_CENTER = [ 47.6062, -122.3321 ];
let MAP, TIMESLIDER, OHMLAYER;
document.addEventListener('DOMContentLoaded', function () {
MAP = L.map('map', {
zoomSnap: 0.1,
})
.setView(START_CENTER, START_ZOOM);
L.control.scale().addTo(MAP);
OHMLAYER = new L.maplibreGL({
attribution: "<a href='https://www.openhistoricalmap.org/'>OHM</a>",
style: OHM_MAP_STYLE,
});
OHMLAYER.addTo(MAP);
const tsoptions = {
vectorLayer: OHMLAYER,
vectorSourceName: 'osm',
range: ['1850-01-01', '2020-12-31'],
date: '1860-06-15',
stepInterval: 1,
stepAmount: '10year',
onDateChange: function (date) {
console.debug(['timeslider.js onDateChange', date, this]);
},
onRangeChange: function (range) {
console.debug(['timeslider.js onRangeChange', range, this]);
},
onReady: function () {
console.debug(['timeslider.js onReady', this]);
},
};
const selectedlanguage = (new URLSearchParams(document.location.search)).get('lang');
if (selectedlanguage) {
tsoptions.language = selectedlanguage;
}
TIMESLIDER = new L.Control.OHMTimeSlider(tsoptions).addTo(MAP);
// add the list of languages to the language picker display
const languageoptions = TIMESLIDER.listLanguages().slice();
languageoptions.splice(0, 0, 'auto');
languageoptions.forEach(function (language) {
const div = document.createElement('label');
const txt = document.createElement('span');
txt.innerText = language;
const cb = document.createElement('input');
cb.type = 'radio';
cb.name = 'language';
cb.value = language;
if (language == selectedlanguage || (!selectedlanguage && language == 'auto')) cb.checked = true;
div.appendChild(txt);
div.appendChild(cb);
document.getElementById('languagepicker').appendChild(div);
cb.addEventListener('change', function () {
const newlanguage = this.value;
document.location.search = '?lang=' + newlanguage;
});
});
});
</script>
</body>
</html>