improve OpenLayers example; maxzoom and TileState

This commit is contained in:
Brandon Liu
2022-10-28 10:56:18 +08:00
parent 84710d250f
commit 674e92624d

View File

@@ -35,14 +35,18 @@
const y = +result[4]; const y = +result[4];
tile.setLoader((extent, resolution, projection) => { tile.setLoader((extent, resolution, projection) => {
this._p.getZxy(z,x,y).then((result) => { tile.setState(1); // LOADING
if (result) { this._p.getZxy(z,x,y).then((tile_result) => {
if (tile_result) {
const format = tile.getFormat(); const format = tile.getFormat();
const features = format.readFeatures(result.data.buffer, { const features = format.readFeatures(tile_result.data.buffer, {
extent: extent, extent: extent,
featureProjection: projection featureProjection: projection
}); });
tile.setFeatures(features); tile.setFeatures(features);
tile.setState(2); // LOADED
} else {
tile.setState(4); // EMPTY
} }
}); });
}); });
@@ -65,7 +69,7 @@
declutter: true, declutter: true,
source: new ol.source.VectorTile({ source: new ol.source.VectorTile({
attributions:["© Land Information New Zealand"], attributions:["© Land Information New Zealand"],
maxZoom: 15, // this could come from the PMTiles header (async) maxZoom: 14, // this could come from the PMTiles header (async)
format: new ol.format.MVT(), // this could come from the PMTiles header (async) format: new ol.format.MVT(), // this could come from the PMTiles header (async)
url:source.url(), url:source.url(),
tileLoadFunction: source.tileLoadFunction tileLoadFunction: source.tileLoadFunction