leaflet-geotiff-2 icon indicating copy to clipboard operation
leaflet-geotiff-2 copied to clipboard

Possible to add multiple geotiff files?

Open mttucl opened this issue 2 years ago • 4 comments

I'm using FileReader to add multiple files. It works fine for one file but when adding more files, only the last file is rendered correctly. I think it an issue with transform(rasterImageData, args) function as it is trying to apply data from the last file to the other files. Below is the relevant code and here is working example in JSFiddle.

   document.getElementById("input-file").addEventListener("change", function(event) {
   let file = event.target.files[0];
   let reader = new FileReader();
   let result = reader.result;
    
    reader.onloadend = function() {
        const layer = L.leafletGeotiff(result, {
          renderer: plottyRenderer,
          sourceFunction: GeoTIFF.fromArrayBuffer,
          arrayBuffer: result 
        });
        layer.addTo(map);

        layerControl.addOverlay(layer, file.name);
    };

    reader.readAsArrayBuffer(file);
  });

Another minor issue, I get [object%20ArrayBuffer] 404 (Not Found) error from layer.addTo(map);. It renders the layer correctly but it seems related to FileReader (async) and onAdd @ leaflet-geotiff.js:116. No issue if layer is not added to the map.

mttucl avatar Jul 02 '22 20:07 mttucl