forked from ikmolbo/vue2-leaflet-hotline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVue2LeafletHotline.vue
121 lines (116 loc) · 2.44 KB
/
Vue2LeafletHotline.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<template>
<div style="display: none;">
<slot v-if="ready"></slot>
</div>
</template>
<script>
const L = require('leaflet')
const { findRealParent, propsBinder } = require('vue2-leaflet')
require('leaflet-hotline')(L)
const props = {
latLngs: {
type: Array,
default: () => [],
custom: false
},
min: {
type: Number,
custom: true
},
max: {
type: Number,
custom: true
},
weight: {
type: Number,
custom: true
},
outlineWidth: {
type: Number,
custom: true
},
outlineColor: {
type: String,
custom: true
},
palette: {
type: Object,
custom: true
},
visible: {
type: Boolean,
custom: true,
default: true
}
};
export default {
name: 'LHotline',
props,
data () {
return {
ready: false
}
},
mounted () {
const options = {};
if (this.min) {
options.min = this.min;
}
if (this.max) {
options.max = this.max;
}
if (this.weight) {
options.weight = this.weight;
}
if (this.outlineWidth) {
options.outlineWidth = this.outlineWidth;
}
if (this.outlineColor) {
options.outlineColor = this.outlineColor;
}
if (this.palette) {
options.palette = this.palette;
}
this.mapObject = L.hotline(this.latLngs, options);
L.DomEvent.on(this.mapObject, this.$listeners);
propsBinder(this, this.mapObject, props);
this.ready = true;
this.parentContainer = findRealParent(this.$parent);
this.parentContainer.addLayer(this, !this.visible);
},
beforeDestroy () {
this.parentContainer.removeLayer(this);
},
methods: {
setMin (newVal, oldVal) {
this.mapObject.setStyle({ min: newVal })
},
setMax (newVal, oldVal) {
this.mapObject.setStyle({ max: newVal })
},
setWidth (newVal, oldVal) {
this.mapObject.setStyle({ width: newVal })
},
setOutlineColor (newVal, oldVal) {
this.mapObject.setStyle({ outlineColor: newVal })
},
setOutlineWidth (newVal, oldVal) {
this.mapObject.setStyle({ outlineWidth: newVal })
},
setPalette (newVal, oldVal) {
this.mapObject.setStyle({ palette: newVal })
},
setVisible (newVal, oldVal) {
if (newVal === oldVal) return;
if (newVal) {
this.parentContainer.addLayer(this);
} else {
this.parentContainer.removeLayer(this);
}
},
addLatLng (value) {
this.mapObject.addLatLng(value);
}
}
};
</script>