-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
225 lines (200 loc) · 7.81 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
<!DOCTYPE html>
<html>
<html lang = "en">
<head>
<meta charset = "UTF-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<title>
In and Out of Place: Tracking Resource Extractions from Treaty Lands
</title>
<!--Leaflet CSS -->
<link
rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""
/>
<link
rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
/>
<link rel="stylesheet" href="css/main.css"/>
<link rel="stylesheet" href="css/slider.css"/>
<!--Leaflet + jQuery js-->
<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"></script>
<!--Time Slider-->
<script src="src/timeslider.js"></script>
<!-- Leaflet Responsive Popup Plugin -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/leaflet.responsive.popup.css" />
<script src="https://unpkg.com/[email protected]/leaflet.responsive.popup.js"></script>
</head>
<body onload="init()">
<!--Basemap and slider-->
<div id="map">
<input
id="slider"
type="range"
min="0" max="1"
step="0.1"
value="1"
oninput="overlay.setOpacity(this.value)"
/>
<div class="map-buttons">
<div class="dropdown timed" data-start-time="3" data-end-time="3" hidden>
<button class="dropbtn">Expeditions <i class="fa fa-caret-down"></i></button>
<div class="dropdown-content">
<a href="https://www.inandoutofplace.digitalscholarship.brown.edu/io/custer-expedition" target="_blank">Custer's Expedition, 1874</a>
</div>
</div>
</div>
</div>
<!--Time Slider-->
<div class="container">
<div class="range">
<input type="range" min="0" max="6" step="1" value="0"/>
</div>
<ul class="range-labels">
<li>Long Ago</li>
<li>1851</li>
<li>1868</li>
<li>1874</li>
<li>1877</li>
<li>1889</li>
<li>Today</li>
</ul>
</div>
<!--Adding map and overlay-->
<script type="text/javascript">
let map, overlay, geoJSONdata;
const DATASETS = [
"geojson/sites.geojson",
"geojson/1851FLTLand.geojson",
"geojson/1868FLTCombinedLand.geojson",
"geojson/1877ActLand.geojson",
"geojson/1889AgreementLand.geojson",
"geojson/2024ReservationLand.geojson"
];
let data = [];
// Define custom icons
const iconMappings = {
'sacred': L.icon({
iconUrl: 'markers/sacredsites_icon.png',
iconSize: [30, 30],
iconAnchor: [15, 30]
}),
'historic': L.icon({
iconUrl: 'markers/forts_icons.png',
iconSize: [30, 30],
iconAnchor: [15, 30]
}),
'city': L.icon({
iconUrl: 'markers/city_icons.png',
iconSize: [30, 30],
iconAnchor: [15, 30]
}),
};
async function init() {
try {
// Load geoJSON data from multiple local files
for (const DATA_PATH of DATASETS) {
console.log(`Fetching data from: ${DATA_PATH}`);
const response = await fetch(DATA_PATH);
if (!response.ok) {
throw new Error(`Failed to fetch ${DATA_PATH}: ${response.statusText}`);
}
const fileData = await response.json();
data.push(fileData);
}
console.log("Data fetched:", data);
// Set map bounds, zoom
var mapBounds = new L.LatLngBounds(
new L.LatLng(-85.051129, -180),
new L.LatLng(85.051129, 180)
);
var mapMinZoom = 1;
var mapMaxZoom = 11;
map = L.map("map", { minZoom: 1, maxZoom: 11 }).setView(
[43.869281, -103.5264874],
6
);
// Add layers to map
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png").addTo(
map
);
overlay = L.tileLayer(
"https://cawm.lib.uiowa.edu/tiles/{z}/{x}/{y}.png",
{
minZoom: mapMinZoom,
maxZoom: mapMaxZoom,
bounds: mapBounds,
opacity: 1,
}
).addTo(map);
filterDataPoints(0); // Initialize with the first time range
} catch (error) {
console.error("Error during initialization:", error);
}
}
function filterDataPoints(selectedTime) {
console.log("Filtering data points for selected time:", selectedTime);
// Remove existing data points from the map
if (typeof window.dataLayer !== "undefined") {
map.removeLayer(window.dataLayer);
}
let filteredData = [];
data.forEach(dataset => {
filteredData = filteredData.concat(dataset.features.filter(function (feature) {
var startTime = parseInt(feature.properties.startTime, 10);
var endTime = parseInt(feature.properties.endTime, 10);
console.log(
"Feature:",
feature.properties,
"Start Time:",
startTime,
"End Time:",
endTime
);
return selectedTime >= startTime && selectedTime <= endTime;
}));
});
console.log("Filtered data:", filteredData);
// Add filtered data points to the map with popups
window.dataLayer = L.geoJSON(filteredData, {
pointToLayer: function (feature, latlng) {
const site = feature.properties.site;
const icon = iconMappings[site] || L.icon({ iconUrl: 'path/to/defaultIcon.png', iconSize: [32, 32], iconAnchor: [16, 32] }); // Fallback to a default icon if no match
return L.marker(latlng, { icon: icon });
},
onEachFeature: function (feature, layer) {
if (feature.properties) {
const name = feature.properties.name || 'No Name';
const popupContent = `<h3>${name}</h3><p>${feature.properties.popupContent || 'No Content'}</p>`;
console.log("Popup Content:", popupContent); // Log popup content
// Use L.responsivePopup for responsive popups
const popup = L.responsivePopup({ autoPanPadding: [50,50] })
.setContent(popupContent);
// Mouseover popup functionality with responsive popup
layer.on('mouseover', function (e) {
popup.setLatLng(e.latlng).openOn(map);
});
}
},
style: function (feature) {
return {
weight: 2,
color: 'grey',
opacity: .6,
fillColor: null, // No fill color
fillOpacity: 0 // Ensure no fill opacity
};
}
}).addTo(map);
}
// Initialize the map and data fetching
window.onload = init;
</script>
</body>
</html>