typescript - Uppdatering från 8.2.0 till 10.2.1 bryter anpassad flikningsladdningsfunktion med cache


Kontext: Jag har en utökad VectorTileSource-klass som ändrar tileLoadFunction till en anpassad. Denna nya funktion använder en cache för att lagra kakel och leverera dem om de redan är laddade. Dessutom, när ett kakel laddas, förladdas alla pbfs för det kaklet vid olika tidpunkter och sparas i cachen. Denna förladdning görs för att undvika blinkningseffekten som uppstår när ett nytt kakel visas för första gången.

Problem: När man uppdaterar OpenLayers-versionen från 8.2.0 till 10.2.1 bryts denna preload-del och blinkandet dyker upp igen när en kakel visas för första gången.

Kod:

export class VectorTileSourceWithCache extends VectorTileSource {
    constructor (options: Options) {
        super(options);
        this.tileLoadFunction = this.tileLoadFunctionWithCache.bind(this);
    }

    private async preloadAllInstances (baseUrl: string, tile: any, extent: Extent, projection: ProjectionLike): Promise<void> {
        const vectorTileStore = useVectorTileStore();
        // Get the instants to preload
        const instants = [/*array of instants*/];
        const urls: string[] = [];
        for (const instant of instants) {
            // Build url for instant
            const url = "url";
            urls.push(url);
        }

        vectorTileStore.addUlrsToPreloadQueue(urls, tile, extent, projection);
    }

    private tileLoadFunctionWithCache (tile: any, url: string): void {
        const vectorTileStore = useVectorTileStore();
        tile.setLoader(async (extent: Extent, _resolution: number, projection: ProjectionLike) => {
            if (!vectorTileStore.isTileInProductBounds(url)) {
                tile.setFeatures([] as Array<Feature<Geometry>>);
            } else if (vectorTileStore.isTileLoaded(url)) {
                const data = vectorTileStore.getDataByUrl(url);
                if (data) {
                    const format = tile.getFormat() as MVT;
                    const features = format.readFeatures(data, {
                        extent,
                        featureProjection: projection as any
                    });
                    tile.setFeatures(features as Array<Feature<Geometry>>);
                } else {
                    tile.setFeatures([] as Array<Feature<Geometry>>);
                }
            } else {
                console.log("PBF not found, requesting...");
                // Fetch tile data if not cached
                try {
                    const response = await axios.get(url, { responseType: "arraybuffer" });
                    if (response.status !== 200) {
                        tile.setFeatures([] as Array<Feature<Geometry>>);
                    } else {
                        const data = response.data;
                        const format = tile.getFormat() as MVT;
                        const features = format.readFeatures(data, {
                            extent,
                            featureProjection: projection as any
                        });
                        tile.setFeatures(features as Array<Feature<Geometry>>);
                        vectorTileStore.addFeatures(url, data, format, extent, projection);
                    }
                } catch (error) {
                    console.error("Error loading tile:", error);
                }
            }
            await this.preloadAllInstances(url, tile, extent, projection);
        });
    }
}

Exempel:

Utan att blinka (Openayers version 8.2.0)

Med blinkande (openayers version 10.2.1)

Uppdatering till 10.2.1 gör att TypeScript ger typfel. Att åtgärda dem verkar inte lösa problemet. Jag vet inte vilka förändringar mellan v8.2.0 och v10.2.1 som orsakar detta eller om det har något att göra med detta problem.