Leaflet.FileLayer
Leaflet.FileLayer copied to clipboard
fileLayerLoad() returns undefined property 'loader'
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);
});
This plugin probably needs to be updated with latest versions of Leaflet...
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);
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.