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:
+16
-3
@@ -82,6 +82,16 @@ fetch(url)
|
|||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
tileUrlFunction: function (tileCoord) {
|
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(
|
const data = tileIndex.getTile(
|
||||||
tileCoord[0],
|
tileCoord[0],
|
||||||
tileCoord[1],
|
tileCoord[1],
|
||||||
@@ -94,9 +104,12 @@ fetch(url)
|
|||||||
},
|
},
|
||||||
replacer
|
replacer
|
||||||
);
|
);
|
||||||
return 'data:application/json;charset=UTF-8,' + geojson;
|
defaultTileLoadFunction(
|
||||||
},
|
tile,
|
||||||
});
|
'data:application/json;charset=UTF-8,' + geojson
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
const vectorLayer = new VectorTileLayer({
|
const vectorLayer = new VectorTileLayer({
|
||||||
source: vectorSource,
|
source: vectorSource,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user