File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,17 @@ import OLVectorLayer from "ol/layer/Vector";
4
4
import { Options } from "ol/layer/BaseVector" ;
5
5
import { BaseLayerProps } from "./base-layer-props" ;
6
6
7
- type Props = Options < any > & BaseLayerProps ;
7
+ interface VectorLayerProps {
8
+ onLayerChangeVisible ?: ( visible : boolean ) => void ;
9
+ }
10
+
11
+ type Props = Options < any > & BaseLayerProps & VectorLayerProps ;
8
12
const VectorLayer : FunctionComponent < Props > = ( {
9
13
source,
10
14
style,
11
15
zIndex = 0 ,
12
16
name,
17
+ onLayerChangeVisible,
13
18
} ) => {
14
19
const map = useContext ( MapContext ) ;
15
20
@@ -21,6 +26,14 @@ const VectorLayer: FunctionComponent<Props> = ({
21
26
style,
22
27
} ) ;
23
28
vectorLayer . setProperties ( { name } ) ;
29
+
30
+ // If function is not null
31
+ if ( onLayerChangeVisible ) {
32
+ vectorLayer . on ( "change:visible" , ( evt ) =>
33
+ onLayerChangeVisible ( evt . target )
34
+ ) ;
35
+ }
36
+
24
37
map . addLayer ( vectorLayer ) ;
25
38
vectorLayer . setZIndex ( zIndex ) ;
26
39
You can’t perform that action at this time.
0 commit comments