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

Commit

Permalink
MINOR: Adds support for DataSourceOptions in WebTileDataSource (#1819)
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 Sep 4, 2020
1 parent bf17797 commit 7fefd71
Show file tree
Hide file tree
Showing 4 changed files with 351 additions and 72 deletions.
35 changes: 16 additions & 19 deletions @here/harp-webtile-datasource/lib/WebTileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { TileKey, TilingScheme, webMercatorTilingScheme } from "@here/harp-geoutils";
import { CopyrightInfo, DataSource, Tile } from "@here/harp-mapview";
import { CopyrightInfo, DataSource, DataSourceOptions, Tile } from "@here/harp-mapview";
import { TileGeometryCreator } from "@here/harp-mapview/lib/geometry/TileGeometryCreator";
import { getOptionValue, LoggerManager } from "@here/harp-utils";
import THREE = require("three");
Expand All @@ -20,6 +20,12 @@ export interface WebTileRenderingOptions {
* @default 1.0
*/
opacity?: number;

/**
* Force Material to use transparency from texture if available
* @default false
*/
transparent?: boolean;
}

export interface WebTileDataProvider {
Expand All @@ -32,7 +38,8 @@ export interface WebTileDataProvider {
/**
* Options for [[WebTileDataSource]].
*/
export interface WebTileDataSourceOptions {
export interface WebTileDataSourceOptions
extends Omit<DataSourceOptions, "enablePicking" | "styleSetName"> {
/**
* A DataProvider that will provide the tiles.
*/
Expand All @@ -43,16 +50,6 @@ export interface WebTileDataSourceOptions {
*/
resolution?: WebTileDataSource.resolutionValue;

/**
* The minimal level Data is available, @defaults 1
*/
minDataLevel?: number;

/**
* The maximal level Data is available, @defaults 20
*/
maxDataLevel?: number;

/**
* Options affecting the rendering of the web tiles.
*/
Expand Down Expand Up @@ -83,11 +80,7 @@ export class WebTileDataSource extends DataSource {
* @param m_options - Represents the [[WebTileDataSourceParameters]].
*/
constructor(protected readonly m_options: WebTileDataSourceOptions) {
super({
name: "webtile",
minDataLevel: getOptionValue(m_options.minDataLevel, 1),
maxDataLevel: getOptionValue(m_options.maxDataLevel, 20)
});
super(m_options);

this.dataProvider = this.m_options.dataProvider;
this.cacheable = true;
Expand Down Expand Up @@ -128,16 +121,20 @@ export class WebTileDataSource extends DataSource {
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
tile.addOwnedTexture(texture);
const transparent =
this.m_options.renderingOptions !== undefined &&
this.m_options.renderingOptions.transparent === true;
const opacity =
this.m_options.renderingOptions !== undefined
this.m_options.renderingOptions !== undefined &&
this.m_options.renderingOptions.opacity !== undefined
? this.m_options.renderingOptions.opacity
: 1;
const material = new THREE.MeshBasicMaterial({
map: texture,
depthTest: false,
depthWrite: false,
opacity,
transparent: opacity !== undefined && opacity < 1.0 ? true : false
transparent: transparent || (opacity !== undefined && opacity < 1.0)
});
const mesh = TileGeometryCreator.instance.createGroundPlane(tile, material, true);
tile.objects.push(mesh);
Expand Down
73 changes: 73 additions & 0 deletions @here/harp-webtile-datasource/test/HereWebTileDataSourceTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2017-2020 HERE Europe B.V.
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/

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

import { assert } from "chai";

import { HereTileProvider, HereWebTileDataSource, WebTileDataSource } from "../index";

describe("HereWebTileDataSource", function() {
it("#createWebTileDataSource has default values", async function() {
const apikey = "123";
const webTileDataSource = new HereWebTileDataSource({
apikey
});
assert(webTileDataSource.maxDataLevel === 19);
});
it("#createWebTileDataSource with token authentication", async function() {
const webTileDataSource = new HereWebTileDataSource({
authenticationCode: "foo123"
});
assert(webTileDataSource.maxDataLevel === 19);
});
it("#createWebTileDataSource with 256px and ppi320", async function() {
const apikey = "123";
const webTileDataSource = new HereWebTileDataSource({
apikey,
resolution: WebTileDataSource.resolutionValue.resolution256,
ppi: WebTileDataSource.ppiValue.ppi320
});
assert(webTileDataSource.maxDataLevel === 20);
});
it("#createWebTileDataSource with satellite.day", async function() {
const apikey = "123";
const webTileDataSource = new HereWebTileDataSource({
apikey,
tileBaseAddress: HereTileProvider.TILE_AERIAL_SATELLITE
});
assert(webTileDataSource.maxDataLevel === 19);
});
it("#createWebTileDataSource with satellite.day and 256px", async function() {
const apikey = "123";
const webTileDataSource = new HereWebTileDataSource({
apikey,
tileBaseAddress: HereTileProvider.TILE_AERIAL_SATELLITE,
resolution: WebTileDataSource.resolutionValue.resolution256
});
assert(webTileDataSource.maxDataLevel === 20);
});
it("#createWebTileDataSource throws with satellite.day and ppi320", async function() {
const apikey = "123";
assert.throw(
() =>
new HereWebTileDataSource({
apikey,
tileBaseAddress: HereTileProvider.TILE_AERIAL_SATELLITE,
ppi: WebTileDataSource.ppiValue.ppi320
})
);
});
it("#createWebTileDataSource throws w/o auth.", async function() {
assert.throw(() => new HereWebTileDataSource({} as any));
});
it("#createWebTileDataSource throws w/ missing appCode", async function() {
assert.throw(() => new HereWebTileDataSource({ appId: "42" } as any));
});
it("#createWebTileDataSource throws w/ missing appId", async function() {
assert.throw(() => new HereWebTileDataSource({ appCode: "42" } as any));
});
});
116 changes: 63 additions & 53 deletions @here/harp-webtile-datasource/test/WebTileTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,81 @@
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
import { mercatorProjection, TileKey } from "@here/harp-geoutils";
import { CopyrightInfo, MapView, Tile } from "@here/harp-mapview";
import { TileGeometryCreator } from "@here/harp-mapview/lib/geometry/TileGeometryCreator";
import { expect } from "chai";
import * as sinon from "sinon";

// Mocha discourages using arrow functions, see https://mochajs.org/#arrow-functions
import { WebTileDataSource } from "../index";

import { assert } from "chai";
describe("WebTileDataSource", function() {
const fakeWebTileProvider = {
getTexture: sinon.spy((tile: Tile) => {
return Promise.resolve(([{}, []] as unknown) as [THREE.Texture, CopyrightInfo[]]);
})
};

import { HereTileProvider, HereWebTileDataSource, WebTileDataSource } from "../index";
const fakeMapView = {
projection: mercatorProjection
} as MapView;

describe("WebTileDataSource", function() {
it("#createWebTileDataSource has default values", async function() {
const apikey = "123";
const webTileDataSource = new HereWebTileDataSource({
apikey
const webTileDataSource = new WebTileDataSource({
dataProvider: fakeWebTileProvider
});
assert(webTileDataSource.maxDataLevel === 19);

expect(webTileDataSource.maxDataLevel).to.equal(20);
expect(webTileDataSource.minDataLevel).to.equal(1);
expect(webTileDataSource.maxZoomLevel).to.equal(20);
expect(webTileDataSource.minZoomLevel).to.equal(1);
expect(webTileDataSource.maxDisplayLevel).to.equal(20);
expect(webTileDataSource.minDisplayLevel).to.equal(1);
expect(webTileDataSource.storageLevelOffset).to.equal(-1);
expect(webTileDataSource.resolution).to.equal(
WebTileDataSource.resolutionValue.resolution512
);
//assert(webTileDataSource.renderingOptions === undefined);
});
it("#createWebTileDataSource with token authentication", async function() {
const webTileDataSource = new HereWebTileDataSource({
authenticationCode: "foo123"

it("#createWebTileDataSource with 256px resolution", async function() {
const webTileDataSource = new WebTileDataSource({
dataProvider: fakeWebTileProvider,
resolution: WebTileDataSource.resolutionValue.resolution256
});
assert(webTileDataSource.maxDataLevel === 19);
expect(webTileDataSource.resolution).to.equal(
WebTileDataSource.resolutionValue.resolution256
);
});
it("#createWebTileDataSource with 256px and ppi320", async function() {
const apikey = "123";
const webTileDataSource = new HereWebTileDataSource({
apikey,
resolution: WebTileDataSource.resolutionValue.resolution256,
ppi: WebTileDataSource.ppiValue.ppi320

it("#gets Texture for requested Tile", async function() {
const webTileDataSource = new WebTileDataSource({
dataProvider: fakeWebTileProvider
});
assert(webTileDataSource.maxDataLevel === 20);
});
it("#createWebTileDataSource with satellite.day", async function() {
const apikey = "123";
const webTileDataSource = new HereWebTileDataSource({
apikey,
tileBaseAddress: HereTileProvider.TILE_AERIAL_SATELLITE
sinon.stub(webTileDataSource, "mapView").get(() => {
return fakeMapView;
});
assert(webTileDataSource.maxDataLevel === 19);

const tileKey = TileKey.fromRowColumnLevel(0, 0, 0);
const tile = webTileDataSource.getTile(tileKey);
expect(fakeWebTileProvider.getTexture.calledOnceWith(tile));
});
it("#createWebTileDataSource with satellite.day and 256px", async function() {
const apikey = "123";
const webTileDataSource = new HereWebTileDataSource({
apikey,
tileBaseAddress: HereTileProvider.TILE_AERIAL_SATELLITE,
resolution: WebTileDataSource.resolutionValue.resolution256

it("#createWebTileDataSource with renderingOptions opacity", async function() {
const webTileDataSource = new WebTileDataSource({
dataProvider: fakeWebTileProvider,
renderingOptions: { opacity: 0.5 }
});
assert(webTileDataSource.maxDataLevel === 20);
});
it("#createWebTileDataSource throws with satellite.day and ppi320", async function() {
const apikey = "123";
assert.throw(
() =>
new HereWebTileDataSource({
apikey,
tileBaseAddress: HereTileProvider.TILE_AERIAL_SATELLITE,
ppi: WebTileDataSource.ppiValue.ppi320
})
);
});
it("#createWebTileDataSource throws w/o auth.", async function() {
assert.throw(() => new HereWebTileDataSource({} as any));
});
it("#createWebTileDataSource throws w/ missing appCode", async function() {
assert.throw(() => new HereWebTileDataSource({ appId: "42" } as any));
});
it("#createWebTileDataSource throws w/ missing appId", async function() {
assert.throw(() => new HereWebTileDataSource({ appCode: "42" } as any));
sinon.stub(webTileDataSource, "mapView").get(() => {
return fakeMapView;
});

const creatorSpy = sinon.spy(TileGeometryCreator.instance, "createGroundPlane");

const tileKey = TileKey.fromRowColumnLevel(0, 0, 0);
const tile = await webTileDataSource.getTile(tileKey);
expect(fakeWebTileProvider.getTexture.calledOnceWith(tile));
expect(creatorSpy.called).to.be.true;
expect((creatorSpy.args[0][1] as THREE.MeshBasicMaterial).opacity).to.equal(0.5);
});
});
Loading

0 comments on commit 7fefd71

Please sign in to comment.