-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaflet-geojson.html
47 lines (42 loc) · 1.77 KB
/
leaflet-geojson.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css" crossorigin="" />
<script src="https://unpkg.com/leaflet@1.8.0/dist/leaflet.js" crossorigin=""></script>
<title>Load 45MB raw GeoJSON with Leaflet</title>
<style>html, body, #map{margin: 0;width: 100%;height: 100%;}</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map').setView([46.92449275279298, 2.0698022338965183], 6);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
fetch('https://jsapi.maps.arcgis.com/sharing/rest/content/items/519765450c2a45c8938108e413b94293/data')
.then((response) => response.json())
.then(data => {
const values = data.features.map(e =>e.properties.medianIncome2015)
const max = Math.max(...values)
geojsonLayer = L.geoJson(data, {
style: function (feature) {
return {
fillColor: "#ffa500",
color: "#ffa500",
fillOpacity: feature.properties.medianIncome2015/max
}
},
onEachFeature: function (feature, layer) {
layer.bindPopup('<h1>'+feature.properties.nom+'</h1><p>Median income: '+feature.properties.medianIncome2015+'</p>');
layer.on('mouseover', function() { layer.openPopup(); });
layer.on('mouseout', function() { layer.closePopup(); });
}
})
map.addLayer(geojsonLayer);
});
</script>
</body>
</html>