Skip to content

Commit 5d10455

Browse files
committed
added layer events
1 parent 05e2833 commit 5d10455

File tree

9 files changed

+62
-37
lines changed

9 files changed

+62
-37
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-maplibre-gl",
3-
"version": "1.0.0-beta.18",
3+
"version": "1.0.0-beta.19",
44
"description": "Vue 3 plugin for maplibre-gl",
55
"keywords": [
66
"vue",

src/components/layers/circle.layer.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CircleLayer, CircleLayout, CirclePaint } 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';
44
import { componentIdSymbol, isLoadedSymbol, mapSymbol, sourceIdSymbol } from '@/components/types';
55
import { getSourceRef } from '@/components/sources/shared';
66

@@ -20,22 +20,24 @@ export default defineComponent({
2020
return;
2121
}
2222

23-
const map = inject(mapSymbol)!,
23+
const ci = getCurrentInstance()!,
24+
map = inject(mapSymbol)!,
2425
isLoaded = inject(isLoadedSymbol)!,
2526
cid = inject(componentIdSymbol)!,
2627
sourceRef = getSourceRef(cid, props.source || sourceId);
2728

2829
watch([ isLoaded, sourceRef ], ([ il, src ]) => {
2930
if (il && (src || src === undefined)) {
3031
map.value.addLayer(genLayerOpts<CircleLayer>(props.layerId, 'circle', props, sourceId), props.before || undefined);
32+
registerLayerEvents(map.value, props.layerId, ci.vnode);
3133
}
3234
}, { immediate: true });
3335

3436
onBeforeUnmount(() => {
35-
if (isLoaded.value) map.value.removeLayer(props.layerId);
37+
map.value.removeLayer(props.layerId);
38+
unregisterLayerEvents(map.value, props.layerId, ci.vnode);
3639
});
3740

38-
3941
},
4042
render() {
4143
return createCommentVNode('Circle Layer');

src/components/layers/fill.layer.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FillLayer, FillLayout, FillPaint } 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';
44
import { componentIdSymbol, isLoadedSymbol, mapSymbol, sourceIdSymbol } from '@/components/types';
55
import { getSourceRef } from '@/components/sources/shared';
66

@@ -20,22 +20,26 @@ export default defineComponent({
2020
return;
2121
}
2222

23-
const map = inject(mapSymbol)!,
23+
const ci = getCurrentInstance()!,
24+
map = inject(mapSymbol)!,
2425
isLoaded = inject(isLoadedSymbol)!,
2526
cid = inject(componentIdSymbol)!,
2627
sourceRef = getSourceRef(cid, props.source || sourceId);
2728

2829
watch([ isLoaded, sourceRef ], ([ il, src ]) => {
2930
if (il && (src || src === undefined)) {
3031
map.value.addLayer(genLayerOpts<FillLayer>(props.layerId, 'fill', props, sourceId), props.before || undefined);
32+
registerLayerEvents(map.value, props.layerId, ci.vnode);
3133
}
3234
}, { immediate: true });
3335

3436
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+
}
3641
});
3742

38-
3943
},
4044
render() {
4145
return createCommentVNode('Fill Layer');

src/components/layers/fillExtrusion.layer.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
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';
44
import { componentIdSymbol, isLoadedSymbol, mapSymbol, sourceIdSymbol } from '@/components/types';
55
import { getSourceRef } from '@/components/sources/shared';
66

@@ -20,22 +20,26 @@ export default defineComponent({
2020
return;
2121
}
2222

23-
const map = inject(mapSymbol)!,
23+
const ci = getCurrentInstance()!,
24+
map = inject(mapSymbol)!,
2425
isLoaded = inject(isLoadedSymbol)!,
2526
cid = inject(componentIdSymbol)!,
2627
sourceRef = getSourceRef(cid, props.source || sourceId);
2728

2829
watch([ isLoaded, sourceRef ], ([ il, src ]) => {
2930
if (il && (src || src === undefined)) {
3031
map.value.addLayer(genLayerOpts<LineLayer>(props.layerId, 'fill-extrusion', props, sourceId), props.before || undefined);
32+
registerLayerEvents(map.value, props.layerId, ci.vnode);
3133
}
3234
}, { immediate: true });
3335

3436
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+
}
3641
});
3742

38-
3943
},
4044
render() {
4145
return createCommentVNode('Fill Extrusion Layer');

src/components/layers/heatmap.layer.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HeatmapLayer, HeatmapLayout, HeatmapPaint } 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';
44
import { componentIdSymbol, isLoadedSymbol, mapSymbol, sourceIdSymbol } from '@/components/types';
55
import { getSourceRef } from '@/components/sources/shared';
66

@@ -20,22 +20,26 @@ export default defineComponent({
2020
return;
2121
}
2222

23-
const map = inject(mapSymbol)!,
23+
const ci = getCurrentInstance()!,
24+
map = inject(mapSymbol)!,
2425
isLoaded = inject(isLoadedSymbol)!,
2526
cid = inject(componentIdSymbol)!,
2627
sourceRef = getSourceRef(cid, props.source || sourceId);
2728

2829
watch([ isLoaded, sourceRef ], ([ il, src ]) => {
2930
if (il && (src || src === undefined)) {
3031
map.value.addLayer(genLayerOpts<HeatmapLayer>(props.layerId, 'heatmap', props, sourceId), props.before || undefined);
32+
registerLayerEvents(map.value, props.layerId, ci.vnode);
3133
}
3234
}, { immediate: true });
3335

3436
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+
}
3641
});
3742

38-
3943
},
4044
render() {
4145
return createCommentVNode('Heatmap Layer');

src/components/layers/hillshade.layer.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HillshadeLayer, HillshadeLayout, HillshadePaint } 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';
44
import { componentIdSymbol, isLoadedSymbol, mapSymbol, sourceIdSymbol } from '@/components/types';
55
import { getSourceRef } from '@/components/sources/shared';
66

@@ -20,22 +20,26 @@ export default defineComponent({
2020
return;
2121
}
2222

23-
const map = inject(mapSymbol)!,
23+
const ci = getCurrentInstance()!,
24+
map = inject(mapSymbol)!,
2425
isLoaded = inject(isLoadedSymbol)!,
2526
cid = inject(componentIdSymbol)!,
2627
sourceRef = getSourceRef(cid, props.source || sourceId);
2728

2829
watch([ isLoaded, sourceRef ], ([ il, src ]) => {
2930
if (il && (src || src === undefined)) {
3031
map.value.addLayer(genLayerOpts<HillshadeLayer>(props.layerId, 'hillshade', props, sourceId), props.before || undefined);
32+
registerLayerEvents(map.value, props.layerId, ci.vnode);
3133
}
3234
}, { immediate: true });
3335

3436
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+
}
3641
});
3742

38-
3943
},
4044
render() {
4145
return createCommentVNode('Hillshade Layer');

src/components/layers/line.layer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export default defineComponent({
4141
}
4242
});
4343

44-
4544
},
4645
render() {
4746
return createCommentVNode('Line Layer');

src/components/layers/raster.layer.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RasterLayer, RasterLayout, RasterPaint } 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';
44
import { componentIdSymbol, isLoadedSymbol, mapSymbol, sourceIdSymbol } from '@/components/types';
55
import { getSourceRef } from '@/components/sources/shared';
66

@@ -20,22 +20,26 @@ export default defineComponent({
2020
return;
2121
}
2222

23-
const map = inject(mapSymbol)!,
23+
const ci = getCurrentInstance()!,
24+
map = inject(mapSymbol)!,
2425
isLoaded = inject(isLoadedSymbol)!,
2526
cid = inject(componentIdSymbol)!,
2627
sourceRef = getSourceRef(cid, props.source || sourceId);
2728

2829
watch([ isLoaded, sourceRef ], ([ il, src ]) => {
2930
if (il && (src || src === undefined)) {
3031
map.value.addLayer(genLayerOpts<RasterLayer>(props.layerId, 'raster', props, sourceId), props.before || undefined);
32+
registerLayerEvents(map.value, props.layerId, ci.vnode);
3133
}
3234
}, { immediate: true });
3335

3436
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+
}
3641
});
3742

38-
3943
},
4044
render() {
4145
return createCommentVNode('Raster Layer');

src/components/layers/smybol.layer.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SymbolLayer, SymbolLayout, SymbolPaint } 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';
44
import { componentIdSymbol, isLoadedSymbol, mapSymbol, sourceIdSymbol } from '@/components/types';
55
import { getSourceRef } from '@/components/sources/shared';
66

@@ -20,22 +20,26 @@ export default defineComponent({
2020
return;
2121
}
2222

23-
const map = inject(mapSymbol)!,
23+
const ci = getCurrentInstance()!,
24+
map = inject(mapSymbol)!,
2425
isLoaded = inject(isLoadedSymbol)!,
2526
cid = inject(componentIdSymbol)!,
2627
sourceRef = getSourceRef(cid, props.source || sourceId);
2728

2829
watch([ isLoaded, sourceRef ], ([ il, src ]) => {
2930
if (il && (src || src === undefined)) {
3031
map.value.addLayer(genLayerOpts<SymbolLayer>(props.layerId, 'symbol', props, sourceId), props.before || undefined);
32+
registerLayerEvents(map.value, props.layerId, ci.vnode);
3133
}
3234
}, { immediate: true });
3335

3436
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+
}
3641
});
3742

38-
3943
},
4044
render() {
4145
return createCommentVNode('Symbol Layer');

0 commit comments

Comments
 (0)