-
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.
Merge branch 'develop' of github.com:hotosm/drone-tm into feat/reproj…
…ect-orthophoto-to-epsg3857
- Loading branch information
Showing
8 changed files
with
95 additions
and
92 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
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
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