onaci / leaflet-geotiff-2

Leaflet plugin for displaying geoTIFF raster data
https://onaci.github.io/leaflet-geotiff-2/
Other
58 stars 20 forks source link

onSuccess event #37

Open eelcocramer opened 2 years ago

eelcocramer commented 2 years ago

It would be nice to have an event that would tell the caller that the image has successfully been processed. This would allow the UI to show a spinner while the image is being loaded / processed.

I can contribute on this if someone can give some pointers about where to add this.

danwild commented 2 years ago

Hi @eelcocramer,

For initial load of data, you could use the sourceFunction option with something other than GeoTIFF.fromUrl (i.e. handle the async pre-load of data yourself).

For a true onSuccess event tho, the renderer itself would also need to provide a callback/event in order for us to know when it is done (so if you are using the plotty renderer, step 1 would be to check if it has something like this, or if one could be added).

eelcocramer commented 2 years ago

Thanks for your response @danwild I appreciate it.

Before I opened this issue I tried loading the data myself in both a blob and arraybuffer but geotiff.js throws an error when processing that data: TypeError: Invalid byte order value.. The fromUrl method does not show this behaviour.

Actually I found that the rendering of data is quite fast. Loading seem to be the issue. The backend I'm hitting takes a couple of seconds to process a request. I notice though that fromUrl is hitting the backend 6 (!) times when I use it to load the image.

eelcocramer commented 2 years ago

When I run the demo the tif's are only requested once so I assume something must be wrong on my (front- or back-) end.

eelcocramer commented 2 years ago

Increasing the blockSize fixes the issue where the tiff is requested multiple times.

I can't get the fromArrayBuffer to work. This expression is always true. First I believed it was because I used geotiffjs version > 2 but when I downgraded to the version listed in this project this still happens.

edit: never mind I did not import geotiff.js correctly

eelcocramer commented 2 years ago

For initial load of data, you could use the sourceFunction option with something other than GeoTIFF.fromUrl (i.e. handle the async pre-load of data yourself).

So this suggestion works fine actually. I don't really need an onSuccess on the rendering so as far as I'm concerned this issue may be closed.

Thanks for the help!

muety commented 2 years ago

I'd be happy to have an onSuccess function :)

Btw., is there a downside to setting blockSize arbitrarily high?

crawld commented 2 years ago

GeoTIFF.fromUrl is useful for loading a subset of the data from a large tiff.

In #38 I added a loadTiff event.