Performance adjustments for project 2 aufgabe 1

This commit is contained in:
Marcel Schwarz 2020-11-12 17:13:51 +01:00
parent 3f1476b609
commit 705a701a8e

View File

@ -9,24 +9,24 @@ const aufgabe1 = () => {
const levels = [0, 20, 50, 100, 200, 250, 300, 400]
let geojson;
const getColor = population => {
const getColor = density => {
switch (true) {
case population > levels[7]:
case density > levels[7]:
return '#800026'
case population > levels[6]:
case density > levels[6]:
return '#BD0026'
case population > levels[5]:
case density > levels[5]:
return '#E31A1C'
case population > levels[4]:
case density > levels[4]:
return '#FC4E2A'
case population > levels[3]:
case density > levels[3]:
return '#FD8D3C'
case population > levels[2]:
case density > levels[2]:
return '#FEB24C'
case population > levels[1]:
case density > levels[1]:
return '#FED976'
case population > levels[0]:
return '#ffdb83'
case density > levels[0]:
return '#FFEDA0'
default:
return '#ffdea1'
}
@ -40,9 +40,10 @@ const aufgabe1 = () => {
const labels = []
for (let i = 0; i < levels.length; i++) {
let from = levels[i] + 1
let to = levels[i + 1] + 1
labels.push('<i style="background:' + getColor(levels[i] + 1) + '"></i> ' + from + (to ? '&ndash;' + to : '+'))
labels.push(
'<i style="background:' + getColor(levels[i] + 1) + '"></i> '
+ levels[i] + (levels[i + 1] ? '&ndash;' + levels[i + 1] : '+')
)
}
legend.innerHTML = labels.join('<br>')
@ -109,9 +110,7 @@ const aufgabe1 = () => {
// Load data in
$.getJSON('europe.geo.json', data => {
for (let [idx, country] of data.features.entries()) {
data.features[idx].properties.density = country.properties.pop_est / (turf.area(country) / 1_000_000)
}
data.features.map(feature => feature.properties.density = feature.properties.pop_est / (turf.area(feature) / 1_000_000))
geojson = L.geoJson(data, {style: getStyle, onEachFeature}).addTo(map)
})