use fetchTileData
This commit is contained in:
parent
6335abf36c
commit
638664c8b0
1 changed files with 10 additions and 42 deletions
|
@ -1,6 +1,6 @@
|
||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
import mlcontour from '../node_modules/maplibre-contour/dist/index.mjs';
|
import mlcontour from '../node_modules/maplibre-contour/dist/index.mjs';
|
||||||
import { getPMtilesTile } from './pmtiles_adapter.js';
|
import { fetchTileData } from './utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages local DEM (Digital Elevation Model) data using maplibre-contour.
|
* Manages local DEM (Digital Elevation Model) data using maplibre-contour.
|
||||||
|
@ -117,47 +117,15 @@ export class LocalDemManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let data;
|
const fetchTile = await fetchTileData(
|
||||||
if (this.sourceType === 'pmtiles') {
|
this.source,
|
||||||
let zxyTile;
|
this.sourceType,
|
||||||
if (getPMtilesTile) {
|
$zxy.z,
|
||||||
zxyTile = await getPMtilesTile(
|
$zxy.x,
|
||||||
this.source,
|
$zxy.y,
|
||||||
$zxy.z,
|
);
|
||||||
$zxy.x,
|
if (fetchTile == null) return null;
|
||||||
$zxy.y,
|
let data = fetchTile.data;
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
if (abortController.signal.aborted) {
|
|
||||||
console.log('pmtiles aborted in default');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
zxyTile = {
|
|
||||||
data: new Uint8Array([$zxy.z, $zxy.x, $zxy.y]),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!zxyTile || !zxyTile.data) {
|
|
||||||
throw new Error(`No tile returned for $`);
|
|
||||||
}
|
|
||||||
data = zxyTile.data;
|
|
||||||
} else {
|
|
||||||
data = await new Promise((resolve, reject) => {
|
|
||||||
this.source.getTile($zxy.z, $zxy.x, $zxy.y, (err, tileData) => {
|
|
||||||
if (err) {
|
|
||||||
return /does not exist/.test(err.message)
|
|
||||||
? resolve(null)
|
|
||||||
: reject(err);
|
|
||||||
}
|
|
||||||
resolve(tileData);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
throw new Error(`No tile returned for $`);
|
throw new Error(`No tile returned for $`);
|
||||||
|
|
Loading…
Reference in a new issue