Leaflet.FileLayer icon indicating copy to clipboard operation
Leaflet.FileLayer copied to clipboard

fileLayerLoad() returns undefined property 'loader'

Open mwolfhoffman opened this issue 6 years ago • 3 comments

I am getting errors that I cannot read the 'on' property of undefined. Therefore, in the example below (copied from the Readme's event example), control.loader is undefined.

    var control = L.Control.fileLayerLoad();
    control.loader.on('data:loaded', function (event) {
        // event.layer gives you access to the layers you just uploaded!

        // Add to map layer switcher
        layerswitcher.addOverlay(event.layer, event.filename);
    });

mwolfhoffman avatar Jan 26 '19 15:01 mwolfhoffman

This plugin probably needs to be updated with latest versions of Leaflet...

leplatrem avatar Jan 28 '19 10:01 leplatrem

This example is broken indeed. Actually loader property is available only after we add control to map.

So this should work:

 var control = L.Control.fileLayerLoad().addTo(map);

johnd0e avatar Mar 26 '19 08:03 johnd0e

BTW, I think that loader could be initialized immediately on control creation (loader._map can be initialized later).

If user tries to use loader before adding control to map it may throw error. But actually I do not see any reason why loader should strictly require map: options.addToMap can be false.

P.S. Also I suppose that L.FileLayer.FileLoader has not to be extended from L.Layer as it's not layer, and does not benefit from any L.Layer-specific properties/methods/events.

johnd0e avatar Mar 29 '19 09:03 johnd0e