From 1adfc9be6e683b287d79c58c8dc837d29936f51e Mon Sep 17 00:00:00 2001 From: apoyen <apoyen@grandlyon.com> Date: Wed, 29 Jul 2020 14:23:21 +0200 Subject: [PATCH] Fix : update map when votes are updated --- web/components/visualization/results-map.js | 7 +++---- web/components/visualization/results-zone.js | 14 ++++++++++++++ .../visualization/visualization-section.js | 5 +++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/web/components/visualization/results-map.js b/web/components/visualization/results-map.js index 520c0c4..28e7276 100644 --- a/web/components/visualization/results-map.js +++ b/web/components/visualization/results-map.js @@ -27,10 +27,10 @@ class MapComponent { const request = new XMLHttpRequest(); request.open("GET", mapFile, false); request.send(null); - let dataSource = JSON.parse(request.responseText); + this.dataSource = JSON.parse(request.responseText); // Add parties and colors to datasource - dataSource = await colorationFunction(this, dataSource); + this.dataSource = await colorationFunction(this, this.dataSource); document.getElementById("map-component").innerHTML = ""; // Create a popup, but don't add it to the map yet. @@ -48,7 +48,7 @@ class MapComponent { this.map.on("load", () => { this.map.addSource("data-source", { type: "geojson", - data: dataSource, + data: this.dataSource, }); this.map.addLayer( @@ -127,7 +127,6 @@ class MapComponent { async colorSections(mapHandler, dataSource) { mapHandler.parent.parent.results.areasResults.forEach(async (area) => { - console.log(area.Sections); for (let section of area.Sections) { if (section.status == mapHandler.parent.parent.filter) { let party = await mapHandler.PartyModel.getParty( diff --git a/web/components/visualization/results-zone.js b/web/components/visualization/results-zone.js index 05be9f4..c4fc0b3 100644 --- a/web/components/visualization/results-zone.js +++ b/web/components/visualization/results-zone.js @@ -231,9 +231,23 @@ class ResultZoneComponent { if (this.parent.zone === "areas") { await this.ResultsFlow.displayFlowAreas(); this.ResultsDetaileds.displayAreasResults(); + if (this.ResultsMap.map.getSource("data-source") !== undefined) { + let dataSource = await this.ResultsMap.colorAreas( + this.ResultsMap, + this.ResultsMap.dataSource + ); + this.ResultsMap.map.getSource("data-source").setData(dataSource); + } } else if (this.parent.zone === "sections") { await this.ResultsFlow.displayFlowSections(); this.ResultsDetaileds.displaySectionsResults(); + if (this.ResultsMap.map.getSource("data-source") !== undefined) { + let dataSource = await this.ResultsMap.colorSections( + this.ResultsMap, + this.ResultsMap.dataSource + ); + this.ResultsMap.map.getSource("data-source").setData(dataSource); + } } } diff --git a/web/components/visualization/visualization-section.js b/web/components/visualization/visualization-section.js index a58d6db..47beaf5 100644 --- a/web/components/visualization/visualization-section.js +++ b/web/components/visualization/visualization-section.js @@ -104,14 +104,12 @@ class ResultComponent { await this.hideGeneralSection(); document.getElementById("sections").setAttribute("class", ""); document.getElementById("areas").setAttribute("class", "is-active"); - this.resultsZone.ResultsMap.displayMapAreas(); }); document.getElementById("sections").addEventListener("click", async () => { resultHandler.zone = "sections"; await this.hideGeneralSection(); document.getElementById("areas").setAttribute("class", ""); document.getElementById("sections").setAttribute("class", "is-active"); - this.resultsZone.ResultsMap.displayMapSections(); }); let radioButtons = document.getElementsByName("filter"); @@ -136,6 +134,9 @@ class ResultComponent { document.getElementById("results-zone").style.display = "flex"; document.getElementById("results-general").style.display = "none"; await resultHandler.calculateResults(); + if (resultHandler.zone == "areas") + await this.resultsZone.ResultsMap.displayMapAreas(); + else await this.resultsZone.ResultsMap.displayMapSections(); await resultHandler.resultsZone.displayResults(); } -- GitLab