Skip to content

Commit

Permalink
SKY30-404 - Add a GFW layer
Browse files Browse the repository at this point in the history
  • Loading branch information
clementprdhomme committed Oct 23, 2024
1 parent 9cfb925 commit b4f907c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/.env.default
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ NEXT_PUBLIC_GOOGLE_ANALYTICS=

NEXT_PUBLIC_MAPBOX_API_TOKEN=
HUBSPOT_TOKEN=
NEXT_PUBLIC_GLOBAL_FISHING_WATCH_TOKEN=

LOCALAZY_CDN=

Expand Down
27 changes: 27 additions & 0 deletions frontend/src/components/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,33 @@ export const Map: FC<CustomMapProps> = ({
mapStyle="mapbox://styles/skytruth/clnud2d3100nr01pl3b4icpyw"
dragRotate={false}
touchZoomRotate={false}
transformRequest={(url) => {
// Global Fishing Watch tilers require authorization token and we're also passing the past
// 12 months as a parameter
if (url.startsWith('https://gateway.api.globalfishingwatch.org/')) {
const endDate = new Date();
const startDate = new Date(endDate);
startDate.setMonth(endDate.getMonth() - 12);

const formatDate = (date: Date): string => {
return date.toISOString().split('T')[0];
};

const newURL = url.replace(
'{{LAST_YEAR}}',
`${formatDate(startDate)},${formatDate(endDate)}`
);

return {
url: newURL,
headers: {
Authorization: `Bearer ${process.env.NEXT_PUBLIC_GLOBAL_FISHING_WATCH_TOKEN}`,
},
};
}

return null;
}}
{...mapboxProps}
{...localViewState}
>
Expand Down

0 comments on commit b4f907c

Please sign in to comment.