Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@here/harp-mapview-decoder

Package Overview
Dependencies
Maintainers
3
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@here/harp-mapview-decoder - npm Package Compare versions

Comparing version
0.20.1
to
0.21.0
+1
-1
lib/TileDataSource.d.ts

@@ -66,3 +66,3 @@ import { Definitions, ITileDecoder, StyleSet, Theme, TileInfo } from "@here/harp-datasource-protocol";

*/
create(dataSource: DataSource, tileKey: TileKey): TileType;
create(dataSource: TileDataSource<TileType>, tileKey: TileKey): TileType;
}

@@ -69,0 +69,0 @@ /**

@@ -33,3 +33,5 @@ "use strict";

create(dataSource, tileKey) {
return new this.m_modelConstructor(dataSource, tileKey);
const tile = new this.m_modelConstructor(dataSource, tileKey);
tile.tileLoader = new TileLoader_1.TileLoader(dataSource, tileKey, dataSource.dataProvider(), dataSource.decoder);
return tile;
}

@@ -151,3 +153,2 @@ }

const tile = this.m_tileFactory.create(this, tileKey);
tile.tileLoader = new TileLoader_1.TileLoader(this, tileKey, this.m_options.dataProvider, this.decoder, 0);
tile.copyrightInfo = this.m_options.copyrightInfo;

@@ -178,3 +179,3 @@ if (this.m_options.copyrightProvider !== undefined) {

const promise = new Promise((resolve, reject) => {
const tileLoader = new TileLoader_1.TileInfoLoader(this, tileKey, this.m_options.dataProvider, this.decoder, 0);
const tileLoader = new TileLoader_1.TileInfoLoader(this, tileKey, this.m_options.dataProvider, this.decoder);
tileLoader.loadAndDecode().then(loaderState => {

@@ -181,0 +182,0 @@ if (loaderState === harp_mapview_1.TileLoaderState.Ready) {

import "@here/harp-fetch";
import { DecodedTile, ITileDecoder, RequestController, TileInfo } from "@here/harp-datasource-protocol";
import { TileKey } from "@here/harp-geoutils";
import { DataSource, ITileLoader, TileLoaderState } from "@here/harp-mapview";
import { BaseTileLoader, DataSource } from "@here/harp-mapview";
import { TileLoaderState } from "@here/harp-mapview/lib/ITileLoader";
import { DataProvider } from "./DataProvider";

@@ -10,3 +11,3 @@ /**

*/
export declare class TileLoader implements ITileLoader {
export declare class TileLoader extends BaseTileLoader {
protected dataSource: DataSource;

@@ -16,12 +17,3 @@ protected tileKey: TileKey;

protected tileDecoder: ITileDecoder;
priority: number;
/**
* Current state of `TileLoader`.
*/
state: TileLoaderState;
/**
* Error object if loading or decoding failed.
*/
error?: Error;
/**
* The binary data in form of [[ArrayBufferLike]], or any object.

@@ -35,6 +27,2 @@ */

/**
* The abort controller notifying the [[DataProvider]] to cancel loading.
*/
protected loadAbortController: AbortController;
/**
* The notifying the [[ITileDecoder]] to cancel decoding.

@@ -44,14 +32,2 @@ */

/**
* The promise which is resolved when loading and decoding have finished.
*/
protected donePromise?: Promise<TileLoaderState>;
/**
* The internal function that is called when loading and decoding have finished successfully.
*/
protected resolveDonePromise?: (state: TileLoaderState) => void;
/**
* The internal function that is called when loading and decoding failed.
*/
protected rejectedDonePromise?: (state: TileLoaderState) => void;
/**
* Set up loading of a single [[Tile]].

@@ -63,37 +39,25 @@ *

* @param tileDecoder - The [[ITileDecoder]] that decodes the binary tile to a [[DecodeTile]].
* @param priority - The priority given to the loading job. Highest number will be served first.
*/
constructor(dataSource: DataSource, tileKey: TileKey, dataProvider: DataProvider, tileDecoder: ITileDecoder, priority: number);
constructor(dataSource: DataSource, tileKey: TileKey, dataProvider: DataProvider, tileDecoder: ITileDecoder);
/**
* Start loading and/or proceed through the various states of loading of this tile.
*
* @returns A promise which resolves the [[TileLoaderState]].
* @override
*/
loadAndDecode(): Promise<TileLoaderState>;
get priority(): number;
/**
* Return the current state in form of a promise. Caller can then wait for the promise to be
* resolved.
*
* @returns A promise which resolves the current [[TileLoaderState]].
* @override
*/
waitSettled(): Promise<TileLoaderState>;
set priority(priority: number);
/**
* Cancel loading of the [[Tile]].
* Cancellation token is notified, an internal state is cleaned up.
* @override
*/
cancel(): void;
protected loadImpl(abortSignal: AbortSignal, onDone: (doneState: TileLoaderState) => void, onError: (error: Error) => void): void;
/**
* Return `true` if [[Tile]] is still loading, `false` otherwise.
* @override
*/
get isFinished(): boolean;
protected cancelImpl(): void;
/**
* Update the priority of this [[Tile]]'s priority. Is effective to sort the decoding requests
* in the request queue (used during heavy load).
* Start decoding the payload.
*/
updatePriority(priority: number): void;
protected startDecodeTile(onDone: (doneState: TileLoaderState) => void, onError: (error: Error) => void): void;
/**
* Start loading. Only call if loading did not start yet.
*/
protected startLoading(): void;
/**
* Called when binary data has been loaded. The loading state is now progressing to decoding.

@@ -103,8 +67,4 @@ *

*/
protected onLoaded(payload: ArrayBufferLike | {}): void;
private onLoaded;
/**
* Start decoding the payload.
*/
protected startDecodeTile(): void;
/**
* Called when the decoding is finished, and the [[DecodedTile]] has been created.

@@ -114,20 +74,3 @@ *

*/
protected onDecoded(decodedTile: DecodedTile): void;
/**
* Cancel the decoding process.
*/
protected cancelDecoding(): void;
/**
* Called when loading and decoding has finished successfully. Resolves loading promise if the
* state is Ready, otherwise it rejects the promise with the supplied state.
*
* @param doneState - The latest state of loading.
*/
protected onDone(doneState: TileLoaderState): void;
/**
* Called when loading or decoding has finished with an error.
*
* @param error - Error object describing the failing.
*/
protected onError(error: Error): void;
private onDecoded;
}

@@ -141,4 +84,4 @@ /**

/** @override */
protected startDecodeTile(): void;
protected startDecodeTile(onDone: (doneState: TileLoaderState) => void, onError: (error: Error) => void): void;
}
//# sourceMappingURL=TileLoader.d.ts.map

@@ -12,2 +12,3 @@ "use strict";

const harp_mapview_1 = require("@here/harp-mapview");
const ITileLoader_1 = require("@here/harp-mapview/lib/ITileLoader");
const harp_utils_1 = require("@here/harp-utils");

@@ -22,3 +23,3 @@ /**

*/
class TileLoader {
class TileLoader extends harp_mapview_1.BaseTileLoader {
/**

@@ -31,5 +32,5 @@ * Set up loading of a single [[Tile]].

* @param tileDecoder - The [[ITileDecoder]] that decodes the binary tile to a [[DecodeTile]].
* @param priority - The priority given to the loading job. Highest number will be served first.
*/
constructor(dataSource, tileKey, dataProvider, tileDecoder, priority) {
constructor(dataSource, tileKey, dataProvider, tileDecoder) {
super(dataSource, tileKey);
this.dataSource = dataSource;

@@ -39,78 +40,14 @@ this.tileKey = tileKey;

this.tileDecoder = tileDecoder;
this.priority = priority;
/**
* Current state of `TileLoader`.
*/
this.state = harp_mapview_1.TileLoaderState.Initialized;
/**
* The abort controller notifying the [[DataProvider]] to cancel loading.
*/
this.loadAbortController = new AbortController();
}
/**
* Start loading and/or proceed through the various states of loading of this tile.
*
* @returns A promise which resolves the [[TileLoaderState]].
* @override
*/
loadAndDecode() {
switch (this.state) {
case harp_mapview_1.TileLoaderState.Loading:
case harp_mapview_1.TileLoaderState.Loaded:
case harp_mapview_1.TileLoaderState.Decoding:
// tile is already loading
return this.donePromise;
case harp_mapview_1.TileLoaderState.Ready:
case harp_mapview_1.TileLoaderState.Failed:
case harp_mapview_1.TileLoaderState.Initialized:
case harp_mapview_1.TileLoaderState.Canceled:
// restart loading
this.startLoading();
return this.donePromise;
}
get priority() {
return this.m_priority;
}
/**
* Return the current state in form of a promise. Caller can then wait for the promise to be
* resolved.
*
* @returns A promise which resolves the current [[TileLoaderState]].
* @override
*/
waitSettled() {
if (!this.donePromise) {
return Promise.resolve(this.state);
}
return this.donePromise;
}
/**
* Cancel loading of the [[Tile]].
* Cancellation token is notified, an internal state is cleaned up.
*/
cancel() {
switch (this.state) {
case harp_mapview_1.TileLoaderState.Loading:
this.loadAbortController.abort();
this.loadAbortController = new AbortController();
break;
case harp_mapview_1.TileLoaderState.Decoding:
if (this.requestController) {
this.requestController.abort();
this.requestController = undefined;
}
break;
}
this.onDone(harp_mapview_1.TileLoaderState.Canceled);
}
/**
* Return `true` if [[Tile]] is still loading, `false` otherwise.
*/
get isFinished() {
return (this.state === harp_mapview_1.TileLoaderState.Ready ||
this.state === harp_mapview_1.TileLoaderState.Canceled ||
this.state === harp_mapview_1.TileLoaderState.Failed);
}
/**
* Update the priority of this [[Tile]]'s priority. Is effective to sort the decoding requests
* in the request queue (used during heavy load).
*/
updatePriority(priority) {
this.priority = priority;
set priority(priority) {
this.m_priority = priority;
if (this.requestController !== undefined) {

@@ -121,10 +58,9 @@ this.requestController.priority = priority;

/**
* Start loading. Only call if loading did not start yet.
* @override
*/
startLoading() {
const myLoadCancellationToken = this.loadAbortController.signal;
loadImpl(abortSignal, onDone, onError) {
this.dataProvider
.getTile(this.tileKey, myLoadCancellationToken)
.getTile(this.tileKey, abortSignal)
.then(payload => {
if (myLoadCancellationToken.aborted) {
if (abortSignal.aborted) {
// safety belt if getTile doesn't really support cancellation tokens

@@ -135,3 +71,3 @@ const err = new Error("Aborted");

}
this.onLoaded(payload);
this.onLoaded(payload, onDone, onError);
})

@@ -143,32 +79,14 @@ .catch(error => {

}
this.onError(error);
onError(error);
});
if (this.donePromise === undefined) {
this.donePromise = new Promise((resolve, reject) => {
this.resolveDonePromise = resolve;
this.rejectedDonePromise = reject;
});
}
this.state = harp_mapview_1.TileLoaderState.Loading;
}
/**
* Called when binary data has been loaded. The loading state is now progressing to decoding.
*
* @param payload - Binary data in form of [[ArrayBufferLike]], or any object.
* @override
*/
onLoaded(payload) {
this.state = harp_mapview_1.TileLoaderState.Loaded;
this.payload = payload;
const byteLength = payload.byteLength;
if (byteLength === 0 ||
(payload.constructor === Object && Object.keys(payload).length === 0)) {
// Object is empty
this.onDecoded({
geometries: [],
techniques: []
});
return;
cancelImpl() {
if (this.state === ITileLoader_1.TileLoaderState.Decoding && this.requestController) {
// we should cancel any decodes already in progress!
this.requestController.abort();
this.requestController = undefined;
}
// TBD: we might suspend decode if tile is not visible ... ?
this.startDecodeTile();
}

@@ -178,3 +96,3 @@ /**

*/
startDecodeTile() {
startDecodeTile(onDone, onError) {
const payload = this.payload;

@@ -185,3 +103,3 @@ if (payload === undefined) {

}
this.state = harp_mapview_1.TileLoaderState.Decoding;
this.state = ITileLoader_1.TileLoaderState.Decoding;
this.payload = undefined;

@@ -200,3 +118,3 @@ // Save our cancellation point, so we can be reliably cancelled by any subsequent decode

}
this.onDecoded(decodedTile);
this.onDecoded(decodedTile, onDone);
})

@@ -209,58 +127,35 @@ .catch(error => {

}
this.onError(error);
onError(error);
});
}
/**
* Called when the decoding is finished, and the [[DecodedTile]] has been created.
* Called when binary data has been loaded. The loading state is now progressing to decoding.
*
* @param decodedTile - The [[DecodedTile]].
* @param payload - Binary data in form of [[ArrayBufferLike]], or any object.
*/
onDecoded(decodedTile) {
this.decodedTile = decodedTile;
this.onDone(harp_mapview_1.TileLoaderState.Ready);
}
/**
* Cancel the decoding process.
*/
cancelDecoding() {
if (this.requestController !== undefined) {
// we should cancel any decodes already in progress!
this.requestController.abort();
this.requestController = undefined;
onLoaded(payload, onDone, onError) {
this.state = ITileLoader_1.TileLoaderState.Loaded;
this.payload = payload;
const byteLength = payload.byteLength;
if (byteLength === 0 ||
(payload.constructor === Object && Object.keys(payload).length === 0)) {
// Object is empty
this.onDecoded({
geometries: [],
techniques: []
}, onDone);
return;
}
// TBD: we might suspend decode if tile is not visible ... ?
this.startDecodeTile(onDone, onError);
}
/**
* Called when loading and decoding has finished successfully. Resolves loading promise if the
* state is Ready, otherwise it rejects the promise with the supplied state.
* Called when the decoding is finished, and the [[DecodedTile]] has been created.
*
* @param doneState - The latest state of loading.
* @param decodedTile - The [[DecodedTile]].
*/
onDone(doneState) {
if (this.resolveDonePromise && doneState === harp_mapview_1.TileLoaderState.Ready) {
this.resolveDonePromise(doneState);
}
else if (this.rejectedDonePromise) {
this.rejectedDonePromise(doneState);
}
this.resolveDonePromise = undefined;
this.rejectedDonePromise = undefined;
this.donePromise = undefined;
this.state = doneState;
onDecoded(decodedTile, onDone) {
this.decodedTile = decodedTile;
onDone(ITileLoader_1.TileLoaderState.Ready);
}
/**
* Called when loading or decoding has finished with an error.
*
* @param error - Error object describing the failing.
*/
onError(error) {
if (this.state === harp_mapview_1.TileLoaderState.Canceled) {
// If we're canceled, we should simply ignore any state transitions and errors from
// underlying load/decode ops.
return;
}
const dataSource = this.dataSource;
logger.error(`[${dataSource.name}]: failed to load tile ${this.tileKey.mortonCode()}`, error);
this.error = error;
this.onDone(harp_mapview_1.TileLoaderState.Failed);
}
}

@@ -274,3 +169,3 @@ exports.TileLoader = TileLoader;

/** @override */
startDecodeTile() {
startDecodeTile(onDone, onError) {
const payload = this.payload;

@@ -281,3 +176,3 @@ if (payload === undefined) {

}
this.state = harp_mapview_1.TileLoaderState.Decoding;
this.state = ITileLoader_1.TileLoaderState.Decoding;
this.payload = undefined;

@@ -297,3 +192,3 @@ // Save our cancellation point, so we can be reliably cancelled by any subsequent decode

this.tileInfo = tileInfo;
this.onDone(harp_mapview_1.TileLoaderState.Ready);
onDone(ITileLoader_1.TileLoaderState.Ready);
})

@@ -306,3 +201,3 @@ .catch(error => {

}
this.onError(error);
onError(error);
});

@@ -309,0 +204,0 @@ }

{
"name": "@here/harp-mapview-decoder",
"version": "0.20.1",
"version": "0.21.0",
"description": "Decoder worker for mapview",

@@ -29,12 +29,12 @@ "main": "index.js",

"dependencies": {
"@here/harp-datasource-protocol": "^0.20.1",
"@here/harp-fetch": "^0.20.0",
"@here/harp-geoutils": "^0.20.0",
"@here/harp-lrucache": "^0.20.0",
"@here/harp-mapview": "^0.20.1",
"@here/harp-utils": "^0.20.0",
"@here/harp-datasource-protocol": "^0.21.0",
"@here/harp-fetch": "^0.21.0",
"@here/harp-geoutils": "^0.21.0",
"@here/harp-lrucache": "^0.21.0",
"@here/harp-mapview": "^0.21.0",
"@here/harp-utils": "^0.21.0",
"geojson-vt": "^3.2.1"
},
"devDependencies": {
"@here/harp-test-utils": "^0.20.0",
"@here/harp-test-utils": "^0.21.0",
"@types/chai": "^4.2.11",

@@ -55,3 +55,3 @@ "@types/chai-as-promised": "^7.1.2",

},
"gitHead": "721342146b114c891f67127fb92533bac0d2460b"
"gitHead": "460af4b155d303d96cb69152cbdbc3ff4c72213e"
}