Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
MINOR: Dont throw, if a Decoder has no style assigned (#1956)
Browse files Browse the repository at this point in the history
Signed-off-by: Frauke Fritz <frauke.fritz@here.com>
  • Loading branch information
FraukeF committed Nov 6, 2020
1 parent da27da7 commit 441876a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion @here/harp-datasource-protocol/lib/ITileDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface ITileDecoder {
tileKey: TileKey,
projection: Projection,
requestController?: RequestController
): Promise<DecodedTile>;
): Promise<DecodedTile | undefined>;

/**
* Get tile info.
Expand Down
8 changes: 6 additions & 2 deletions @here/harp-mapview-decoder/lib/ThemedTileDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
} from "@here/harp-datasource-protocol";
import { StyleSetEvaluator, StyleSetOptions } from "@here/harp-datasource-protocol/index-decoder";
import { Projection, TileKey } from "@here/harp-geoutils";
import { LoggerManager } from "@here/harp-utils";

const logger = LoggerManager.instance.create("ThemedTileDecoder");

/**
* `ThemedTileDecoder` implements an [[ITileDecoder]] which uses a [[Theme]] to apply styles to the
Expand All @@ -35,9 +38,10 @@ export abstract class ThemedTileDecoder implements ITileDecoder {
data: ArrayBufferLike,
tileKey: TileKey,
projection: Projection
): Promise<DecodedTile> {
): Promise<DecodedTile | undefined> {
if (this.m_styleSetEvaluator === undefined) {
return Promise.reject(new Error("No style is defined"));
logger.info("cannot decode tile, as there is not style available");
return Promise.resolve(undefined);
}

return this.decodeThemedTile(data, tileKey, this.m_styleSetEvaluator, projection);
Expand Down
4 changes: 2 additions & 2 deletions @here/harp-mapview-decoder/lib/TileDecoderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class TileDecoderService extends WorkerService {
}
};

decodedTile.geometries.forEach(geom => {
decodedTile?.geometries.forEach(geom => {
geom.vertexAttributes?.forEach(attr => transferBufferAttribute(attr));
geom.interleavedVertexAttributes?.forEach(attr => transferBufferAttribute(attr));
transferBufferAttribute(geom.index);
Expand All @@ -128,7 +128,7 @@ export class TileDecoderService extends WorkerService {
}
});

decodedTile.techniques.forEach(technique => {
decodedTile?.techniques.forEach(technique => {
addBuffersToTransferList(technique, transferList);
});

Expand Down
5 changes: 4 additions & 1 deletion @here/harp-mapview-decoder/lib/TileLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ export class TileLoader extends BaseTileLoader {
*
* @param decodedTile - The [[DecodedTile]].
*/
private onDecoded(decodedTile: DecodedTile, onDone: (doneState: TileLoaderState) => void) {
private onDecoded(
decodedTile: DecodedTile | undefined,
onDone: (doneState: TileLoaderState) => void
) {
this.decodedTile = decodedTile;
onDone(TileLoaderState.Ready);
}
Expand Down
21 changes: 21 additions & 0 deletions @here/harp-vectortile-datasource/test/VectorTileDecoderTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2017-2020 HERE Europe B.V.
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
import { mercatorProjection, TileKey } from "@here/harp-geoutils";
import { expect } from "chai";

import { VectorTileDecoder } from "../index-worker";

// Mocha discourages using arrow functions, see https://mochajs.org/#arrow-functions

describe("ThemedTileDecoder", function() {
it("#decodeTile does not throw", async function() {
const target = new VectorTileDecoder();

expect(
await target.decodeTile(new ArrayBuffer(0), new TileKey(0, 0, 0), mercatorProjection)
).to.not.throw;
});
});

0 comments on commit 441876a

Please sign in to comment.