From f9ea03e64c322b0f962d0d8cdf689d2509a0bd17 Mon Sep 17 00:00:00 2001 From: louai98 Date: Thu, 6 Jun 2024 15:55:38 +0200 Subject: [PATCH] show/hide info box and filter, languages --- .../ControlInAfrica/ControlInAfricaMap.js | 154 ++------- .../Layout/ControlInAfrica/FilterBox.jsx | 74 ++-- .../Layout/ControlInAfrica/Geo_Org_Filter.jsx | 47 +-- .../Layout/ControlInAfrica/LanguageSelect.jsx | 41 +++ .../Layout/ControlInAfrica/MapInfoBox.jsx | 327 +++++++++--------- .../Layout/ControlInAfrica/Reg_Org_Filter.jsx | 7 +- .../ControlInAfrica/Treaties_Filter.jsx | 94 +++-- src/Styles/Layout/_filters.scss | 8 + src/Styles/Layout/_map.scss | 58 ++-- src/Styles/Layout/_map_info_box.scss | 14 +- src/Styles/Utilities/_variables.scss | 4 +- src/tmp/orgs.txt | 185 +++++----- 12 files changed, 523 insertions(+), 490 deletions(-) create mode 100644 src/Components/Layout/ControlInAfrica/LanguageSelect.jsx diff --git a/src/Components/Layout/ControlInAfrica/ControlInAfricaMap.js b/src/Components/Layout/ControlInAfrica/ControlInAfricaMap.js index 939f175..e385e43 100644 --- a/src/Components/Layout/ControlInAfrica/ControlInAfricaMap.js +++ b/src/Components/Layout/ControlInAfrica/ControlInAfricaMap.js @@ -74,7 +74,6 @@ class ControlInAfricaMap extends React.Component { super(props); this.mapRef = createRef(); // Create a ref to store the MapContainer instance - this.state = { africaCountries: null, countriesNames: [], @@ -88,8 +87,9 @@ class ControlInAfricaMap extends React.Component { error: null, center: [3, 15], - zoom: 4, - scrollWheelZoom: false, + zoom: this.getZoomLevel(window.innerWidth), + scrollWheelZoom: true, + zoomControl: false, openedTooltipLayer: null, @@ -112,116 +112,18 @@ class ControlInAfricaMap extends React.Component { infoBox: [], showInfoBox: false, }; + } - regional_organisations = [ - { name: "AU", color: "#b2df8a" }, - { name: "EAC", color: "#33a02c" }, - { name: "IGAD", color: "#fb9a99" }, - { name: "UMA", color: "#e31a1c" }, - { name: "COMESA", color: "#fdbf6f" }, - { name: "ECOWAS", color: "#ff7f00" }, - { name: "CEN-SAD", color: "#cab2d6" }, - { name: "SADC", color: "#6a3d9a" }, - { name: "ECCAS", color: "#ffff99" }, - { name: "ICGLR", color: "#b15928" }, - { name: "RECSA", color: "#a6cee3" }, - { name: "SARCOM", color: "#1f78b4" }, - ]; - - regional_treaties = [ - { - name: "Bamako Declaration", - name2: "BamakoDeclaration", - icon_eligible: Icon26, - icon_signed: Icon24, - icon_ratified: null, - }, - { - name: "Kinshasa Convention", - name2: "KinshasaConvention", - icon_eligible: Icon4, - icon_signed: Icon6, - icon_ratified: Icon5, - }, - { - name: "ECOWAS Convention", - name2: "ECOWASConvention", - icon_eligible: Icon2, - icon_signed: Icon3, - icon_ratified: null, - }, - { - name: "Khartoum Declaration", - name2: "KhartoumDeclaration", - icon_eligible: Icon21, - icon_signed: Icon23, - icon_ratified: null, - }, - { - name: "Nairobi Protocol", - name2: "NairobiProtocol", - icon_eligible: Icon22, - icon_signed: Icon25, - icon_ratified: null, - }, - { - name: "SADC Firearms Protocol", - name2: "SADCFirearmsProtocol", - icon_eligible: Icon8, - icon_signed: Icon7, - icon_ratified: Icon9, - }, - ]; - - international_treaties = [ - { - name: "Arms Trade Treaty", - name2: "ArmsTradeTreaty", - icon_eligible: Icon19, - icon_signed: Icon17, - icon_ratified: Icon18, - }, - { - name: "Firearms Protocol", - name2: "FirearmsProtocol", - icon_eligible: Icon12, - icon_signed: Icon10, - icon_ratified: Icon11, - }, - { - name: "Wassenaar Agreement", - name2: "WassenaarAgreement", - icon_eligible: Icon15, - icon_signed: Icon13, - icon_ratified: Icon14, - }, - ]; - intsruments = [ - { - name2: "UNProgrammeofAction", - name: "UN Programme of Action", - icon: Icon20, - }, - { - name2: "InternationalTracingInstrument", - name: "International Tracing Instrument", - icon: Icon16, - }, - { - name2: "StG-PoA", - name: "Silencing the Guns in Africa Programme of Action", - icon: Icon1, - }, - ]; componentDidMount() { this.fetchData(); - this.calculateZoomLevel(); - window.addEventListener("resize", this.calculateZoomLevel); + window.addEventListener("resize", this.handleResize); } - componentWillUnmount() {} + componentWillUnmount() { + window.removeEventListener('resize', this.handleResize); + } fetchData = async () => { try { @@ -251,7 +153,6 @@ class ControlInAfricaMap extends React.Component { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); - console.log(data); // Replace icon names with actual icon objects const regional_treaties = data.regional_treaties.map((treaty) => ({ ...treaty, @@ -290,17 +191,25 @@ class ControlInAfricaMap extends React.Component { } }; - calculateZoomLevel = () => { + getZoomLevel = () => { const screenWidth = window.innerWidth; - if (screenWidth <= 768) { - this.setState({ zoom: 3 }); + console.log(screenWidth); + if (screenWidth <= 800) { + console.log("small screen"); + return 3; } else if (screenWidth <= 1024) { - this.setState({ zoom: 4 }); + return 4; } else { - this.setState({ zoom: 4 }); + return 4; } }; + handleResize = () => { + this.setState({ + zoom: this.getZoomLevel(window.innerWidth), + }); + }; + resetMap = () => { if (this.mapRef.current) { this.mapRef.current.setView(this.state.center, this.state.zoom); // Set the center and zoom to initial values @@ -585,6 +494,7 @@ class ControlInAfricaMap extends React.Component { selectedCountriesFeaturesRegions, regional_treaties, international_treaties, + intsruments, } = this.state; // Helper function to process treaties @@ -619,7 +529,7 @@ class ControlInAfricaMap extends React.Component { international_treaties ); - const organisationsInstruments = this.intsruments.map((instrument) => { + const organisationsInstruments = intsruments.map((instrument) => { const countris = selectedCountriesFeaturesRegions.filter( (feature) => feature.properties[instrument.name2] === 1 ); @@ -678,6 +588,10 @@ class ControlInAfricaMap extends React.Component { africaCountries, loading, error, + zoom, + zoomControl, + center, + scrollWheelZoom, countriesNames, selectedCountry, selectedCountriesNamesRegions, @@ -701,7 +615,7 @@ class ControlInAfricaMap extends React.Component { return ( - + - +
{africaCountries && ( <> @@ -800,6 +714,7 @@ class ControlInAfricaMap extends React.Component {
+