-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestmap2.html
86 lines (72 loc) · 2.71 KB
/
testmap2.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
<!DOCTYPE html>
<html lang="en">
<head>
<base target="_top">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Quick Start - Leaflet</title>
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-kLaT2GOSpHechhsozzB+flnD+zUyjE2LlfWPgU04xyI=" crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-WBkoXOwTeyKclOHuWtc+i2uENFpDZ9YPdf5Hf+D7ewM=" crossorigin=""></script>
<script src="https://unpkg.com/[email protected]/dist/flatgeobuf-geojson.min.js"></script>
<script src="https://unpkg.com/json-formatter-js"></script>
<style>
html, body {
height: 100%;
margin: 0;
}
.leaflet-container {
height: 800px;
width: 1200px;
max-width: 100%;
max-height: 100%;
}
</style>
</head>
<body>
<h3> American Perimeter Trail Test 2</h3>
<div id="map"></div>
<script>
document.addEventListener("DOMContentLoaded", async () => {
// basic OSM Leaflet map
let map = L.map('map').setView([39, -98], 4);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
const response = await fetch('./data/vector/CaliforniaPrimary_v1.4.fgb');
for await (let feature of flatgeobuf.deserialize(response.body, undefined, handleHeaderMeta)) {
// Leaflet styling
const defaultStyle = {
color: 'blue',
weight: 2,
fillOpacity: 0.2,
};
// Add the feature to the map
L.geoJSON(feature, {
style: defaultStyle
}).on({
// highlight on hover
'mouseover': function(e) {
const layer = e.target;
layer.setStyle({
color: 'blue',
weight: 4,
fillOpacity: 0.7,
});
layer.bringToFront();
},
// remove highlight when hover stops
'mouseout': function(e) {
const layer = e.target;
layer.setStyle(defaultStyle);
}
})
// show some per-feature properties when clicking on the feature
.bindPopup(`<h1>${feature.properties["status"]} ${feature.properties["partner"]}, ${feature.properties["state"]}</h1>`)
.addTo(map);
}
});
</script>
</body>
</html>