This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HARP-12581: Add PoiBuilder to create PoiInfo for marker techniques.
- Loading branch information
1 parent
70c429c
commit 222e25b
Showing
6 changed files
with
303 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.