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

HARP-12599: Deprecates setTheme(theme, languages) #1953

Merged
merged 1 commit into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion @here/harp-datasource-protocol/lib/StyleSetEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class OptimizedSubSetKey {
*
* Basically identical as the DecoderOptions but requires styleSet to be set.
*/
export type StyleSetOptions = DecoderOptions & { styleSet: StyleSet };
export type StyleSetOptions = Omit<DecoderOptions, "languages"> & { styleSet: StyleSet };

/**
* Combine data from datasource and apply the rules from a specified theme to show it on the map.
Expand Down
53 changes: 33 additions & 20 deletions @here/harp-mapview-decoder/lib/TileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
import { FlatTheme, ITileDecoder, StyleSet, Theme, TileInfo } from "@here/harp-datasource-protocol";
import {
FlatTheme,
ITileDecoder,
OptionsMap,
StyleSet,
Theme,
TileInfo
} from "@here/harp-datasource-protocol";
import { TileKey, TilingScheme } from "@here/harp-geoutils";
import {
ConcurrentDecoderFacade,
Expand Down Expand Up @@ -126,20 +133,7 @@ export class TileDataSource<TileType extends Tile = Tile> extends DataSource {
private readonly m_tileFactory: TileFactory<TileType>,
private readonly m_options: TileDataSourceOptions
) {
super({
name: m_options.name,
styleSetName: m_options.styleSetName,
minZoomLevel: m_options.minZoomLevel,
maxZoomLevel: m_options.maxZoomLevel,
minDataLevel: m_options.minDataLevel,
maxDataLevel: m_options.maxDataLevel,
minDisplayLevel: m_options.minDisplayLevel,
maxDisplayLevel: m_options.maxDisplayLevel,
storageLevelOffset: m_options.storageLevelOffset,
allowOverlappingTiles: m_options.allowOverlappingTiles,
minGeometryHeight: m_options.minGeometryHeight,
maxGeometryHeight: m_options.maxGeometryHeight
});
super(m_options);
if (m_options.decoder) {
this.m_decoder = m_options.decoder;
} else if (m_options.concurrentDecoderServiceName) {
Expand Down Expand Up @@ -187,16 +181,32 @@ export class TileDataSource<TileType extends Tile = Tile> extends DataSource {
await Promise.all([this.m_options.dataProvider.register(this), this.m_decoder.connect()]);
this.m_isReady = true;

this.m_decoder.configure(undefined, {
storageLevelOffset: this.m_options.storageLevelOffset
let customOptions: OptionsMap = {};
if (this.m_options.storageLevelOffset !== undefined) {
customOptions = {
storageLevelOffset: this.m_options.storageLevelOffset
};
}
this.m_decoder.configure({ languages: this.languages }, customOptions);
}

/**
* @override
*/
setLanguages(languages: string[]): void {
this.languages = languages;

this.m_decoder.configure({
languages: this.languages
});
this.mapView.clearTileCache(this.name);
}

/**
* Apply the [[Theme]] to this data source.
* Apply the {@link @here/harp-datasource-protocol#Theme} to this data source.
*
* Applies new [[StyleSet]] and definitions from theme only if matching styleset (see
* `styleSetName` property) is found in `theme`.
* Applies new {@here/harp-datasource-protocol StyleSet} and definitions from theme only
* if matching styleset (see `styleSetName` property) is found in `theme`.
* @override
*/
async setTheme(theme: Theme | FlatTheme, languages?: string[]): Promise<void> {
Expand All @@ -207,6 +217,9 @@ export class TileDataSource<TileType extends Tile = Tile> extends DataSource {
if (this.styleSetName !== undefined && theme.styles !== undefined) {
styleSet = theme.styles[this.styleSetName];
}
if (languages !== undefined) {
this.languages = languages;
}

if (styleSet !== undefined) {
this.m_decoder.configure({
Expand Down
28 changes: 27 additions & 1 deletion @here/harp-mapview-decoder/test/TileDataSourceTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
webMercatorTilingScheme
} from "@here/harp-geoutils";
import { DataSource, MapView, Statistics, Tile, TileLoaderState } from "@here/harp-mapview";
import { assert } from "chai";
import { assert, expect } from "chai";
import * as sinon from "sinon";

import { DataProvider, TileDataSource, TileFactory } from "../index";
Expand Down Expand Up @@ -343,4 +343,30 @@ describe("TileDataSource", function() {
assert(mockDecoder.configure.calledOnce);
assert(mockDecoder.configure.calledWith(sinon.match({ styleSet: styles })));
});

it("supports setting of languages", async function() {
const mockDecoder = createMockTileDecoder();
const testedDataSource = new TileDataSource(new TileFactory(Tile), {
styleSetName: "tilezen",
tilingScheme: webMercatorTilingScheme,
dataProvider: new MockDataProvider(),
decoder: mockDecoder,
minZoomLevel: 3,
maxZoomLevel: 17,
languages: ["de"]
});

await testedDataSource.connect();

expect(mockDecoder.configure.calledOnce).to.be.true;
expect(mockDecoder.configure.calledWith(sinon.match({ languages: ["de"] }))).to.be.true;

testedDataSource.attach(createMockMapView());

testedDataSource.setLanguages(["de", "en"]);

expect(mockDecoder.configure.calledTwice).to.be.true;
expect(mockDecoder.configure.calledWith(sinon.match({ languages: ["de", "en"] }))).to.be
.true;
});
});
30 changes: 30 additions & 0 deletions @here/harp-mapview/lib/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export interface DataSourceOptions {
* The name of the [[StyleSet]] to evaluate for the decoding.
*/
styleSetName?: string;
/**
* Used to configure the languages used by the `DataSource` according to priority;
* the first language in the array has the highest priority.
*
* An array of ISO 639-1 language codes.
*/
languages?: string[];
/**
* The minimum zoom level at which data is available or displayed at
* (depending on {@link DataSource} subclass).
Expand Down Expand Up @@ -220,6 +227,11 @@ export abstract class DataSource extends THREE.EventDispatcher {

private readonly m_featureStateMap = new Map<number, ValueMap>();

/**
* An array of ISO 639-1 language codes.
*/
protected languages?: string[];

/**
* Constructs a new `DataSource`.
*
Expand All @@ -230,6 +242,7 @@ export abstract class DataSource extends THREE.EventDispatcher {
let { name } = options;
const {
styleSetName,
languages,
minZoomLevel,
maxZoomLevel,
minDataLevel,
Expand All @@ -250,6 +263,10 @@ export abstract class DataSource extends THREE.EventDispatcher {

this.styleSetName = styleSetName;

if (languages !== undefined) {
this.languages = languages;
}

if (minDataLevel !== undefined) {
this.minDataLevel = minDataLevel;
}
Expand Down Expand Up @@ -454,6 +471,16 @@ export abstract class DataSource extends THREE.EventDispatcher {
return this.m_mapView === undefined;
}

/**
* Apply the {@link @here/harp-datasource-protocol#Theme} to this data source.
*
* If `DataSource` depends on a `styleSet` defined by this theme or `languages`, it must update
* its tiles' geometry.
*
* @param theme - The Theme to be applied
*/
async setTheme(theme: Theme | FlatTheme): Promise<void>;

/**
* Apply the {@link @here/harp-datasource-protocol#Theme} to this data source.
*
Expand All @@ -462,6 +489,8 @@ export abstract class DataSource extends THREE.EventDispatcher {
*
* @param theme - The Theme to be applied
* @param languages - optional: The languages in priority order to be applied
*
* @deprecated use setTheme( Theme | FlatTheme) and setLanguages(string[]) instead
*/
async setTheme(theme: Theme | FlatTheme, languages?: string[]): Promise<void> {
// to be overwritten by subclasses
Expand All @@ -474,6 +503,7 @@ export abstract class DataSource extends THREE.EventDispatcher {
* @param languages - An array of ISO 639-1 language codes.
*/
setLanguages(languages?: string[]): void {
this.languages = languages;
// to be overloaded by subclasses
}

Expand Down
5 changes: 2 additions & 3 deletions @here/harp-mapview/lib/PolarTileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class PolarTileDataSource extends DataSource {
}

/** @override */
async setTheme(theme: Theme | FlatTheme, languages?: string[]): Promise<void> {
async setTheme(theme: Theme | FlatTheme): Promise<void> {
// Seems superfluent, but the call to ThemeLoader.load will resolve extends etc.
theme = await ThemeLoader.load(theme);
let styleSet: StyleSet | undefined;
Expand All @@ -140,8 +140,7 @@ export class PolarTileDataSource extends DataSource {
styleSet: styleSet ?? [],
definitions: theme.definitions,
priorities: theme.priorities,
labelPriorities: theme.labelPriorities,
languages
labelPriorities: theme.labelPriorities
});

this.m_northPoleEntry = this.createTechiqueEntry("north_pole");
Expand Down
3 changes: 2 additions & 1 deletion @here/harp-mapview/test/DataSourceTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ describe("DataSource", function() {
maxDataLevel: 14,
minDisplayLevel: 10,
maxDisplayLevel: 17,
storageLevelOffset: -1
storageLevelOffset: -1,
languages: []
});

expect(dataSource.name).to.equal("TestDataSource");
Expand Down
7 changes: 0 additions & 7 deletions @here/harp-vectortile-datasource/lib/VectorTileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,6 @@ export class VectorTileDataSource extends TileDataSource {
return true;
}

/** @override */
setLanguages(languages?: string[]): void {
if (languages !== undefined) {
this.configureDecoder({ languages }, undefined);
}
}

/** @override */
setPoliticalView(politicalView?: string): void {
// Just in case users mess with letters' casing.
Expand Down