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

Removing control throws error - TypeError: map.hasControl is not a function #118

Open nmccready opened 9 years ago

nmccready commented 9 years ago

From @skray on September 27, 2015 3:19

I ran into this trying to use the Leaflet.draw plugin and was able to recreate it in this fiddle (click the 'Remove Controls' button to trigger the error).

If you have controls in your map and use the controls directive, like this:

$scope.controls = { draw: {} };

and then remove the control from the controls object later, like this:

$scope.controls = { };

This error is thrown:

angular-leaflet-directive-error

It seems the culprit is this line, where it tries to call map.hasControl(), but I cannot find the hasControl method defined in either the leaflet.js source or in this project.

If this is just me misunderstanding how to work with controls, I'd love to know what I'm doing wrong. If this is a bug, I'd be happy to try to put a pull request in to fix it.

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

enantiomer2000 commented 8 years ago

Having the exact same problem. Getting around it by manually adding the control to the map instance.

jbgtmartin commented 8 years ago

Hi, I'm having the same problem (with controls like scale, draw, fullscreen...), so I also added the controls manually.