diff --git a/projects/project-2/aufgabe3.js b/projects/project-2/aufgabe3.js index d7952f5..c1748d7 100644 --- a/projects/project-2/aufgabe3.js +++ b/projects/project-2/aufgabe3.js @@ -2,8 +2,8 @@ const aufgabe3 = async () => { const wantedYears = [2015, 2016, 2017] const wantedSeries = [ - {code: "SH_H2O_SAFE", displayName: "drinking water services"}, - {code: "SH_SAN_SAFE", displayName: "sanitation services"} + {code: "SH_H2O_SAFE", displayName: "drinking water"}, + {code: "SH_SAN_SAFE", displayName: "sanitation"} ] const levels = [0, 50.0, 80.0, 85.0, 90.0, 95.0, 99.0, 99.9] @@ -26,11 +26,9 @@ const aufgabe3 = async () => { let dataArrays = (await Promise.all(requests)).map(arr => arr.data.data) const values = [].concat(...dataArrays) return values.filter(elem => elem.dimensions.Location === "ALLAREA") - } const apiData = await Promise.all(wantedSeries.map(loadSeries)) return [].concat(...apiData) - } const getColor = percentage => { @@ -55,12 +53,12 @@ const aufgabe3 = async () => { } const map = L.map('suiMap', {zoomControl: false}).setView([53.0, 14.0], 4) - L.control.zoom({position: 'bottomleft'}).addTo(map) map.addLayer(new L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: 'Map data OpenStreetMap contributors', minZoom: 0, maxZoom: 18 })) + const [geojsonData, apiData] = await Promise.all([ $.getJSON('europe.geo.json'), loadData() @@ -116,8 +114,8 @@ const aufgabe3 = async () => { info.addTo(map) + // Create datalayer instances for series and year let layers = {} - for (let currSeries of wantedSeries) { for (let currYear of wantedYears) { let fullSeriesName = `${currSeries.code}_${currYear}` @@ -155,13 +153,44 @@ const aufgabe3 = async () => { }) } }) - layers[`${currSeries.displayName} ${currYear}`] = geoJsonLayer + layers[`${currSeries.code}_${currYear}`] = geoJsonLayer } } - map.addLayer(Object.values(layers)[0]) + // Create button layer selector + const layerSelector = L.control({position: "topright"}) + layerSelector._div = L.DomUtil.create("div", "info text-center") + layerSelector._div.id = "layerSelector" + layerSelector.onAdd = () => { + const createButtonGroup = (values, groupName) => { + let outer = `