nau-sidewalks/static/index.html

109 lines
3.1 KiB
HTML
Raw Permalink Normal View History

2025-02-11 00:14:58 -06:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NAU Sidewalk Map</title>
<link rel="stylesheet" href="/leaflet/leaflet.css" />
<style>
body {
margin: 0;
}
#map {
height: 100vh;
width: 100%;
background-color: black;
}
.grayscale {
filter: saturate(0.4);
}
2025-02-11 00:14:58 -06:00
</style>
<!-- TODO: self-host -->
<link rel="stylesheet" href="https://mfhsieh.github.io/leaflet-simple-locate/examples/demo.css" />
</head>
<body>
<div id="map"></div>
<script src="/leaflet/leaflet.js"></script>
<!-- TODO: self-host -->
<script src="https://mfhsieh.github.io/leaflet-simple-locate/dist/leaflet-simple-locate.min.js"></script>
<script>
const map = L.map('map').fitBounds([[35.171563,-111.661606],[35.195695,-111.647701]]);
// Set up the OpenStreetMap tile layer
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
opacity: 0.6,
className: 'grayscale',
2025-02-11 00:14:58 -06:00
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
const CONDITIONS = [
{name: "Unknown", color: "#444"},
{name: "Clear", color: "#04591b"},
{name: "Partially Covered", color: "yellow"},
2025-02-11 00:14:58 -06:00
{name: "Covered", color: "red"},
];
fetch('api/sidewalks')
.then(response => response.json())
.then(osmData => {
// Function to create the polyline and popup for each OSM way
for (let [i, way] of osmData.entries()) {
const polyline = L.polyline(way.Geometry, {
color: CONDITIONS[way.Condition].color,
weight: 10,
2025-02-11 00:14:58 -06:00
opacity: 0.7
}).addTo(map);
polyline.on('mouseover', function(e) {
e.target.setStyle({
weight: 20,
2025-02-11 00:14:58 -06:00
opacity: 1,
});
});
polyline.on('mouseout', function(e){
e.target.setStyle({
weight: 10,
2025-02-11 00:14:58 -06:00
opacity: 0.7,
});
});
// Create a popup with the tags when clicking on the polyline
const extraContent = {
Condition: CONDITIONS[way.Condition].name,
Description: way.Description,
LastUpdated: way.LastUpdated,
};
const tagsContent = Object.entries({...extraContent/*, ...way.Tags*/}).map(([key, value]) => {
return `<b>${key}:</b> ${value}`;
}).join('<br>');
let buttons = "";
for (let [val, condition] of CONDITIONS.slice(1).entries()) {
buttons += `
<form method="POST" action="/api/sidewalks/${i}">
<input type="hidden" name="condition" value="${val+1}">
<button type="submit">${condition.name}</button>
</form>
`;
}
polyline.bindPopup(tagsContent+"<br>"+buttons);
}
})
.catch(error => {
console.error('Error loading OSM data:', error);
});
const control = new L.Control.SimpleLocate({
position: "topleft",
className: "button-locate",
}).addTo(map);
</script>
</body>
</html>