-
Notifications
You must be signed in to change notification settings - Fork 0
/
4-map-leaflet-trees.html
57 lines (54 loc) · 1.76 KB
/
4-map-leaflet-trees.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>4 - Trees</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/tailwind.min.css" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
</head>
<body>
<div id="map" class="absolute top-0 bottom-0 w-full"></div>
<script>
const citylayer = L.tileLayer("./citymap-mercator/{z}/{x}/{y}.png", {
tms: true
});
const map = L.map("map", {
center: [47.9957644517, 7.85278691645],
zoom: 14,
minZoom: 12,
maxZoom: 17,
layers: [citylayer]
});
const treeStyle = {
radius: 8,
fillColor: "#009900",
weight: 0,
fillOpacity: 0.5
};
fetch(`./trees-small.json`).then(response => response.json())
.then(trees => {
L.geoJSON(trees, {
pointToLayer: function (feature, latlng) {
const style = feature.properties.genus
? { ...treeStyle, color: "#ffffff", weight: 2 }
: treeStyle
return L.circleMarker(latlng, style);
},
style: function(feature) {
switch (feature.properties.leaf_type) {
case 'needleleaved': return { fillColor: "#005555" };
case 'broadleaved': return { fillColor: "#555500" };
}
},
onEachFeature: function (feature, layer) {
if (feature.properties.genus) {
layer.bindPopup(feature.properties.genus);
}
}
}).addTo(map);
})
</script>
</body>
</html>