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

Strange behaviour with overlay layers. #312

Closed rburone closed 7 years ago

rburone commented 7 years ago

I'm not sure what happened, but I could analyze that everything happens when it goes through the initialization function of the layer in leaflet.js

If i use a Array.prototype.someThing definitions, the overlays layers dont´work and report the error:

Error: layer.on is not a function L.Control.Layers<.addLayer@http://localhost/leaflet/lib/leaflet-src.js:12307:4 L.Control.Layers<.initialize@http://localhost/leaflet/lib/leaflet-src.js:12169:4 L.Class.extend/NewClass@http://localhost/leaflet/lib/leaflet-src.js:310:4 L.control.layers@http://localhost/leaflet/lib/leaflet-src.js:12487:9

Lines 1268~1270 of leaflet.js where the function is called.

for (var i in baseLayers) {
            console.log(typeof baseLayers);    ----> Object
            console.log(typeof baseLayers[i]); ----> Function, and "i" is a name of function in prototype of the Array.
            this._addLayer(baseLayers[i], i);
        }

And this happends only when i use Array.prototype.... declarations, if i remove these, works fine.

But i could resolve checking the type of variable layer first in leaf.js.

_addLayer: function (layer, name, overlay) {
      if (typeof layer == 'object') {
          layer.on ... 
      }

I don´t know if is something with the way of collections works in AngularJS or what. Angular version is 1.5.5, leaflet is 1.0.1 and ui-leaflet is 2.0.0

elesdoar commented 7 years ago

ui-leaflet 2.0.0 not is working with leaflet 1.x, for leaflet 1.x please use leaflet1.X branch. https://github.com/angular-ui/ui-leaflet/tree/leaflet-1.X, this is in alpha state.