Skip to content

Commit

Permalink
working federal electoral district data #74
Browse files Browse the repository at this point in the history
  • Loading branch information
Scobiform committed Oct 20, 2024
1 parent 3f861f7 commit 5cd22c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/components/Map/DynamicMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ const DynamicMap = ({ polygons = [],
// parentNr
electoralDistrict = properties.parentNr;
break;
case 'bundestag':
electoralDistrict = properties.WKR_NR;
break;
default:
console.warn(`State '${state}' not recognized.`);
electoralDistrict = null; // Fallback in case of an unrecognized state
Expand Down Expand Up @@ -217,7 +220,8 @@ const DynamicMap = ({ polygons = [],
berlin: electIT,
brandenburg: electIT,
hessen: rlphessen,
rlp: rlphessen
rlp: rlphessen,
bundestag: electIT,
};

const handler = stateHandlers[state] || ((feature, layer) => {
Expand All @@ -230,7 +234,6 @@ const DynamicMap = ({ polygons = [],
handler(feature, layer, state);
};


return (
<>
{/* Conditionally render LoadingSpinner */}
Expand Down Expand Up @@ -298,7 +301,7 @@ const DynamicMap = ({ polygons = [],
{selectedMap === 'bundestag' && (
<GeoJSON data={bundestagGeoData}
style={() => ({ color: 'green', weight: 1, fillColor: 'green', fillOpacity: 0.1 })}
onEachFeature={onEachFeature}
onEachFeature={(feature, layer) => onEachFeature(feature, layer, 'bundestag')}
/>
)}

Expand Down
14 changes: 8 additions & 6 deletions src/pages/api/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ async function scrapeVoterTurnoutChart(page) {
}
}





export default async function handler(req, res) {
let browser;
const { electoralDistrict, state } = req.query;
Expand Down Expand Up @@ -212,7 +208,13 @@ export default async function handler(req, res) {
break;
case 'brandenburg':
await page.goto(`https://wahlergebnisse.brandenburg.de/12/500/20240922/landtagswahl_land/ergebnisse_wahlkreis_${electoralDistrict}.html`, { waitUntil: 'domcontentloaded' });
break;
break;
case 'bundestag':
console.log('Scraping data for Bundestag');
let url = `https://www.bundeswahlleiter.de/bundestagswahlen/2021/ergebnisse/bund-99/land-12/wahlkreis-${electoralDistrict}.html`;
console.log(url);
await page.goto(url, { waitUntil: 'domcontentloaded' });
break;
}

// Wait for the table to appear
Expand Down Expand Up @@ -250,7 +252,7 @@ export default async function handler(req, res) {

// Scrape all SVG elements
let svgData = null;
if(state !== 'berlin') {
if(state !== 'berlin' || state !== 'bundestag') {
svgData = await scrapeAllSVGs(page);
}

Expand Down

0 comments on commit 5cd22c2

Please sign in to comment.