Skip to content

Commit 3a25959

Browse files
authored
feat: allow CRS instance to be used as input as an alternative to UTM zone (#56)
1 parent a4249c0 commit 3a25959

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/components/UtmArea/UtmArea.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { UtmAreaContext, UtmAreaContextProps } from './UtmAreaContext'
99
* @expand
1010
*/
1111
export type UtmAreaProps = {
12-
utmZone: string,
12+
crsInstance?: CRS,
13+
utmZone?: string,
1314
origin: [number, number],
1415
originUnits?: 'utm' | 'lnglat',
1516
offset?: Vec3,
@@ -37,12 +38,16 @@ export type UtmAreaProps = {
3738
*
3839
* @group Components
3940
*/
40-
export const UtmArea = forwardRef<CRS, PropsWithChildren<UtmAreaProps>>(({ utmZone, origin, originUnits = 'utm', offset = [0, 0, 0], children }, fref) => {
41+
export const UtmArea = forwardRef<CRS, PropsWithChildren<UtmAreaProps>>(({ crsInstance, utmZone, origin, originUnits = 'utm', offset = [0, 0, 0], children }, fref) => {
4142
const ref = useRef<Group>(null)
4243
const crs = useMemo(()=> {
43-
const utmDef = getProjectionDefFromUtmZone(utmZone.toUpperCase())
44-
return new CRS(utmDef, origin, originUnits)
45-
}, [utmZone, origin, originUnits])
44+
if (crsInstance) return crsInstance;
45+
if (utmZone) {
46+
const utmDef = getProjectionDefFromUtmZone(utmZone.toUpperCase())
47+
return new CRS(utmDef, origin, originUnits)
48+
}
49+
throw Error('Either a UTM zone (string containing zone number + N/S for north/south hemisphere) or a CRS instance must be provided as props to the UtmArea component!')
50+
}, [crsInstance, utmZone, origin, originUnits])
4651

4752
useImperativeHandle(fref, () => crs, [crs])
4853

0 commit comments

Comments
 (0)