From 8b741d39901d98c0c0cc38ce7f3e70be6214ccd2 Mon Sep 17 00:00:00 2001 From: Alexis POYEN <apoyen@grandlyon.com> Date: Mon, 17 Aug 2020 11:34:51 +0200 Subject: [PATCH] fix : when changing filter, empty the map before coloration --- web/components/visualization/results-map.js | 30 +++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/web/components/visualization/results-map.js b/web/components/visualization/results-map.js index 3fdb314..98e2961 100644 --- a/web/components/visualization/results-map.js +++ b/web/components/visualization/results-map.js @@ -30,7 +30,10 @@ class MapComponent { let election = await this.ElectionModel.getElection( this.parent.parent.round.ElectionID ); - await this.initMap(election.MapSectionFile.replace("web/", ""), this.colorSections); + await this.initMap( + election.MapSectionFile.replace("web/", ""), + this.colorSections + ); } async initMap(mapFile, colorationFunction) { @@ -118,6 +121,14 @@ class MapComponent { } async colorAreas(mapHandler, dataSource) { + for (let tile of dataSource.features) { + dataSource = mapHandler.colorTiles( + dataSource, + tile.properties.gid, + "", + "" + ); + } for (let area of mapHandler.parent.parent.results.areasResults) { if (area.status == mapHandler.parent.parent.filter) { let party = await mapHandler.PartyModel.getParty( @@ -129,15 +140,21 @@ class MapComponent { party.Name, party.Color ); - } else { - dataSource = mapHandler.colorTiles(dataSource, area.MapID, "", ""); } } return dataSource; } async colorSections(mapHandler, dataSource) { - mapHandler.parent.parent.results.areasResults.forEach(async (area) => { + dataSource.features.forEach((tile) => { + dataSource = mapHandler.colorTiles( + dataSource, + tile.properties.gid, + "", + "" + ); + }); + for (let area of mapHandler.parent.parent.results.areasResults) { for (let section of area.Sections) { if (section.status == mapHandler.parent.parent.filter) { let party = await mapHandler.PartyModel.getParty( @@ -149,11 +166,9 @@ class MapComponent { party.Name, party.Color ); - } else { - dataSource = mapHandler.colorTiles(dataSource, section.MapID, "", ""); } } - }); + } return dataSource; } @@ -165,7 +180,6 @@ class MapComponent { if (f.properties.gid === gid) { f.properties.partyName = partyName; f.properties.color = color; - break; } } -- GitLab