-
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.
- Loading branch information
1 parent
687e6be
commit 1cec2ef
Showing
5 changed files
with
112 additions
and
2 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './map'; | ||
export * from './marker'; | ||
export * from './source'; | ||
export * from './layer'; | ||
export * from './hooks/useMap'; |
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,2 @@ | ||
export { Layer } from './layer'; | ||
export type { LayerProps } from './types'; |
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,23 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { useMap } from '@/hooks/useMap'; | ||
|
||
import type { FC } from 'react'; | ||
import type { AnyLayer } from 'mapbox-gl'; | ||
import type { LayerProps } from './types'; | ||
|
||
export const Layer: FC<LayerProps> = (props) => { | ||
const { before, ...rest } = props; | ||
const map = useMap(); | ||
const [layer, setLayer] = useState<AnyLayer>(); | ||
|
||
useEffect(() => { | ||
if (map) { | ||
map.addLayer(rest as AnyLayer, before); | ||
|
||
setLayer(map.getLayer(props.id)); | ||
} | ||
}, [map]); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import type { | ||
Layer, | ||
BackgroundLayout, | ||
BackgroundPaint, | ||
CircleLayout, | ||
CirclePaint, | ||
FillLayout, | ||
FillPaint, | ||
FillExtrusionLayout, | ||
FillExtrusionPaint, | ||
HeatmapLayout, | ||
HeatmapPaint, | ||
LineLayout, | ||
LinePaint, | ||
RasterLayout, | ||
RasterPaint, | ||
SkyLayout, | ||
SkyPaint, | ||
SymbolLayout, | ||
SymbolPaint, | ||
HillshadeLayout, | ||
HillshadePaint, | ||
} from 'mapbox-gl'; | ||
|
||
export type LayerType = | ||
| 'background' | ||
| 'circle' | ||
| 'fill-extrusion' | ||
| 'fill' | ||
| 'heatmap' | ||
| 'hillshade' | ||
| 'line' | ||
| 'raster' | ||
| 'symbol' | ||
| 'sky'; | ||
|
||
export interface LayoutPaint { | ||
background: { | ||
layout: BackgroundLayout; | ||
paint: BackgroundPaint; | ||
}; | ||
circle: { | ||
layout: CircleLayout; | ||
paint: CirclePaint; | ||
}; | ||
'fill-extrusion': { | ||
layout: FillExtrusionLayout; | ||
paint: FillExtrusionPaint; | ||
}; | ||
fill: { | ||
layout: FillLayout; | ||
paint: FillPaint; | ||
}; | ||
heatmap: { | ||
layout: HeatmapLayout; | ||
paint: HeatmapPaint; | ||
}; | ||
hillshade: { | ||
layout: HillshadeLayout; | ||
paint: HillshadePaint; | ||
}; | ||
line: { | ||
layout: LineLayout; | ||
paint: LinePaint; | ||
}; | ||
raster: { | ||
layout: RasterLayout; | ||
paint: RasterPaint; | ||
}; | ||
symbol: { | ||
layout: SymbolLayout; | ||
paint: SymbolPaint; | ||
}; | ||
sky: { | ||
layout: SkyLayout; | ||
paint: SkyPaint; | ||
}; | ||
} | ||
|
||
export interface LayerProps<T extends LayerType> extends Omit<Layer, 'layout' | 'paint'> { | ||
type: T; | ||
before?: string; | ||
layout?: LayoutPaint[T]; | ||
paint?: LayoutPaint[T]; | ||
} |
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