angular-ui / ui-leaflet

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

Custom watch expressions for layers and markers #300

Closed mtfurlan closed 7 years ago

mtfurlan commented 8 years ago

I was running into a problem with really long digests, and instead of doing angular.equals on markers which can have thousands of members, looking at one version member or some other watch expression was quite useful.

Added a setting in defaults called watch to allow for custom watch expressions.

So for example, this is what I'm doing in my project:

defaults: {
 watch: {
      baselayers: function(scope){
        return Object.keys(scope.layers.baselayers).length;
      },
      markers: 'markers.version'
    }
}

I'm not sure defaults is the correct place for these, but putting them in markers or layers didn't seem right either.

I can write tests and an example, just wanted feedback on how I did this or if it's even wanted in the project first. I don't really know how the test or example naming scheme works though.

Would it be beneficial to try to replace leafletScope.defaults with leafletMapDefaults.getDefaults(mapId) right before a leafletScope.$watch?

mtfurlan commented 7 years ago

Okay, it actually doesn't work, and in fact may break more things. Not sure how I missed that part. I may come back with another pull request if I do get it to work, but at this point probably not. Sorry for the bother.