test 2
This commit is contained in:
parent
a10555e2ee
commit
b95a20791f
1 changed files with 27 additions and 18 deletions
|
@ -8,12 +8,12 @@ import { getPMtilesTile } from './pmtiles_adapter.js';
|
||||||
export class LocalDemManager {
|
export class LocalDemManager {
|
||||||
/**
|
/**
|
||||||
* Creates a new LocalDemManager instance.
|
* Creates a new LocalDemManager instance.
|
||||||
* @param {string} encoding - The encoding type for the DEM data.
|
* @param encoding - The encoding type for the DEM data.
|
||||||
* @param {number} maxzoom - The maximum zoom level for the DEM data.
|
* @param maxzoom - The maximum zoom level for the DEM data.
|
||||||
* @param {object} source - The source object that contains either pmtiles or mbtiles.
|
* @param source - The source object that contains either pmtiles or mbtiles.
|
||||||
* @param {'pmtiles' | 'mbtiles'} sourceType - The type of data source
|
* @param {'pmtiles' | 'mbtiles'} sourceType - The type of data source
|
||||||
* @param {Function} [extractZXYFromUrlTrimFunction] - The function to extract the zxy from the url.
|
* @param [extractZXYFromUrlTrimFunction] - The function to extract the zxy from the url.
|
||||||
* @param {Function} [GetTileFunction] - the function that returns a tile from the pmtiles object.
|
* @param [GetTileFunction] - the function that returns a tile from the pmtiles object.
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
encoding,
|
encoding,
|
||||||
|
@ -27,9 +27,8 @@ export class LocalDemManager {
|
||||||
this.maxzoom = maxzoom;
|
this.maxzoom = maxzoom;
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.sourceType = sourceType;
|
this.sourceType = sourceType;
|
||||||
this.getTile = GetTileFunction || this.GetTile.bind(this);
|
this._getTile = GetTileFunction;
|
||||||
this.extractZXYFromUrlTrim =
|
this._extractZXYFromUrlTrim = extractZXYFromUrlTrimFunction;
|
||||||
extractZXYFromUrlTrimFunction || this.extractZXYFromUrlTrim.bind(this);
|
|
||||||
|
|
||||||
this.manager = new mlcontour.LocalDemManager({
|
this.manager = new mlcontour.LocalDemManager({
|
||||||
demUrlPattern: '/{z}/{x}/{y}',
|
demUrlPattern: '/{z}/{x}/{y}',
|
||||||
|
@ -42,12 +41,22 @@ export class LocalDemManager {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get getTileFunction() {
|
||||||
|
return this._getTile ? this._getTile.bind(this) : this.GetTile.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
get extractZXYFromUrlTrim() {
|
||||||
|
return this._extractZXYFromUrlTrim
|
||||||
|
? this._extractZXYFromUrlTrim.bind(this)
|
||||||
|
: this._extractZXYFromUrlTrimFunction.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes image data from a blob.
|
* Processes image data from a blob.
|
||||||
* @param {Blob} blob - The image data as a Blob.
|
* @param blob - The image data as a Blob.
|
||||||
* @param {AbortController} abortController - An AbortController to cancel the image processing.
|
* @param abortController - An AbortController to cancel the image processing.
|
||||||
* @returns {Promise<any>} - A Promise that resolves with the processed image data, or null if aborted.
|
* @returns {Promise<any>} - A Promise that resolves with the processed image data, or null if aborted.
|
||||||
* @throws {Error} If an error occurs during image processing.
|
* @throws If an error occurs during image processing.
|
||||||
*/
|
*/
|
||||||
async getImageData(blob, abortController) {
|
async getImageData(blob, abortController) {
|
||||||
try {
|
try {
|
||||||
|
@ -81,10 +90,10 @@ export class LocalDemManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches a tile using the provided url and abortController
|
* Fetches a tile using the provided url and abortController
|
||||||
* @param {string} url - The url that should be used to fetch the tile.
|
* @param url - The url that should be used to fetch the tile.
|
||||||
* @param {AbortController} abortController - An AbortController to cancel the request.
|
* @param abortController - An AbortController to cancel the request.
|
||||||
* @returns {Promise<{data: Blob, expires: undefined, cacheControl: undefined}>} A promise that resolves with the response data.
|
* @returns {Promise<{data: Blob, expires: undefined, cacheControl: undefined}>} A promise that resolves with the response data.
|
||||||
* @throws {Error} If an error occurs fetching or processing the tile.
|
* @throws If an error occurs fetching or processing the tile.
|
||||||
*/
|
*/
|
||||||
async GetTile(url, abortController) {
|
async GetTile(url, abortController) {
|
||||||
console.log(url);
|
console.log(url);
|
||||||
|
@ -100,7 +109,7 @@ export class LocalDemManager {
|
||||||
let data;
|
let data;
|
||||||
if (this.sourceType === 'pmtiles') {
|
if (this.sourceType === 'pmtiles') {
|
||||||
let zxyTile;
|
let zxyTile;
|
||||||
if (this.getPMtilesTile) {
|
if (getPMtilesTile) {
|
||||||
zxyTile = await getPMtilesTile(
|
zxyTile = await getPMtilesTile(
|
||||||
this.source,
|
this.source,
|
||||||
$zxy.z,
|
$zxy.z,
|
||||||
|
@ -160,10 +169,10 @@ export class LocalDemManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation for extracting z,x,y from a url
|
* Default implementation for extracting z,x,y from a url
|
||||||
* @param {string} url - The url to extract from
|
* @param url - The url to extract from
|
||||||
* @returns {{z: number, x: number, y:number} | null} Returns the z,x,y of the url, or null if can't extract
|
* @returns {{z: number, x: number, y:number} | null} Returns the z,x,y of the url, or null if can't extract
|
||||||
*/
|
*/
|
||||||
extractZXYFromUrlTrim(url) {
|
_extractZXYFromUrlTrimFunction(url) {
|
||||||
// 1. Find the index of the last `/`
|
// 1. Find the index of the last `/`
|
||||||
const lastSlashIndex = url.lastIndexOf('/');
|
const lastSlashIndex = url.lastIndexOf('/');
|
||||||
if (lastSlashIndex === -1) {
|
if (lastSlashIndex === -1) {
|
||||||
|
@ -197,7 +206,7 @@ export class LocalDemManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the underlying maplibre-contour LocalDemManager
|
* Get the underlying maplibre-contour LocalDemManager
|
||||||
* @returns {any} the underlying maplibre-contour LocalDemManager
|
* @returns the underlying maplibre-contour LocalDemManager
|
||||||
*/
|
*/
|
||||||
getManager() {
|
getManager() {
|
||||||
return this.manager;
|
return this.manager;
|
||||||
|
|
Loading…
Reference in a new issue