-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vue2LeafletPolylineOffset.vue
56 lines (54 loc) · 1.43 KB
/
Vue2LeafletPolylineOffset.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" />
</div>
</template>
<script>
import { optionsMerger, propsBinder, findRealParent } from 'vue2-leaflet/dist/utils/utils.js';
import PolylineMixin from 'vue2-leaflet/dist/mixins/Polyline.js';
import Options from 'vue2-leaflet/dist/mixins/Options.js';
import { polyline, DomEvent } from 'leaflet';
import 'leaflet-polylineoffset';
export default {
name: 'LPolylineOffset',
mixins: [PolylineMixin, Options],
props: {
latLngs: {
type: Array,
default: () => [],
},
offset: {
type: Number,
default: () => 0,
}
},
data() {
return {
ready: false,
};
},
watch: {
offset: function(val){
if(this.mapObject) this.mapObject.setOffset(val);
}
},
mounted() {
const options = optionsMerger(this.polyLineOptions, this);
this.mapObject = polyline(this.latLngs, options);
DomEvent.on(this.mapObject, this.$listeners);
propsBinder(this, this.mapObject, this.$options.props);
this.ready = true;
this.parentContainer = findRealParent(this.$parent);
this.parentContainer.addLayer(this, !this.visible);
this.mapObject.setOffset(this.offset);
this.$nextTick(() => {
/**
* Triggers when the component is ready
* @type {object}
* @property {object} mapObject - reference to leaflet map object
*/
this.$emit('ready', this.mapObject);
});
},
};
</script>