-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update MapLibre and Integrate COG Protocol for Efficient Orthophoto R…
…endering (#334) * feat: add `COGOrthophotoViewer` component * feat: add `@geomatico/maplibre-cog-protocol` and update `maplibre-gl` version to support COG file * feat: implement `COGOrthophotoViewer` to preview task orthophoto * feat: add s3 endpoint to vite `defineConfig` * feat(orthophoto-preview): add dynamic source with the url prepended with `cog://` to preview orthophoto --------- Co-authored-by: Sujit <[email protected]>
- Loading branch information
Showing
4 changed files
with
70 additions
and
75 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
49 changes: 49 additions & 0 deletions
49
src/frontend/src/components/common/MapLibreComponents/COGOrthophotoViewer/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,49 @@ | ||
import { useEffect } from 'react'; | ||
import mapLibre, { RasterSourceSpecification } from 'maplibre-gl'; | ||
import { cogProtocol } from '@geomatico/maplibre-cog-protocol'; | ||
import { MapInstanceType } from '../types'; | ||
|
||
interface IViewOrthophotoProps { | ||
map?: MapInstanceType; | ||
isMapLoaded?: Boolean; | ||
id: string; | ||
source: RasterSourceSpecification; | ||
visibleOnMap?: Boolean; | ||
} | ||
|
||
const COGOrthophotoViewer = ({ | ||
map, | ||
isMapLoaded, | ||
id, | ||
source, | ||
visibleOnMap, | ||
}: IViewOrthophotoProps) => { | ||
useEffect(() => { | ||
if (!map || !isMapLoaded || !source || !visibleOnMap) return; | ||
|
||
// Registers the 'cog' protocol with the mapLibre instance, enabling support for Cloud Optimized GeoTIFF (COG) files | ||
mapLibre?.addProtocol('cog', cogProtocol); | ||
|
||
if (!map.getSource(id)) { | ||
map.addSource(id, source); | ||
map.addLayer({ | ||
id, | ||
source: id, | ||
layout: {}, | ||
...source, | ||
}); | ||
} | ||
|
||
// eslint-disable-next-line consistent-return | ||
return () => { | ||
if (map?.getSource(id)) { | ||
map?.removeSource(id); | ||
if (map?.getLayer(id)) map?.removeLayer(id); | ||
} | ||
}; | ||
}, [map, isMapLoaded, id, source, visibleOnMap]); | ||
|
||
return null; | ||
}; | ||
|
||
export default COGOrthophotoViewer; |
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