-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcog_map_step_05.html
More file actions
107 lines (90 loc) · 3.65 KB
/
Copy pathcog_map_step_05.html
File metadata and controls
107 lines (90 loc) · 3.65 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<base target="_top">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Stanford Campus Map - Step 4: Add Popups</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<script src="https://unpkg.com/proj4"></script>
<script src="https://unpkg.com/georaster"></script>
<script src="https://unpkg.com/georaster-layer-for-leaflet"></script>
<style>
html, body {
height: 100%;
margin: 0;
}
.leaflet-container {
height: 600px;
width: 800px;
max-width: 100%;
max-height: 100%;
}
</style>
</head>
<body>
<h1>Stanford Public Art Map</h1>
<p>Step 5: Add a Cloud Optimized GEOTIFF (COG)</p>
<div id="map" style="width: 800px; height: 600px;"></div>
<script>
// Initialize map centered on Stanford campus
const map = L.map('map').setView([37.427, -122.169], 15);
// Add OpenStreetMap tile layer
const tiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
// add COG layer using georaster-layer-for-leaflet
var url_to_geotiff_file = new URL("../stanford_campus_irg.tif", window.location.href).href;
parseGeoraster(url_to_geotiff_file).then(georaster => {
console.log("georaster:", georaster);
fetch("../stanford_campus.geojson")
.then(r => r.json())
.then(maskGeojson => {
var layer = new GeoRasterLayer({
attribution: "Planet",
georaster: georaster,
resolution: 128,
mask: maskGeojson
});
layer.addTo(map);
map.fitBounds(layer.getBounds());
});
}).catch(console.error);
// Load GeoJSON data
fetch('../stanford_public_art.geojson')
.then(response => response.json())
.then(data => {
// Add GeoJSON layer with custom circle markers and popups
const artworkLayer = L.geoJSON(data, {
pointToLayer: function(feature, latlng) {
return L.circleMarker(latlng, {
radius: 6,
color: 'white',
weight: 2,
fillColor: 'blue',
fillOpacity: 0.7
});
},
onEachFeature: function(feature, layer) {
const props = feature.properties || {};
const title = props.name || 'Artwork';
const artist = props.artist_name;
const type = props.artwork_type;
// Build popup content
let popupContent = '<div style="min-width:200px;">';
popupContent += '<b>' + title + '</b><br>';
if (artist) popupContent += '<b>Artist:</b> ' + artist + '<br>';
if (type) popupContent += '<b>Type:</b> ' + type;
popupContent += '</div>';
layer.bindPopup(popupContent);
}
}).addTo(map);
// Zoom to fit all markers
map.fitBounds(artworkLayer.getBounds());
})
.catch(error => console.error('Error loading GeoJSON:', error));
</script>
</body>
</html>