Naimikan / angular-mapboxgl-directive

AngularJS directive for Mapbox GL
https://naimikan.github.io/angular-mapboxgl-directive/
MIT License
49 stars 21 forks source link

Adding checks to ensure managers have been defined on directives' sco… #33

Closed dwohlfahrt closed 7 years ago

dwohlfahrt commented 7 years ago

…pes before calling their respective functions on directive events.

When browsing away from a page using the angular-mapboxgl-directive before the map has had enough time to fully load, errors were being thrown within the $destroy event handlers for the markers, layers, and sources directives. This occurs when the respective manager class (MarkersManager, LayersManager, or SourcesManager) for one or more of these directives (whichever of them have been implemented) hasn't yet been defined on its respective scope, something that only happens once the underlying mapboxgl.Map has fully loaded and controller._mapboxGlMap is resolved in the main directive's controller. To prevent these errors, I've simply added checks to each of these directive's $destroy evens to ensure the manager has been defined on its scope before making the necessary function calls on it.

Naimikan commented 7 years ago

Hi @dwohlfahrt!

Thank you!