-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathVue2LeafletLocatecontrol.vue
56 lines (47 loc) · 1.06 KB
/
Vue2LeafletLocatecontrol.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
54
55
56
<template>
<div style="display: none;">
<slot v-if="ready"></slot>
</div>
</template>
<script>
import { DomEvent } from 'leaflet';
import { findRealParent, propsBinder } from 'vue2-leaflet';
import Locatecontrol from "leaflet.locatecontrol";
const props = {
options: {
type: Object,
default() { return {}; },
},
visible: {
type: Boolean,
custom: true,
default: true
}
}
export default {
name: "Vue2LeafletLocatecontrol",
props,
data() {
return {
ready: false
}
},
beforeDestroy() {
this.parentContainer.removeLayer(this);
},
mounted() {
this.mapObject = new Locatecontrol(this.options);
DomEvent.on(this.mapObject, this.$listeners);
propsBinder(this, this.mapObject, props);
this.ready = true;
this.parentContainer = findRealParent(this.$parent);
this.mapObject.addTo(this.parentContainer.mapObject, !this.visible);
this.$nextTick(() => {
this.$emit('ready', this.mapObject);
});
}
}
</script>
<style>
@import "~leaflet.locatecontrol/dist/L.Control.Locate.css";
</style>