hosuaby / Leaflet.SmoothMarkerBouncing

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

Fixed "Property style on undefined" #23

Closed ankit22687 closed 4 years ago

ankit22687 commented 5 years ago

Found issue before set icon style, so I just wrap those with If condition and it is working fine now.

hosuaby commented 4 years ago

Only style of the code was changed. Indentation, etc. But no fix in sight

ankit22687 commented 4 years ago

Go to line no. 645, 668 and 691. I wrap code with If conditions

hosuaby commented 4 years ago

I found. For which use-case do you introduce those modifications ? If you wrap those code lines into condition and icon object does not exist, bouncing doesn-t work at all, and this made the use of this pugin pointless

tomek-servlets commented 4 years ago

Unfortunately, the problem still exists. There ate no if statements in the master.

hosuaby commented 4 years ago

@tomek-servlets Can you please, present the minimal snippet that reproduce the bug. How do you create marker that has no icon ?

tomek-servlets commented 4 years ago

In my opinion before line 645 https://github.com/hosuaby/Leaflet.SmoothMarkerBouncing/blob/master/leaflet.smoothmarkerbouncing.js#L645 there should be if(icon) the same in the line 687

after adding of these statements there are no more errors in the console

hosuaby commented 4 years ago

@tomek-servlets is it bug or just console warning ?

tomek-servlets commented 4 years ago

If I remove the if before line 645 I get hundreds of errors: leaflet.smoothmarkerbouncing.js:645 Uncaught TypeError: Cannot read property 'style' of undefined at makeMoveStep (leaflet.smoothmarkerbouncing.js:645)

hosuaby commented 4 years ago

@tomek-servlets Please, check this demo and tell me if you have error: http://hosuaby.github.io/Leaflet.SmoothMarkerBouncing/

ironbone commented 4 years ago

On your page there I can see no errors.

I created a small page with errors. Click on the map and see the console: https://github.com/ironbone/leaflet-test

hosuaby commented 4 years ago

@ironbone Thanks for concrete example!

Your problem is easy to solve. You made a mistake by calling method bounce() before add market to the map:

    marker = L.marker(latlng, {icon: personIcon})
        .bindPopup(popupText).bounce()  // <- wrong place to call bounce
        .setBouncingOptions({
            bounceSpeed: bounceSpeed,
        }).addTo(map);

To fix, just call bounce() after addTo(map):

    marker = L.marker(latlng, {icon: personIcon})
        .bindPopup(popupText)
        .setBouncingOptions({
            bounceSpeed: bounceSpeed,
        }).addTo(map).bounce();  // <- bounce called in the end
ironbone commented 4 years ago

Thank you for your answer. This was not clear after reading the description of the plugin.

hosuaby commented 4 years ago

@ironbone I updated readme to outline importance to add market to map before call bounce() method.