angular-ui / ui-leaflet

AngularJS directive to embed an interact with maps managed by Leaflet library
http://angular-ui.github.io/ui-leaflet
Other
314 stars 134 forks source link

Changin markers on scope, the model is different #343

Open pabloalcaraz opened 7 years ago

pabloalcaraz commented 7 years ago

Hi,

I have a map with a filter that shows or hide depending of category of the marker you choose.

so, depending of the choose i have to update the $scope.markers variable.

I have a function on click on marker and the model the first time the map is loaded is the correct but when I apply a filter and put the new markers on scope variable the model is different.

In the leafletEvent object when click i get the good lat,lng, the label and icon correctly, but not the model.

I've tested with object {} instead of array [], I've done controls.markers.clean(), etc without success.

Can anyone tell me what I have to do for do this change of markers correctly?

Thanks.

8Duke8 commented 7 years ago

Same issue here. If I change markers, I get wrong model on marker mouserOver, but in leafletEvent lat, lng are correct.

bdirito commented 7 years ago

I may have found the issue. When markers detects a change it checks watchTrap and aborts if this is true. watchTrap comes from modelChangeInDirective and acts as a throttling mechanism. The issue is if you abort you will miss your change until some other future change happens beyond the throttle timeout.

As a workaround I decorated leafletHelpers.modelChangeInDirective to do no throttling as i would much rather eat a possible performance hit then have wrong data.

in coffee:

.config ($provide) ->
    'ngInject'
    $provide.decorator 'leafletHelpers', ($delegate) ->
        'ngInject'
        $delegate.modelChangeInDirective = (trapObj, trapField, cbToExec) ->
            trapObj[trapField] = false
            cbToExec()
        $delegate