hosuaby / Leaflet.SmoothMarkerBouncing

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

Property style on undefined. #21

Closed dbielak closed 4 years ago

dbielak commented 5 years ago

Hi, i have a problem with marker when is starting bouncing. It's make an error loop with message

"Uncaught TypeError: Cannot read property 'style' of undefined
    at makeMoveStep (leaflet.smoothmarkerbouncing.js:659)"

I have a custom Icon somthing like that

const ICON = L.icon( {
  iconUrl: require('./icons/javascript.png'),
  iconSize:     [44, 44], 
  iconAnchor:   [22, 44], 
  popupAnchor:  [-3, -44]
})

Do you know what is a problem?

MACscr commented 5 years ago

Get this resolved? Im having the same issue.

ankit22687 commented 5 years ago

I found solution by addding if condition before line no. 659

I added this condition at couple of places, so the condition is

if(icon){ // code }

tomek-servlets commented 4 years ago

Unfortunately, the problem still exists.

hosuaby commented 4 years ago

This issue was solved in https://github.com/hosuaby/Leaflet.SmoothMarkerBouncing/pull/23

Error "Uncaught TypeError: Cannot read property 'style' of undefined at makeMoveStep (leaflet.smoothmarkerbouncing.js:659)" was due to the fact that method bounce() was called before addTo(map).

Here is a working code snippet:

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

Hi,

I am using Leaflet routing machine and the marker are created from that by dragging. If i bounce the marker then i get the style error. If i do addTo(map) to the marker and bounce it works but then i have two markers. my repo is here https://neogeomat.github.io/MapPath/

hosuaby commented 3 years ago

Hello @neogeomat . I don't have example with Leaflet routing machine. The key to solve your problem is to assure that marker was successfully added to the map before call to method .bounce().

You you don't add marker by yourself, you need to find callback in the library that do it. It must be named something like: onMarkerAdded().