-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Vizzuality/feature/country-layer
Country layer
- Loading branch information
Showing
21 changed files
with
10,613 additions
and
6,988 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
client/src/components/map/layers/countries-layer/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { useEffect, useMemo } from "react"; | ||
|
||
import { Source, Layer, GeoJSONSourceRaw } from "react-map-gl"; | ||
|
||
import { Feature } from "geojson"; | ||
|
||
import { useGetCountries } from "@/types/generated/country"; | ||
import { LayerDataset } from "@/types/generated/strapi.schemas"; | ||
import { Config, LayerProps } from "@/types/layers"; | ||
|
||
export type CountriesLayerProps = LayerProps & { | ||
config: Config; | ||
dataset?: LayerDataset; | ||
beforeId?: string; | ||
}; | ||
|
||
const CountriesLayer = ({ beforeId, dataset, config, onAdd, onRemove }: CountriesLayerProps) => { | ||
const { data: countriesData } = useGetCountries({ | ||
"pagination[pageSize]": 100, | ||
}); | ||
|
||
const SOURCE = useMemo(() => { | ||
if (!countriesData?.data?.data) return null; | ||
|
||
return { | ||
type: "geojson", | ||
data: { | ||
type: "FeatureCollection", | ||
features: countriesData.data.data.map((c) => ({ | ||
type: "Feature", | ||
geometry: c.attributes?.geometry as Feature["geometry"], | ||
properties: { | ||
id: c.id, | ||
name: c.attributes?.name, | ||
...(dataset?.data?.attributes?.datum as Record<string, unknown>[])?.find( | ||
(d) => d.iso3 === c.attributes?.iso3, | ||
), | ||
}, | ||
})), | ||
}, | ||
} satisfies GeoJSONSourceRaw; | ||
}, [countriesData, dataset?.data?.attributes?.datum]); | ||
|
||
const STYLES = config.styles; | ||
|
||
useEffect(() => { | ||
if (SOURCE && STYLES && onAdd) { | ||
onAdd({ | ||
source: SOURCE, | ||
styles: STYLES, | ||
}); | ||
} | ||
|
||
return () => { | ||
if (SOURCE && STYLES && onRemove) { | ||
onRemove({ | ||
source: SOURCE, | ||
styles: STYLES, | ||
}); | ||
} | ||
}; | ||
}, []); // eslint-disable-line react-hooks/exhaustive-deps | ||
|
||
if (!SOURCE || !STYLES) return null; | ||
|
||
return ( | ||
<Source {...SOURCE}> | ||
{STYLES.map((layer) => ( | ||
<Layer key={layer.id} {...layer} beforeId={beforeId} /> | ||
))} | ||
</Source> | ||
); | ||
}; | ||
|
||
export default CountriesLayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Open_Sans } from "next/font/google"; | ||
import localFont from "next/font/local"; | ||
|
||
export const openSans = Open_Sans({ | ||
subsets: ["latin"], | ||
variable: "--font-open-sans", | ||
fallback: ["system-ui", "Helvetica Neue", "Helvetica", "Arial"], | ||
weight: ["300"], | ||
style: ["italic", "normal"], | ||
display: "block", | ||
}); | ||
|
||
export const metropolis = localFont({ | ||
src: [ | ||
{ | ||
path: "./Metropolis-Black.woff2", | ||
weight: "900", | ||
style: "normal", | ||
}, | ||
], | ||
display: "block", | ||
variable: "--font-metropolis", | ||
}); |
File renamed without changes.
Oops, something went wrong.