From 3bac7acb489b801e0d48905a0176f81eb86492b8 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Thu, 16 Apr 2020 21:40:38 +0100 Subject: [PATCH] Use the tile coordinate as a pseudo URL Use the unique tile coordinate as a pseudo tile URL instead of a GeoJSON data URL which may not be unique --- examples/geojson-vt.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/examples/geojson-vt.js b/examples/geojson-vt.js index d5627d6f08..b8d2f5c12e 100644 --- a/examples/geojson-vt.js +++ b/examples/geojson-vt.js @@ -82,6 +82,16 @@ fetch(url) }), }), tileUrlFunction: function (tileCoord) { + // Use the tile coordinate as a pseudo URL for caching purposes + return JSON.stringify(tileCoord); + }, + }); + // For tile loading obtain the GeoJSON for the tile coordinate + // before calling the default tileLoadFunction + const defaultTileLoadFunction = vectorSource.getTileLoadFunction(); + vectorSource.setTileLoadFunction( + function (tile, url) { + const tileCoord = JSON.parse(url); const data = tileIndex.getTile( tileCoord[0], tileCoord[1], @@ -94,9 +104,12 @@ fetch(url) }, replacer ); - return 'data:application/json;charset=UTF-8,' + geojson; - }, - }); + defaultTileLoadFunction( + tile, + 'data:application/json;charset=UTF-8,' + geojson + ); + } + ); const vectorLayer = new VectorTileLayer({ source: vectorSource, });