perliedman / leaflet-realtime

Put realtime data on a Leaflet map
ISC License
742 stars 167 forks source link

TypeError: Cannot read property 'features' of undefined when removing leaflet map #177

Open roddc opened 4 years ago

roddc commented 4 years ago

I am using leaflet-realtime in Angular as a directive with @asymmetrik/ngx-leaflet. I got an error 'TypeError: Cannot read property 'features' of undefined' when removing the map. How do I fix this?

claustres commented 3 years ago

It appears to me that the layer of this plugin implements the remove layer interface in order to manage the removal of some features. However, when destroying the map Leaflet calls remove() on each added layer so that the interface will be called without any argument, causing an exception as the plugin always expects a geoJson object input. In this specific case we should simply remove all features, but not sure of side-effects of doing so, maybe @perliedman could provide some feedback?

claustres commented 3 years ago

Maybe a workaround is to remove the layer before destroying the map using map.removeLayer(layer).

claustres commented 3 years ago

Would be happy to push a PR but only if it's relevant, @perliedman I hope you will be able to provide some feedback, thanks.

claustres commented 1 year ago

Seems to be fixed by PR https://github.com/perliedman/leaflet-realtime/pull/146.