gabriel-russo / Leaflet.BetterFileLayer

The definitive plugin to load your spatialized files into leaflet.
https://gabriel-russo.github.io/Leaflet.BetterFileLayer/example/
Other
18 stars 0 forks source link

how to use the event 'bfl:layerloaded' #1

Closed luisfio1 closed 4 months ago

luisfio1 commented 8 months ago

I want to add the new file, opened with BFL to L.control.layers, using: // Better-FileLayer var fileLayer = L.Control.betterFileLayer( options = { style: () => myStyle,
}, ).addTo(map);

    fileLayer.loader.on('bfl:layerloaded', function (event) { 
        layerswitcher.addOverlay(event.layer, event.filename);
    });

But it does not work. Which would be the correct function?

gabriel-russo commented 7 months ago

I don't fully understand your question, but i will try:

The event will trigger in the map container, so, you have to add a listener to you map instance like this:

map.on("bfl:layerloaded", (ev) => {
         console.log("Your file was read successfully!! Event: ", ev);
});

Also, the plugin will add your layer into map automatically.

Try this:

map.on('bfl:layerloaded', function (event) { 
             layerswitcher.addOverlay(event.layer, event.filename);
});