-
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.
Client/feature/animated tile layer (#47)
* Update mapbox version * Refactor animated tile layer to be used with deck-json-layer * Add env variables for mapbox username and style id
- Loading branch information
1 parent
24f228e
commit 9bfe7e0
Showing
33 changed files
with
538 additions
and
460 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Public url. Canonical url of the project. | ||
NEXT_PUBLIC_URL= | ||
|
||
# Environment. Only for development. It will be provided by Vercel otherwise. | ||
NEXT_PUBLIC_ENVIRONMENT= | ||
|
||
# API Url. | ||
# Development, Preview, Production | ||
# Depending on the environment we will use different urls. It can be the same for the storybook and for the project. | ||
NEXT_PUBLIC_API_URL= | ||
NEXT_PUBLIC_BASE_PATH= | ||
NEXT_PUBLIC_PREVIEW_SECRET= | ||
# Mapbox token | ||
# Development, Preview, Production | ||
# corresponding to the account used for this project. It can be the same for the storybook and for the project. | ||
NEXT_PUBLIC_MAPBOX_API_TOKEN= | ||
NEXT_PUBLIC_MAPBOX_USERNAME= | ||
NEXT_PUBLIC_MAPBOX_STYLE_ID= | ||
|
||
# Google Analytics tracking ID. | ||
# Development, Preview, Production | ||
# If you're working with an Google Analytics 4 property, you have a Measurement ID instead of a Tracking ID. | ||
NEXT_PUBLIC_GA_TRACKING_ID= | ||
|
||
# Recoil: Remove warnings about duplicate atoms due to hot-reloading | ||
# Development | ||
RECOIL_DUPLICATE_ATOM_KEY_CHECKING_ENABLED=false |
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
217 changes: 0 additions & 217 deletions
217
client/src/components/map/layers/animated-tile-layer/index.tsx
This file was deleted.
Oops, something went wrong.
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,89 @@ | ||
import { TileLayer } from '@deck.gl/geo-layers'; | ||
import { BitmapLayer } from '@deck.gl/layers'; | ||
import parseAPNG from 'apng-js'; | ||
import { RasterSource } from 'mapbox-gl'; | ||
|
||
import { LayerProps } from '@/types/layers'; | ||
|
||
export interface AnimatedTileProps extends LayerProps { | ||
source: RasterSource; | ||
opacity: number; | ||
visibility: boolean; | ||
beforeId: string; | ||
decodeFunction: string; | ||
decodeParams: Record<string, unknown>; | ||
frame: number; | ||
} | ||
|
||
export class AnimatedTile { | ||
constructor({ id, source, visibility = true, opacity = 1, frame = 0 }: AnimatedTileProps) { | ||
return new TileLayer({ | ||
id, | ||
frame, | ||
tileSize: source.tileSize ?? 256, | ||
minZoom: source.minzoom, | ||
maxZoom: source.maxzoom, | ||
visible: visibility ?? true, | ||
opacity: opacity ?? 1, | ||
refinementStrategy: 'no-overlap', | ||
getTileData: (tile: any) => { | ||
const { | ||
index: { x, y, z }, | ||
signal, | ||
} = tile; | ||
if (!source.url) return null; | ||
const tileUrl = source.url.replace('{z}', z).replace('{x}', x).replace('{y}', y); | ||
|
||
const response = fetch(tileUrl, { signal }); | ||
|
||
if (signal.aborted) { | ||
return null; | ||
} | ||
|
||
return response | ||
.then((res) => res.arrayBuffer()) | ||
.then((buffer) => { | ||
const apng = parseAPNG(buffer); | ||
if (apng instanceof Error) { | ||
return null; | ||
} | ||
return apng.frames.map((f: any) => { | ||
return { | ||
...f, | ||
bitmapData: createImageBitmap(f.imageData), | ||
}; | ||
}); | ||
}); | ||
}, | ||
renderSubLayers: (sl: any) => { | ||
if (!sl) return null; | ||
|
||
const { id: subLayerId, data, tile, visible, opacity = 1, frame: f } = sl; | ||
|
||
if (!tile || !data) return null; | ||
|
||
const { | ||
zoom, | ||
bbox: { west, south, east, north }, | ||
} = tile; | ||
|
||
const FRAME = data[f]; | ||
|
||
if (FRAME) { | ||
return new BitmapLayer({ | ||
id: subLayerId, | ||
image: FRAME.bitmapData, | ||
bounds: [west, south, east, north], | ||
getPolygonOffset: () => { | ||
return [0, 20000]; | ||
}, | ||
zoom, | ||
visible, | ||
opacity, | ||
}); | ||
} | ||
return null; | ||
}, | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.