1
1
import { FillExtrusionLayout , FillExtrusionPaint , LineLayer } from 'maplibre-gl' ;
2
- import { genLayerOpts , Shared } from '@/components/layers/shared' ;
3
- import { createCommentVNode , defineComponent , inject , onBeforeUnmount , PropType , warn , watch } from 'vue' ;
2
+ import { genLayerOpts , registerLayerEvents , Shared , unregisterLayerEvents } from '@/components/layers/shared' ;
3
+ import { createCommentVNode , defineComponent , getCurrentInstance , inject , onBeforeUnmount , PropType , warn , watch } from 'vue' ;
4
4
import { componentIdSymbol , isLoadedSymbol , mapSymbol , sourceIdSymbol } from '@/components/types' ;
5
5
import { getSourceRef } from '@/components/sources/shared' ;
6
6
@@ -20,22 +20,26 @@ export default defineComponent({
20
20
return ;
21
21
}
22
22
23
- const map = inject ( mapSymbol ) ! ,
23
+ const ci = getCurrentInstance ( ) ! ,
24
+ map = inject ( mapSymbol ) ! ,
24
25
isLoaded = inject ( isLoadedSymbol ) ! ,
25
26
cid = inject ( componentIdSymbol ) ! ,
26
27
sourceRef = getSourceRef ( cid , props . source || sourceId ) ;
27
28
28
29
watch ( [ isLoaded , sourceRef ] , ( [ il , src ] ) => {
29
30
if ( il && ( src || src === undefined ) ) {
30
31
map . value . addLayer ( genLayerOpts < LineLayer > ( props . layerId , 'fill-extrusion' , props , sourceId ) , props . before || undefined ) ;
32
+ registerLayerEvents ( map . value , props . layerId , ci . vnode ) ;
31
33
}
32
34
} , { immediate : true } ) ;
33
35
34
36
onBeforeUnmount ( ( ) => {
35
- if ( isLoaded . value ) map . value . removeLayer ( props . layerId ) ;
37
+ if ( isLoaded . value ) {
38
+ map . value . removeLayer ( props . layerId ) ;
39
+ unregisterLayerEvents ( map . value , props . layerId , ci . vnode ) ;
40
+ }
36
41
} ) ;
37
42
38
-
39
43
} ,
40
44
render ( ) {
41
45
return createCommentVNode ( 'Fill Extrusion Layer' ) ;
0 commit comments