hosuaby / Leaflet.SmoothMarkerBouncing

Smooth animation of marker bouncing for Leaflet.
BSD 2-Clause "Simplified" License
146 stars 28 forks source link

Cannot read property 'style' of undefined #31

Closed TamaraVucic closed 2 years ago

TamaraVucic commented 3 years ago

Hello, thanks for your plugin, but I had problems using it. Exception that I got after including your script via CDN link:

Uncaught TypeError: Cannot read property 'style' of undefined at Function.ofMarker (bundle.js:391) at BouncingMotion3D.resetStyles (bundle.js:475) at i.setIcon (bundle.js:1316) at Object.success (map.js:122) at c (jquery.min.js:2) at Object.fireWith [as resolveWith] (jquery.min.js:2) at l (jquery.min.js:2) at XMLHttpRequest. (jquery.min.js:2)

My function where exception is thrown:

success: function(data) { var placeLayerGroups = dict['Place'];
var features = data.features;
for (i = 0; i < features.length; ++i) { var coordinates = features[i].geometry.coordinates; var marker = L.marker([coordinates[1],coordinates[0]]);// switch lat long marker.dbID = features[i].properties.pk; marker.name = features[i].properties.name; var layerGroup = placeLayerGroups[features[i].properties.placeType];
var iconName = layerGroup.name.replace("/", "_"); var iconUrl = iconFolder + "/place" + "/" + iconName + ".png";

            var icon = L.icon({
                iconUrl: iconUrl,
                iconSize: [40,40]
            });         
            marker.setIcon(icon);     //THIS IS WHERE EXCEPTION IS THROWN//      
            marker.addTo(layerGroup);
            marker.on('click', populateAndOpenPopupForPlace);
            marker.on('mouseover',leafletMarkerOnHover);
            marker.on('mouseout',leafletMarkerOnHoverEnded);
        }
        addPlacesToLayerControl();
    }
hosuaby commented 3 years ago

Hm. Probably a bug. I will check it later. For the moment, you can solve te problem if you set icon in the same time when you create your marker:

 var icon = L.icon({
    iconUrl: iconUrl,
    iconSize: [40,40]
});    

L.marker([coordinates[1],coordinates[0]], {
    icon: icon 
});
hosuaby commented 2 years ago

It is possible to change icon of bouncing marker starting from version 3.0.1.