-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CDC #248 - Creating separate components for react-map-gl and @periple…
…o/maplibre warped layer components
- Loading branch information
1 parent
3ce619c
commit 4dd6f0f
Showing
9 changed files
with
185 additions
and
51 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
56 changes: 56 additions & 0 deletions
56
packages/geospatial/src/components/WarpedImageLayerPeripleo.js
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,56 @@ | ||
// @flow | ||
|
||
import { useEffect } from 'react'; | ||
import { useLoadedMap } from '@peripleo/maplibre'; | ||
import MapUtils from '../utils/Map'; | ||
|
||
type Props = { | ||
/** | ||
* ID of the new layer. | ||
*/ | ||
id: string, | ||
|
||
/** | ||
* (Optional) IIIF manifest content containing the image and geo-reference annotations. | ||
*/ | ||
manifest?: string, | ||
|
||
/** | ||
* (Optional) layer opacity. | ||
*/ | ||
opacity?: number, | ||
|
||
/** | ||
* (Optional) URL to the IIIF manifest. | ||
*/ | ||
url?: string | ||
}; | ||
|
||
const WarpedImageLayer = (props: Props) => { | ||
const map = useLoadedMap(); | ||
|
||
/** | ||
* Adds the WarpedMapLayer object to the map as a new layer. | ||
*/ | ||
useEffect(() => { | ||
if (!map) { | ||
return undefined; | ||
} | ||
|
||
MapUtils.addGeoreferenceLayer(map, props.id, { | ||
manifest: props.manifest, | ||
opacity: props.opacity, | ||
url: props.url | ||
}); | ||
|
||
return () => MapUtils.removeLayer(map, props.id); | ||
}, [map]); | ||
|
||
return null; | ||
}; | ||
|
||
WarpedImageLayer.defaultProps = { | ||
opacity: 0.5 | ||
}; | ||
|
||
export default WarpedImageLayer; |
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
44 changes: 44 additions & 0 deletions
44
packages/storybook/src/geospatial/WarpedImageLayerPeripleo.stories.js
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,44 @@ | ||
// @flow | ||
|
||
import { Map as PeripleoMap, Zoom } from '@peripleo/maplibre'; | ||
import { Controls, Peripleo } from '@peripleo/peripleo'; | ||
import React from 'react'; | ||
import Env from '../utils/Environment'; | ||
import WarpedImageLayerPeripleo from '../../../geospatial/src/components/WarpedImageLayerPeripleo'; | ||
|
||
export default { | ||
title: 'Components/Geospatial/WarpedImageLayerPeripleo', | ||
component: WarpedImageLayerPeripleo | ||
}; | ||
|
||
const mapTilerKey = Env.getMapTilerKey(); | ||
const mapStyle = `https://api.maptiler.com/maps/basic-v2/style.json?key=${mapTilerKey}`; | ||
|
||
export const Default = () => ( | ||
<Peripleo> | ||
<PeripleoMap | ||
defaultBounds={[ | ||
[-74.123501, 40.679546], | ||
[-73.796486, 40.805444] | ||
]} | ||
style={mapStyle} | ||
> | ||
<Controls | ||
position='topright' | ||
> | ||
<Zoom /> | ||
</Controls> | ||
<div | ||
style={{ | ||
width: '100%', | ||
height: '500px' | ||
}} | ||
> | ||
<WarpedImageLayerPeripleo | ||
id='nyc' | ||
url='https://annotations.allmaps.org/images/d180902cb93d5bf2' | ||
/> | ||
</div> | ||
</PeripleoMap> | ||
</Peripleo> | ||
); |
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