stuartmatthews / leaflet-geotiff

Leaflet plugin for displaying geoTIFF raster data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Detect the GeoTIFF has been fully loaded

tirengarfio opened this issue · comments

Hi,

is is possible to detect when the geotiff has been loaded to, for example, get the min and the max values from the main?

I mean: based on the version 2 of this library, I have added the lines that you can see in this snippet below, to get the min and the max values:

        this.tiff = GeoTIFF.parse(arrayBuffer);

        if (typeof(this.options.image)=='undefined') {
            this.options.image = 0;
        }
        if (typeof(this.options.band)=='undefined') {
            this.options.band = 0;
        }
        this.setBand(this.options.band);

        // I have added these lines below to the original library
        this.min = this.raster.data
            .filter((val) => val !== this.options.noDataValue)
            .reduce((a, b) => Math.min(a, b));

        this.max = this.raster.data
            .filter((val) => val !== this.options.noDataValue)
            .reduce((a, b) => Math.max(a, b));

And on my main code I have this:

            var windSpeed = L.leafletGeotiff(
                url= filename,
                options={
                    band: 0,
                    displayMin: 0,
                    displayMax: 30,
                    name: 'Wind speed',
                    colorScale: 'mycolorscale',
                    clampLow: false,
                    clampHigh: true,
                    //vector:true,
                    arrowSize: 20,
                    // opacity: 0.3
                }
            ).addTo(mymap);

            console.log(windSpeed.min);
            console.log(windSpeed.max);

but I get 'undefined' from both of console.log() calls I guess because the AJAX request is asynchronous. Since I don't want to use a synchronous AJAX request, how can I get the min and max values?

Javier

Hi how can i change the lat lng bounds from australia to another location

Hi @tirengarfio, use async and await to fully load the tiff before doing something else. You can refer to https://geotiffjs.github.io/ for the latest update.