angular-mapboxgl-directive icon indicating copy to clipboard operation
angular-mapboxgl-directive copied to clipboard

Map events are not $broadcast inside an $apply

Open ezk84 opened this issue 6 years ago • 3 comments

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, $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.

ezk84 avatar Apr 18 '18 13:04 ezk84

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!

Naimikan avatar Apr 22 '18 17:04 Naimikan

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?

ezk84 avatar May 11 '18 16:05 ezk84

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

siddmegadeth avatar Oct 02 '19 19:10 siddmegadeth