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

Commit

Permalink
HARP-12581: Add PoiBuilder to create PoiInfo for marker techniques.
Browse files Browse the repository at this point in the history
  • Loading branch information
atomicsulfate committed Nov 23, 2020
1 parent 70c429c commit 222e25b
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 327 deletions.
4 changes: 2 additions & 2 deletions @here/harp-datasource-protocol/lib/DecodedTile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export interface TextGeometry {
positions: BufferAttribute;
texts: number[];
technique?: number;
stringCatalog?: Array<string | undefined>;
stringCatalog: Array<string | undefined>;
objInfos?: AttributeMap[];
}

Expand All @@ -274,7 +274,7 @@ export interface PoiGeometry {
*/
imageTextures?: number[];
technique?: number;
stringCatalog?: Array<string | undefined>;
stringCatalog: Array<string | undefined>;
objInfos?: AttributeMap[];
// Angle in degrees from north clockwise specifying the directions the icons can be shifted.
offsetDirections?: number[];
Expand Down
147 changes: 147 additions & 0 deletions @here/harp-mapview/lib/poi/PoiBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* 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 {
composeTechniqueTextureName,
Env,
getPropertyValue,
IndexedTechniqueParams,
LineMarkerTechnique,
MapEnv,
PoiTechnique
} from "@here/harp-datasource-protocol";
import { assert, LoggerManager } from "@here/harp-utils";

import { ColorCache } from "../ColorCache";
import { PoiInfo, TextElement } from "../text/TextElement";

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

function getImageTexture(technique: PoiTechnique | LineMarkerTechnique, env: MapEnv | Env) {
return technique.imageTexture !== undefined
? composeTechniqueTextureName(getPropertyValue(technique.imageTexture, env), technique)
: undefined;
}

/**
* Creates {@link TextElement} objects from the decoded tile and list of materials specified. The
* priorities of the {@link TextElement}s are updated to simplify label placement.
*
* @param tile - The {@link Tile} to create the testElements on.
* @param decodedTile - The {@link @here/harp-datasource-protocol#DecodedTile}.
* @param textFilter -: Optional filter. Should return true for any text technique that is
* applicable.
*/
export class PoiBuilder {
private m_iconMinZoomLevel?: number;
private m_iconMaxZoomLevel?: number;
private m_textMinZoomLevel?: number;
private m_textMaxZoomLevel?: number;
private m_technique?: (PoiTechnique | LineMarkerTechnique) & IndexedTechniqueParams;
private m_imageTextureName?: string;
private m_shieldGroupIndex?: number;

constructor(private readonly m_env: MapEnv | Env) {}

withTechnique(technique: (PoiTechnique | LineMarkerTechnique) & IndexedTechniqueParams): this {
this.m_imageTextureName = getImageTexture(technique, this.m_env);

this.m_iconMinZoomLevel =
getPropertyValue(technique.iconMinZoomLevel ?? technique.minZoomLevel, this.m_env) ??
undefined;
this.m_iconMaxZoomLevel =
getPropertyValue(technique.iconMaxZoomLevel ?? technique.maxZoomLevel, this.m_env) ??
undefined;
this.m_textMinZoomLevel =
getPropertyValue(technique.textMinZoomLevel ?? technique.minZoomLevel, this.m_env) ??
undefined;
this.m_textMaxZoomLevel =
getPropertyValue(technique.textMaxZoomLevel ?? technique.maxZoomLevel, this.m_env) ??
undefined;

this.m_technique = technique;
return this;
}

withIcon(imageTextureName?: string, shieldGroupIndex?: number): this {
if (imageTextureName !== undefined) {
this.m_imageTextureName = imageTextureName;
}
this.m_shieldGroupIndex = shieldGroupIndex;
return this;
}

build(textElement: TextElement): PoiInfo | undefined {
assert(this.m_technique !== undefined);
const technique = this.m_technique!;
const env = this.m_env;
const imageTextureName = this.m_imageTextureName;

// The POI name to be used is taken from the data, since it will
// specify the name of the texture to use.

// The POI name in the technique may override the POI name from the
// data.
const poiName =
technique.poiTable !== undefined ? technique.poiName ?? imageTextureName : undefined;

if (imageTextureName !== undefined && poiName !== undefined) {
logger.warn(
"Possible duplicate POI icon definition via imageTextureName and poiTable!"
);
}

if (imageTextureName === undefined && poiName === undefined) {
// Select the smaller/larger one of the two min/max values, because the TextElement
// is a container for both.
if (textElement.minZoomLevel === undefined) {
textElement.minZoomLevel =
getPropertyValue(technique.textMinZoomLevel, env) ?? undefined;
}

if (textElement.maxZoomLevel === undefined) {
textElement.maxZoomLevel =
getPropertyValue(technique.textMaxZoomLevel, env) ?? undefined;
}
return undefined;
}

const textIsOptional = technique.textIsOptional === true;
const iconIsOptional = technique.iconIsOptional !== false;
const renderTextDuringMovements = !(technique.renderTextDuringMovements === false);
const iconMayOverlap = technique.iconMayOverlap ?? technique.textMayOverlap;

const iconReserveSpace = technique.iconReserveSpace ?? technique.textReserveSpace;
const iconColorRaw = getPropertyValue(technique.iconColor, env);
const iconColor =
iconColorRaw !== null ? ColorCache.instance.getColor(iconColorRaw) : undefined;

textElement.poiInfo = {
technique,
imageTextureName,
poiTableName: technique.poiTable,
poiName,
shieldGroupIndex: this.m_shieldGroupIndex,
textElement,
textIsOptional,
iconIsOptional,
renderTextDuringMovements,
mayOverlap: iconMayOverlap,
reserveSpace: iconReserveSpace,
featureId: textElement.featureId,
iconBrightness: technique.iconBrightness,
iconColor,
iconMinZoomLevel: this.m_iconMinZoomLevel,
iconMaxZoomLevel: this.m_iconMaxZoomLevel,
textMinZoomLevel: this.m_textMinZoomLevel,
textMaxZoomLevel: this.m_textMaxZoomLevel
};

textElement.updateMinMaxZoomLevelsFromPoiInfo();

return textElement.poiInfo;
}
}
Loading

0 comments on commit 222e25b

Please sign in to comment.