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

Commit

Permalink
HARP-12599: Moves Priority Handling to StyleSetEvaluator (#1927)
Browse files Browse the repository at this point in the history
* Moves processing of theme.priorities from Geometry Creation to StyleSetEvaluation,
as the needed MapView.theme accessor is deprecated and not always correct, due to asynchronouse theme updates. Therefore the priorites from the theme need to get passed through to the Decoders in the WebWorkers
* Changes the setStyleSet and Decoder.configure signature to take an options object instead of flat parameters, as the list gets very long now with priorities and labelPriorities
* Adjusts all available examples and Datasources/Decoders/Loaders to the new signature and to pass the needed priorities through

Signed-off-by: Frauke Fritz <frauke.fritz@here.com>
  • Loading branch information
FraukeF authored and nzjony committed Nov 3, 2020
1 parent 460af4b commit a0b5ec2
Show file tree
Hide file tree
Showing 21 changed files with 418 additions and 387 deletions.
42 changes: 31 additions & 11 deletions @here/harp-datasource-protocol/lib/ITileDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,37 @@
import { Projection, TileKey } from "@here/harp-geoutils";

import { DecodedTile } from "./DecodedTile";
import { Definitions, StyleSet } from "./Theme";
import { Definitions, StylePriority, StyleSet } from "./Theme";
import { TileInfo } from "./TileInfo";
import { OptionsMap, RequestController } from "./WorkerDecoderProtocol";

export interface DecoderOptions {
/**
* The StyleSet to be applied during decoding.
*/
styleSet?: StyleSet;

/**
* The Definitions to be applied during decoding.
*/
definitions?: Definitions;

/**
* The Priorities to be applied during decoding.
*/
priorities?: StylePriority[];

/**
* The Label Priorities to be applied during decoding.
*/
labelPriorities?: string[];

/**
* A prioritized list of language codes to be applied.
*/
languages?: string[];
}

/**
* General type decoder which can be used to provide decoded tile data.
*/
Expand Down Expand Up @@ -57,17 +84,10 @@ export interface ITileDecoder {
*
* Non-existing (`undefined`) options (including styleSet) are not changed.
*
* @param styleSet - optional, new style set.
* @param definitions - optional, definitions used to resolve references in `styleSet`
* @param languages - optional, language list
* @param options - optional, new options - shape is specific for each decoder
* @param options - configuration options
* @param customOptions - optional, new options - shape is specific for each decoder
*/
configure(
styleSet?: StyleSet,
definitions?: Definitions,
languages?: string[],
options?: OptionsMap
): void;
configure(options?: DecoderOptions, customOptions?: OptionsMap): void;

/**
* Free all resources associated with this decoder.
Expand Down
22 changes: 17 additions & 5 deletions @here/harp-datasource-protocol/lib/StyleSetEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/

import { LoggerManager } from "@here/harp-utils";

import {
Expand Down Expand Up @@ -33,8 +32,9 @@ import {
interpolatedPropertyDefinitionToJsonExpr,
isInterpolatedPropertyDefinition
} from "./InterpolatedPropertyDefs";
import { DecoderOptions } from "./ITileDecoder";
import { AttrScope, getTechniqueAttributeDescriptor } from "./TechniqueDescriptors";
import { IndexedTechnique, Technique } from "./Techniques";
import { IndexedTechnique, setTechniqueRenderOrderOrPriority, Technique } from "./Techniques";
import { Definitions, Style, StyleSet } from "./Theme";

const logger = LoggerManager.instance.create("StyleSetEvaluator");
Expand Down Expand Up @@ -331,6 +331,13 @@ class OptimizedSubSetKey {
}
}

/**
* Options to be passed to the StyleSetEvaluator
*
* Basically identical as the DecoderOptions but requires styleSet to be set.
*/
export type StyleSetOptions = DecoderOptions & { styleSet: StyleSet };

/**
* Combine data from datasource and apply the rules from a specified theme to show it on the map.
*/
Expand All @@ -353,9 +360,9 @@ export class StyleSetEvaluator {
private m_previousResult: IndexedTechnique[] | undefined;
private m_previousEnv: Env | undefined;

constructor(styleSet: StyleSet, definitions?: Definitions) {
this.m_definitions = definitions;
this.styleSet = resolveReferences(styleSet, definitions);
constructor(private readonly m_options: StyleSetOptions) {
this.m_definitions = this.m_options.definitions;
this.styleSet = resolveReferences(this.m_options.styleSet, this.m_definitions);
computeDefaultRenderOrder(this.styleSet);
this.compileStyleSet();
}
Expand Down Expand Up @@ -912,6 +919,11 @@ export class StyleSetEvaluator {
if (style._usesFeatureState !== undefined) {
technique._usesFeatureState = style._usesFeatureState;
}
setTechniqueRenderOrderOrPriority(
technique,
this.m_options.priorities ?? [],
this.m_options.labelPriorities ?? []
);
this.m_techniques.push(technique as IndexedTechnique);
return technique as IndexedTechnique;
}
Expand Down
10 changes: 6 additions & 4 deletions @here/harp-datasource-protocol/lib/Techniques.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
TextTechniqueParams,
TextureCoordinateType
} from "./TechniqueParams";
import { Theme } from "./Theme";
import { StylePriority } from "./Theme";

/**
* Names of the supported texture properties.
Expand Down Expand Up @@ -494,9 +494,11 @@ export function composeTechniqueTextureName(
* @param technique- The technique whose render order or priority will be set.
* @param theme - The theme from which the category priorities will be taken.
*/
export function setTechniqueRenderOrderOrPriority(technique: IndexedTechnique, theme: Theme) {
const { priorities, labelPriorities } = theme;

export function setTechniqueRenderOrderOrPriority(
technique: IndexedTechnique,
priorities: StylePriority[],
labelPriorities: string[]
) {
if (
isTextTechnique(technique) ||
isPoiTechnique(technique) ||
Expand Down
4 changes: 3 additions & 1 deletion @here/harp-datasource-protocol/lib/WorkerDecoderProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { Definitions, StyleSet } from "./Theme";
import { Definitions, StylePriority, StyleSet } from "./Theme";
import { WorkerServiceProtocol } from "./WorkerServiceProtocol";

/**
Expand Down Expand Up @@ -75,6 +75,8 @@ export namespace WorkerDecoderProtocol {
type: DecoderMessageName.Configuration;
styleSet?: StyleSet;
definitions?: Definitions;
priorities?: StylePriority[];
labelPriorities?: string[];
options?: OptionsMap;
languages?: string[];
}
Expand Down
Loading

0 comments on commit a0b5ec2

Please sign in to comment.