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

"Defaults" keys #130

Open nmccready opened 9 years ago

nmccready commented 9 years ago

From @markovaljaots on October 9, 2015 13:18

I want to use https://github.com/yohanboniface/Leaflet.Editable together with angular-leaflet-directive, but in order to do so it is necessary to create a map with following options:

angular.extend($scope, {defaults: {editable: true}});

Unfortunately all the "defaults" keys are hardcoded in angular-leaflet-directive.js and therefore "editable: true" is skipped. I managed to enable "editable" key by modifying angular-leflet-directive.js and making these adjustments:

getMapCreationDefaults: function(scopeId) {

  ...

  if(isDefined(d.editable)) {
    mapDefaults.editable = d.editable;
  }

  ...

},

setDefaults: function(userDefaults, scopeId) {
  var newDefaults = _getDefaults();

  if (isDefined(userDefaults)) {

    ...

    if(isDefined(userDefaults.editable)) {
      newDefaults.editable = userDefaults.editable;
    }

  }

  ...

}

Now Leaflet.Editable works, but this solution is quite hacky. Are there any alternative ways to achieve this?

Copied from original issue: tombatossals/angular-leaflet-directive#986

nmccready commented 9 years ago

From @skray on October 12, 2015 3:28

I also was trying to use Leaflet.Editable, and ran into this same problem. Looking at this line in LeafletMapDefaults, it looks like you can assign any non-standard default to the map field of the defaults object, and they will get carried over. So for your example @markovaljaots, I did this instead and it worked for me:

angular.extend($scope, { defaults: { map: { editable: true } } });

I'm not sure if this is the correct use of defaults.map, but it seems to do the trick.

nmccready commented 9 years ago

With leafletMapDefaults factory why doesn't someone PR changes to setDefaults to make them less restrictive. IE remove all the isDefined and default checks and just merge / extend all the properties via angular.extend({}. newDefaults, userDefaults)