-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathVue2LeafletVectorGridProtobuf.vue
73 lines (68 loc) · 1.64 KB
/
Vue2LeafletVectorGridProtobuf.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<template></template>
<script>
import L from 'leaflet'
import 'leaflet.vectorgrid'
export default {
props: {
url: {
type: String,
required: true
},
options: {
type: Object,
default: function () {
return {}
}
}
},
watch: {
url() {
this.updateLayer()
},
options() {
this.updateLayer()
},
},
mounted () {
this.mapObject = L.vectorGrid.protobuf(this.url, this.options)
if (this.options && this.options.interactive) {
L.DomEvent.on(this.mapObject, this.$listeners)
}
if (this.$parent._isMounted) {
this.deferredMountedTo(this.$parent.mapObject);
}
},
beforeDestroy() {
this.removeLayer()
},
methods: {
deferredMountedTo(parent) {
this.mapObject.addTo(parent);
this.attributionControl = parent.attributionControl;
for (var i = 0; i < this.$children.length; i++) {
if (typeof this.$children[i].deferredMountedTo === "function") {
this.$children[i].deferredMountedTo(this.mapObject);
}
}
},
setAttribution(val, old) {
this.attributionControl.removeAttribution(old);
this.attributionControl.addAttribution(val);
},
setToken(val) {
this.options.token = val;
},
removeLayer() {
this.$parent.mapObject.removeLayer(this.mapObject);
},
updateLayer() {
this.removeLayer()
this.mapObject = L.vectorGrid.protobuf(this.url, this.options)
if (this.options && this.options.interactive) {
L.DomEvent.on(this.mapObject, this.$listeners)
}
this.deferredMountedTo(this.$parent.mapObject);
}
}
}
</script>