1
1
<template >
2
- <div >
3
- <slot ></ slot >
4
- </div >
2
+ <div >
3
+ <slot / >
4
+ </div >
5
5
</template >
6
6
7
7
<script >
8
+ import propsBinder from ' ../utils/propsBinder.js' ;
8
9
import findRealParent from ' ../utils/findRealParent.js' ;
9
10
import { optionsMerger } from ' ../utils/optionsUtils.js' ;
10
- import Options from ' ../mixins/Options.js' ;
11
11
12
12
export default {
13
13
name: ' LIcon' ,
14
- mixins: [Options],
15
14
props: {
16
- iconUrl: String ,
17
- iconRetinaUrl: String ,
18
- iconSize: [Object , Array ],
19
- iconAnchor: [Object , Array ],
20
- popupAnchor: [Object , Array ],
21
- tooltipAnchor: [Object , Array ],
22
- shadowUrl: String ,
23
- shadowRetinaUrl: String ,
24
- shadowSize: [Object , Array ],
25
- shadowAnchor: [Object , Array ],
26
- bgPos: [Object , Array ],
27
- className: String
15
+ iconUrl: {
16
+ type: String ,
17
+ custom: true ,
18
+ default: null
19
+ },
20
+ iconRetinaUrl: {
21
+ type: String ,
22
+ custom: true ,
23
+ default: null
24
+ },
25
+ iconSize: {
26
+ type: [Object , Array ],
27
+ custom: true ,
28
+ default: null
29
+ },
30
+ iconAnchor: {
31
+ type: [Object , Array ],
32
+ custom: true ,
33
+ default: null
34
+ },
35
+ popupAnchor: {
36
+ type: [Object , Array ],
37
+ custom: true ,
38
+ default : () => [0 , 0 ]
39
+ },
40
+ tooltipAnchor: {
41
+ type: [Object , Array ],
42
+ custom: true ,
43
+ default : () => [0 , 0 ]
44
+ },
45
+ shadowUrl: {
46
+ type: String ,
47
+ custom: true ,
48
+ default: null
49
+ },
50
+ shadowRetinaUrl: {
51
+ type: String ,
52
+ custom: true ,
53
+ default: null
54
+ },
55
+ shadowSize: {
56
+ type: [Object , Array ],
57
+ custom: true ,
58
+ default: null
59
+ },
60
+ shadowAnchor: {
61
+ type: [Object , Array ],
62
+ custom: true ,
63
+ default: null
64
+ },
65
+ bgPos: {
66
+ type: [Object , Array ],
67
+ custom: true ,
68
+ default : () => [0 , 0 ]
69
+ },
70
+ className: {
71
+ type: String ,
72
+ custom: true ,
73
+ default: ' '
74
+ },
75
+ options: {
76
+ type: Object ,
77
+ custom: true ,
78
+ default : () => ({})
79
+ },
80
+ // TODO: Remove tempName here (and from the example)
81
+ tempName: {
82
+ type: String ,
83
+ custom: true ,
84
+ default: null
85
+ }
28
86
},
29
87
30
- data () {
88
+ data () {
31
89
return {
32
90
observer: null
33
- }
91
+ };
34
92
},
35
93
36
94
mounted () {
37
- const options = optionsMerger ({
38
- iconUrl: this .iconUrl ,
39
- iconRetinaUrl: this .iconRetinaUrl ,
40
- iconSize: this .iconSize ,
41
- iconAnchor: this .iconAnchor ,
42
- popupAnchor: this .popupAnchor ,
43
- tooltipAnchor: this .tooltipAnchor ,
44
- shadowUrl: this .shadowUrl ,
45
- shadowRetinaUrl: this .shadowRetinaUrl ,
46
- shadowSize: this .shadowSize ,
47
- shadowAnchor: this .shadowAnchor ,
48
- bgPos: this .bgPos ,
49
- className: this .className
50
- }, this );
95
+ propsBinder (this , null , this .$options .props );
51
96
52
- this .watchProps (options);
53
- this .watchSlot (options);
97
+ this .observer = new MutationObserver (() => {
98
+ this .createIcon ();
99
+ });
100
+ this .observer .observe (
101
+ this .$el ,
102
+ { attributes: true , childList: true , characterData: true , subtree: true }
103
+ );
54
104
55
- this .createIcon (options );
105
+ this .createIcon ();
56
106
},
57
107
58
108
beforeDestroy () {
@@ -63,17 +113,29 @@ export default {
63
113
this .observer .disconnect ();
64
114
},
65
115
66
- render () {
67
- return null ;
68
- },
69
-
70
116
methods: {
71
- createIcon (options ) {
117
+ createIcon () {
118
+ console .log (Date .now () + ' - recreate ' + this .tempName );
119
+
72
120
if (this .iconObject ) {
73
121
L .DomEvent .off (this .iconObject , this .$listeners );
74
122
}
75
123
76
- options .html = this .$el .innerHTML ;
124
+ const options = optionsMerger ({
125
+ iconUrl: this .iconUrl ,
126
+ iconRetinaUrl: this .iconRetinaUrl ,
127
+ iconSize: this .iconSize ,
128
+ iconAnchor: this .iconAnchor ,
129
+ popupAnchor: this .popupAnchor ,
130
+ tooltipAnchor: this .tooltipAnchor ,
131
+ shadowUrl: this .shadowUrl ,
132
+ shadowRetinaUrl: this .shadowRetinaUrl ,
133
+ shadowSize: this .shadowSize ,
134
+ shadowAnchor: this .shadowAnchor ,
135
+ bgPos: this .bgPos ,
136
+ className: this .className ,
137
+ html: this .$el .innerHTML || this .html
138
+ }, this );
77
139
78
140
if (options .html ) {
79
141
this .iconObject = L .divIcon (options);
@@ -86,36 +148,46 @@ export default {
86
148
this .parentContainer = findRealParent (this .$parent );
87
149
this .parentContainer .mapObject .setIcon (this .iconObject );
88
150
},
89
-
90
- watchProps (options ) {
91
- const props = this .$options .props ;
92
- const keys = Object .keys (props);
93
-
94
- for (let i = 0 ; i < keys .length ; i++ ) {
95
- this .$watch (keys[i], (newVal , oldVal ) => {
96
- // TODO: why is watch triggered on foreign props when changing icon size in my example?
97
- if (JSON .stringify (newVal) === JSON .stringify (oldVal)) {
98
- return ;
99
- }
100
-
101
- options[keys[i]] = newVal;
102
- this .createIcon (options);
103
- }, {
104
- deep: props[keys[i]].type === Object
105
- });
106
- }
151
+ setIconUrl () {
152
+ this .createIcon ();
107
153
},
108
-
109
- watchSlot (options ) {
110
- this .observer = new MutationObserver (() => {
111
- this .createIcon (options);
112
- });
113
-
114
- this .observer .observe (
115
- this .$el ,
116
- { attributes: true , childList: true , characterData: true , subtree: true }
117
- );
154
+ setIconRetinaUrl () {
155
+ this .createIcon ();
156
+ },
157
+ setIconSize () {
158
+ this .createIcon ();
159
+ },
160
+ setIconAnchor () {
161
+ this .createIcon ();
162
+ },
163
+ setPopupAnchor () {
164
+ this .createIcon ();
165
+ },
166
+ setTooltipAnchor () {
167
+ this .createIcon ();
168
+ },
169
+ setShadowUrl () {
170
+ this .createIcon ();
171
+ },
172
+ setShadowRetinaUrl () {
173
+ this .createIcon ();
174
+ },
175
+ setShadowAnchor () {
176
+ this .createIcon ();
177
+ },
178
+ setBgPos () {
179
+ this .createIcon ();
180
+ },
181
+ setClassName () {
182
+ this .createIcon ();
183
+ },
184
+ setHtml () {
185
+ this .createIcon ();
118
186
}
187
+ },
188
+
189
+ render () {
190
+ return null ;
119
191
}
120
192
};
121
193
</script >
0 commit comments