-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
84 lines (77 loc) · 2.95 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
<!DOCTYPE html>
<html>
<head>
<title>Filtered Weather Data Map</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css"/>
<style>
html, body {
height: 100%;
margin: 0;
}
#map {
width: 100%;
height: 100%;
}
.value-label {
font-size: 6px;
color: black;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script>
var map = L.map('map').fitWorld(); // Initially fit the world view
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/Ocean/World_Ocean_Base/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Modified Jul 8 © <a href="https://www.esri.com/">Esri</a> contributors © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
subdomains: 'abcd',
maxZoom: 19
}).addTo(map);
function getColor(value) {
// Generate color from value
const maxVal = 100;
const minVal = 0;
const valRange = maxVal - minVal;
const percentage = (value - minVal) / valRange;
const hue = (1 - percentage) * 240; // From blue to red
return `hsl(${hue}, 100%, 50%)`;
}
fetch('http/weather_filtered.geojson')
.then(function(response) {
return response.json();
})
.then(function(data) {
var geojsonLayer = L.geoJSON(data, {
style: function (feature) {
var value = feature.properties.value;
var fillColor = getColor(value);
return {
color: "none", // Remove the outline
fillColor: fillColor,
fillOpacity: 0.5
};
},
onEachFeature: function (feature, layer) {
// Create a divIcon for the value label
var value = feature.properties.value;
var label = L.divIcon({
className: 'value-label',
html: value
});
// Calculate the center of the hex to position the label
var coords = feature.geometry.coordinates[0];
var latlngs = coords.map(function(c) { return [c[1], c[0]]; });
var polygon = L.polygon(latlngs);
var center = polygon.getBounds().getCenter();
L.marker(center, { icon: label }).addTo(map);
}
}).addTo(map);
// Fit the map to the bounds of the geojson layer
map.fitBounds(geojsonLayer.getBounds());
});
</script>
</body>
</html>