@@ -76,33 +76,32 @@ export default {
76
76
type: Object ,
77
77
custom: true ,
78
78
default : () => ({})
79
- },
80
- // TODO: Remove tempName here (and from the example)
81
- tempName: {
82
- type: String ,
83
- custom: true ,
84
- default: null
85
79
}
86
80
},
87
81
88
82
data () {
89
83
return {
90
- observer: null
84
+ parentContainer: null ,
85
+ observer: null ,
86
+ recreationNeeded: false ,
87
+ swapHtmlNeeded: false
91
88
};
92
89
},
93
90
94
91
mounted () {
92
+ this .parentContainer = findRealParent (this .$parent );
93
+
95
94
propsBinder (this , null , this .$options .props );
96
95
97
96
this .observer = new MutationObserver (() => {
98
- this .createIcon ( ' html slot ' );
97
+ this .scheduleHtmlSwap ( );
99
98
});
100
99
this .observer .observe (
101
100
this .$el ,
102
101
{ attributes: true , childList: true , characterData: true , subtree: true }
103
102
);
104
103
105
- this .createIcon ( ' initial ' );
104
+ this .scheduleCreateIcon ( );
106
105
},
107
106
108
107
beforeDestroy () {
@@ -114,8 +113,30 @@ export default {
114
113
},
115
114
116
115
methods: {
117
- createIcon (reason ) {
118
- console .log (Date .now () + ' - recreate ' + this .tempName + ' (' + reason + ' )' );
116
+ scheduleCreateIcon () {
117
+ this .recreationNeeded = true ;
118
+
119
+ this .$nextTick (this .createIcon );
120
+ },
121
+
122
+ scheduleHtmlSwap () {
123
+ this .htmlSwapNeeded = true ;
124
+
125
+ this .$nextTick (this .createIcon );
126
+ },
127
+
128
+ createIcon () {
129
+ // If only html of a divIcon changed, we can just replace the DOM without the need of recreating the whole icon
130
+ if (this .htmlSwapNeeded && ! this .recreationNeeded && this .iconObject ) {
131
+ this .parentContainer .mapObject .getElement ().innerHTML = this .$el .innerHTML ;
132
+
133
+ this .htmlSwapNeeded = false ;
134
+ return ;
135
+ }
136
+
137
+ if (! this .recreationNeeded ) {
138
+ return ;
139
+ }
119
140
120
141
if (this .iconObject ) {
121
142
L .DomEvent .off (this .iconObject , this .$listeners );
@@ -145,44 +166,47 @@ export default {
145
166
146
167
L .DomEvent .on (this .iconObject , this .$listeners );
147
168
148
- this .parentContainer = findRealParent (this .$parent );
149
169
this .parentContainer .mapObject .setIcon (this .iconObject );
170
+
171
+ this .recreationNeeded = false ;
172
+ this .htmlSwapNeeded = false ;
150
173
},
174
+
151
175
setIconUrl () {
152
- this .createIcon ( ' iconUrl ' );
176
+ this .scheduleCreateIcon ( );
153
177
},
154
178
setIconRetinaUrl () {
155
- this .createIcon ( ' iconRetinaUrl ' );
179
+ this .scheduleCreateIcon ( );
156
180
},
157
181
setIconSize () {
158
- this .createIcon ( ' iconSize ' );
182
+ this .scheduleCreateIcon ( );
159
183
},
160
184
setIconAnchor () {
161
- this .createIcon ( ' iconAnchor ' );
185
+ this .scheduleCreateIcon ( );
162
186
},
163
187
setPopupAnchor () {
164
- this .createIcon ( ' popupAnchor ' );
188
+ this .scheduleCreateIcon ( );
165
189
},
166
190
setTooltipAnchor () {
167
- this .createIcon ( ' tooltipAnchor ' );
191
+ this .scheduleCreateIcon ( );
168
192
},
169
193
setShadowUrl () {
170
- this .createIcon ( ' shadowUrl ' );
194
+ this .scheduleCreateIcon ( );
171
195
},
172
196
setShadowRetinaUrl () {
173
- this .createIcon ( ' shadowRetinaUrl ' );
197
+ this .scheduleCreateIcon ( );
174
198
},
175
199
setShadowAnchor () {
176
- this .createIcon ( ' shadowAnchor ' );
200
+ this .scheduleCreateIcon ( );
177
201
},
178
202
setBgPos () {
179
- this .createIcon ( ' bgPos ' );
203
+ this .scheduleCreateIcon ( );
180
204
},
181
205
setClassName () {
182
- this .createIcon ( ' className ' );
206
+ this .scheduleCreateIcon ( );
183
207
},
184
208
setHtml () {
185
- this .createIcon ( ' html ' );
209
+ this .scheduleCreateIcon ( );
186
210
}
187
211
},
188
212
0 commit comments