Naimikan / angular-mapboxgl-directive

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

Map events are not $broadcast inside an $apply #48

Open ezk84 opened 6 years ago

ezk84 commented 6 years ago

Currently, if I hook into map events using $scope.$on('mapboxglMap:...' the handler is running outside of a digest cycle and so model changes inside of them will not be reflected through the rest of the app.

According to the [Angular dev guide](https://github.com/angular/angular.js/wiki/Dev-Guide%3A-When-to-use-%24scope.%24apply()), $scope.$apply() should occur as close to the async event binding as possible.

Is there a reason not to do $rootScope.$apply($rootScope.$broadcast('mapboxglMap:' ...)) inside mapboxglEventsUtils.exposeMapEvents or in glControl when adding angular events for the control?

This is relevant particularly when listening to mapboxglDraw events.

Naimikan commented 6 years ago

Hi @ezk84!

Events was the first things that I did in the directive. Thank you for the advice! I will update a new version with that enhancement.

Thank you!

ezk84 commented 6 years ago

The only problem may be with the mouse events, where each mouse move would trigger a digest cycle through $rootScope.apply, may be too much no?

siddmegadeth commented 5 years ago

Also i need to control and get access to data in controllers. can it be done with about mapInstance