-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
Vue2LeafletMarkercluster.vue
53 lines (50 loc) · 1.14 KB
/
Vue2LeafletMarkercluster.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<template>
<div style="display: none;">
<slot v-if="ready"></slot>
</div>
</template>
<script>
import { MarkerClusterGroup } from 'leaflet.markercluster'
import { findRealParent, propsBinder } from 'vue2-leaflet'
import { DomEvent } from 'leaflet'
const props = {
options: {
type: Object,
default() { return {}; },
},
};
export default {
props,
data() {
return {
ready: false,
};
},
mounted() {
this.mapObject = new MarkerClusterGroup(this.options);
DomEvent.on(this.mapObject, this.$listeners);
propsBinder(this, this.mapObject, props);
this.ready = true;
this.parentContainer = findRealParent(this.$parent);
this.parentContainer.addLayer(this);
this.$nextTick(() => {
this.$emit('ready', this.mapObject);
});
},
beforeDestroy() {
this.parentContainer.removeLayer(this);
},
methods: {
addLayer(layer, alreadyAdded) {
if (!alreadyAdded) {
this.mapObject.addLayer(layer.mapObject);
}
},
removeLayer(layer, alreadyRemoved) {
if (!alreadyRemoved) {
this.mapObject.removeLayer(layer.mapObject);
}
}
}
};
</script>