Closed raywu closed 6 years ago
That looks like the bug. I think the reason is that plugin not handles well situation when you change icon after marker creation. Try to solve this problem by defining icon a the same time you create a marker. Look at this example: https://github.com/hosuaby/Leaflet.SmoothMarkerBouncing/blob/fix/icon_size/debug/scripts/divicon.js
@hosuaby Alexei, thanks for the link. I tried your method, but turns out ._icon
is still undefined.
// setup
var bounds = [[48.824384, 2.284298], [48.872054, 2.409782]];
var lat = _.random(bounds[0][0], bounds[1][0]);
var lng = _.random(bounds[0][1], bounds[1][1]);
var marker = L.marker([lat, lng], {
icon: L.divIcon({ className: 'ball-icon' })
});
// console
marker._icon
> undefined
marker.options.icon
> { options: { className: "ball-icon" }, _initHooksCalled: true }
I fixed my problem (TypeError
) by making sure the marker
is added to the relevant layer
before calling bounce
.
However, ._icon
is still undefined
and I'm not sure why makeMoveStep
and makeResizesStep
are not failing, since global icon
is still relying on this._icon
.
I tried this on Leaflet v1.0.2 (via mabox.js) and v1.3.1. I'll close this issue for now.
Hey, I am also having this issue, but can't addTo before using setIcon, this causes a "style" of undefined error on the following line (855):
// this._icon is undefined
var styles = parseCssText(this._icon.style.cssText);
This is similar to: https://github.com/Leaflet/Leaflet/issues/311
Context
TypeError: Cannot read property 'style' of null
makeMoveStep
and 668makeResizesStep
when callingicon.style.cssText
Setup
Problem
._icon
Question