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

Commit

Permalink
HARP-12599: Deprecates Datasource.setStyleSet (#1936)
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 4, 2020
1 parent afefe50 commit 047024d
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 142 deletions.
82 changes: 42 additions & 40 deletions @here/harp-examples/src/datasource_geojson_styling_game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,47 +173,49 @@ export namespace GeoJsonStylingGame {
correct: boolean;
}

geoJsonDataSource.setStyleSet({
styleSet: [
{
description: "GeoJson polygon",
when: ["==", ["geometry-type"], "Polygon"],
renderOrder: 1000,
technique: "fill",
attr: {
color: "#37afaa",
lineColor: "#267874",
lineWidth: 1
geoJsonDataSource.setTheme({
styles: {
geojson: [
{
description: "GeoJson polygon",
when: ["==", ["geometry-type"], "Polygon"],
renderOrder: 1000,
technique: "fill",
attr: {
color: "#37afaa",
lineColor: "#267874",
lineWidth: 1
}
},
{
description: "GeoJson polygons selection",
when: ["==", ["geometry-type"], "Polygon"],
renderOrder: 1010,
technique: "fill",
attr: {
// enable geometries created by this technique only when
// the feature's name is equal to the value stored
// in the dynamic property named `selected`
enabled: [
"==",
["get", "name"],
["get", "selected", ["dynamic-properties"]]
],

// select the color based on the the value of the dynamic property `correct`.
color: [
"case",
["get", "correct", ["dynamic-properties"]],
"#009900",
"#ff4422"
],

// avoid picking
transient: true
}
}
},
{
description: "GeoJson polygons selection",
when: ["==", ["geometry-type"], "Polygon"],
renderOrder: 1010,
technique: "fill",
attr: {
// enable geometries created by this technique only when
// the feature's name is equal to the value stored
// in the dynamic property named `selected`
enabled: [
"==",
["get", "name"],
["get", "selected", ["dynamic-properties"]]
],

// select the color based on the the value of the dynamic property `correct`.
color: [
"case",
["get", "correct", ["dynamic-properties"]],
"#009900",
"#ff4422"
],

// avoid picking
transient: true
}
}
]
]
}
});

// snippet:harp_gl_gamestyleset.ts
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-examples/src/styling_interpolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export namespace TiledGeoJsonTechniquesExample {
});

mapView.addDataSource(baseMapDataSource).then(() => {
baseMapDataSource.setStyleSet({ styleSet: theme.styles!.tilezen });
baseMapDataSource.setTheme(theme);
});

mapView.update();
Expand Down
36 changes: 8 additions & 28 deletions @here/harp-mapview-decoder/lib/TileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
import {
Definitions,
ITileDecoder,
StyleSet,
Theme,
TileInfo
} from "@here/harp-datasource-protocol";
import { StyleSetOptions } from "@here/harp-datasource-protocol/index-decoder";
import { ITileDecoder, Theme, TileInfo } from "@here/harp-datasource-protocol";
import { TileKey, TilingScheme } from "@here/harp-geoutils";
import {
ConcurrentDecoderFacade,
Expand Down Expand Up @@ -198,45 +191,32 @@ export class TileDataSource<TileType extends Tile = Tile> extends DataSource {
});
}

/** @override */
setStyleSet(
options: StyleSetOptions | StyleSet,
definitions?: Definitions,
languages?: string[]
): void {
if (!options?.hasOwnProperty("styleSet")) {
this.m_decoder.configure({
styleSet: options as StyleSet,
definitions,
languages
});
} else {
this.m_decoder.configure(options as StyleSetOptions);
}
this.mapView.clearTileCache(this.name);
}

/**
* Apply the [[Theme]] to this data source.
*
* Applies new [[StyleSet]] and definitions from theme only if matching styleset (see
* `styleSetName` property) is found in `theme`.
* @override
*/
setTheme(theme: Theme, languages?: string[]): void {
setTheme(theme: Theme, languages?: string[], styleSetName?: string): void {
if (styleSetName !== undefined) {
this.styleSetName = styleSetName;
}

const styleSet =
this.styleSetName !== undefined && theme.styles
? theme.styles[this.styleSetName]
: undefined;

if (styleSet !== undefined) {
this.setStyleSet({
this.m_decoder.configure({
styleSet,
definitions: theme.definitions,
priorities: theme.priorities,
labelPriorities: theme.labelPriorities,
languages
});
this.mapView.clearTileCache(this.name);
}
}

Expand Down
30 changes: 5 additions & 25 deletions @here/harp-mapview/lib/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
import { Definitions, StyleSet, Theme, ValueMap } from "@here/harp-datasource-protocol";
import { StyleSetOptions } from "@here/harp-datasource-protocol/index-decoder";
import { Theme, ValueMap } from "@here/harp-datasource-protocol";
import { ExprPool } from "@here/harp-datasource-protocol/lib/ExprPool";
import { Projection, TileKey, TilingScheme } from "@here/harp-geoutils";
import { assert, LoggerManager } from "@here/harp-utils";
Expand Down Expand Up @@ -455,36 +454,17 @@ export abstract class DataSource extends THREE.EventDispatcher {
return this.m_mapView === undefined;
}

/**
* Invoked by {@link MapView} to notify when the
* {@link @here/harp-datasource-protocol#Theme} has been changed.
*
* @remarks
* If `DataSource` depends on a `styleSet` or `languages`, it must update its tiles' geometry.
*
* @deprecated Use [[setTheme]].
*
* @param options - The Options used for decodeing and/or styling, alternativly a StyleSet
* @param definitions - The Definitions used for decoding/styling
* @param languages - A prioritized list of ISO 639-1 language codes
*/
setStyleSet(
options: StyleSetOptions | StyleSet,
definitions?: Definitions,
languages?: string[]
): void {
// to be overwritten by subclasses
}

/**
* 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 languages -
* @param theme - The Theme to be applied
* @param languages - optional: The languages in priority order to be applied
* @param styleSetName - optional: The Name of the StyleSet to be used.
*/
setTheme(theme: Theme, languages?: string[]): void {
setTheme(theme: Theme, languages?: string[], styleSetName?: string): void {
// to be overwritten by subclasses
}

Expand Down
52 changes: 14 additions & 38 deletions @here/harp-mapview/lib/PolarTileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
import {
Definitions,
StandardGeometryKind,
StyleSet,
Technique,
Theme
} from "@here/harp-datasource-protocol";
import {
MapEnv,
StyleSetEvaluator,
StyleSetOptions
} from "@here/harp-datasource-protocol/index-decoder";
import { StandardGeometryKind, StyleSet, Technique, Theme } from "@here/harp-datasource-protocol";
import { MapEnv, StyleSetEvaluator } from "@here/harp-datasource-protocol/index-decoder";
import {
GeoCoordinates,
MercatorConstants,
Expand Down Expand Up @@ -64,7 +54,7 @@ export class PolarTileDataSource extends DataSource {

constructor({
name = "polar",
styleSetName,
styleSetName = "polar",
minDataLevel,
maxDataLevel,
minDisplayLevel,
Expand Down Expand Up @@ -130,44 +120,30 @@ export class PolarTileDataSource extends DataSource {
}

/** @override */
setStyleSet(
options: StyleSetOptions | StyleSet,
definitions?: Definitions,
languages?: string[]
): void {
this.dispose();
setTheme(theme: Theme, languages?: string[], styleSetName?: string): void {
let styleSet: StyleSet | undefined;

if (!options?.hasOwnProperty("styleSet")) {
this.m_styleSetEvaluator = new StyleSetEvaluator({
styleSet: options as StyleSet,
definitions,
languages
});
} else {
this.m_styleSetEvaluator = new StyleSetEvaluator(options as StyleSetOptions);
if (styleSetName) {
this.styleSetName = styleSetName;
}

this.m_northPoleEntry = this.createTechiqueEntry("north_pole");
this.m_southPoleEntry = this.createTechiqueEntry("south_pole");

this.mapView.markTilesDirty(this);
}

/** @override */
setTheme(theme: Theme, languages?: string[]): void {
let styleSet: StyleSet | undefined;

if (this.styleSetName !== undefined && theme.styles !== undefined) {
styleSet = theme.styles[this.styleSetName];
}
this.dispose();

this.setStyleSet({
this.m_styleSetEvaluator = new StyleSetEvaluator({
styleSet: styleSet ?? [],
definitions: theme.definitions,
priorities: theme.priorities,
labelPriorities: theme.labelPriorities,
languages
});

this.m_northPoleEntry = this.createTechiqueEntry("north_pole");
this.m_southPoleEntry = this.createTechiqueEntry("south_pole");

this.mapView.markTilesDirty(this);
}

/** @override */
Expand Down
31 changes: 21 additions & 10 deletions @here/harp-mapview/test/PolarTileDataSourceTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

import { Style } from "@here/harp-datasource-protocol";
import { Style, Theme } from "@here/harp-datasource-protocol";
import {
GeoCoordinates,
MercatorConstants,
Expand All @@ -31,22 +31,33 @@ describe("PolarTileDataSource", function() {
const north_style: Style = {
when: ["==", ["get", "kind"], "north_pole"],
technique: "fill",
attr: { color: "#dac0de" }
attr: { color: "#dac0de" },
styleSet: "polar"
};
const south_style: Style = {
when: ["==", ["get", "kind"], "south_pole"],
technique: "fill",
attr: { color: "#bada55" }
attr: { color: "#bada55" },
styleSet: "polar"
};

const theme_both: Style[] = [north_style, south_style];
const theme_south: Style[] = [south_style];
const theme_both: Theme = {
styles: {
polar: [north_style, south_style]
}
};
const theme_south: Theme = {
styles: {
polar: [south_style]
}
};
const renderer = { capabilities: { isWebGL2: false } };

describe("should", function() {
it("#canGetTile()", function() {
dataSource = new PolarTileDataSource({
storageLevelOffset: 0
storageLevelOffset: 0,
styleSetName: "polar"
});

const msgLess = "should not render tileKey of level less than current";
Expand Down Expand Up @@ -149,7 +160,7 @@ describe("PolarTileDataSource", function() {
});

it("Creates tile with objects if has pole styles", function() {
dataSource.setStyleSet({ styleSet: theme_south });
dataSource.setTheme(theme_south);
const north = dataSource.getTile(TileKey.fromRowColumnLevel(2, 1, 2));
const south = dataSource.getTile(TileKey.fromRowColumnLevel(0, 1, 2));

Expand All @@ -158,7 +169,7 @@ describe("PolarTileDataSource", function() {
});

it("Creates meshes with proper materials", function() {
dataSource.setStyleSet({ styleSet: theme_both });
dataSource.setTheme(theme_both);
const north = dataSource.getTile(TileKey.fromRowColumnLevel(2, 1, 2));
const south = dataSource.getTile(TileKey.fromRowColumnLevel(0, 1, 2));

Expand All @@ -174,7 +185,7 @@ describe("PolarTileDataSource", function() {
});

it("Don't create geometries if disposed", function() {
dataSource.setStyleSet({ styleSet: theme_both });
dataSource.setTheme(theme_both);
dataSource.dispose();

const north = dataSource.getTile(TileKey.fromRowColumnLevel(2, 1, 2));
Expand Down Expand Up @@ -216,7 +227,7 @@ describe("PolarTileDataSource", function() {
return renderer;
});
dataSource.attach((mapViewStub as unknown) as MapView);
dataSource.setStyleSet({ styleSet: theme_both });
dataSource.setTheme(theme_both);
});

it("Creates empty tile if outside of pole radius", function() {
Expand Down

0 comments on commit 047024d

Please sign in to comment.