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
This commit is contained in:
mike-000
2020-04-16 21:40:38 +01:00
committed by GitHub
parent 12043e147c
commit 3bac7acb48

View File

@@ -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,
});