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

Commit

Permalink
HARP-12581: Move TextElement construction into builders. (#1988)
Browse files Browse the repository at this point in the history
* HARP_12581: Remove unused file Poi.ts

* HARP-12581: Move TextElement creation to TextElementBuilder.

* HARP-12581: Add PoiBuilder to create PoiInfo for marker techniques.

* HARP_12581: Builder unit tests.

* HARP-12581: Address review comments and fix tests.
  • Loading branch information
atomicsulfate authored Nov 24, 2020
1 parent 6470275 commit aabe350
Show file tree
Hide file tree
Showing 13 changed files with 693 additions and 681 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
1 change: 0 additions & 1 deletion @here/harp-mapview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export * from "./lib/MapViewAtmosphere";
export * from "./lib/MapViewFog";
export * from "./lib/MapViewPoints";
export * from "./lib/PickHandler";
export * from "./lib/poi/Poi";
export * from "./lib/poi/PoiManager";
export * from "./lib/poi/PoiTableManager";
export * from "./lib/Statistics";
Expand Down
118 changes: 20 additions & 98 deletions @here/harp-mapview/lib/geometry/TileGeometryCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
GeometryKind,
GeometryKindSet,
getArrayConstructor,
getFeatureId,
getPropertyValue,
IndexedTechnique,
InterleavedBufferAttribute,
Expand Down Expand Up @@ -74,7 +73,6 @@ import {
setShaderMaterialDefine,
SolidLineMaterial
} from "@here/harp-materials";
import { ContextualArabicConverter } from "@here/harp-text-canvas";
import { assert, LoggerManager } from "@here/harp-utils";
import * as THREE from "three";

Expand All @@ -96,8 +94,7 @@ import { MapAdapterUpdateEnv, MapMaterialAdapter } from "../MapMaterialAdapter";
import { MapObjectAdapter, MapObjectAdapterParams } from "../MapObjectAdapter";
import { MapViewPoints } from "../MapViewPoints";
import { PathBlockingElement } from "../PathBlockingElement";
import { TextElement } from "../text/TextElement";
import { DEFAULT_TEXT_DISTANCE_SCALE } from "../text/TextElementsRenderer";
import { TextElementBuilder } from "../text/TextElementBuilder";
import { Tile, TileFeatureData } from "../Tile";
import { LodMesh } from "./LodMesh";

Expand Down Expand Up @@ -484,12 +481,13 @@ export class TileGeometryCreator {
textFilter?: (technique: IndexedTechnique) => boolean
) {
const mapView = tile.mapView;
const textStyleCache = tile.textStyleCache;
const worldOffsetX = tile.computeWorldOffsetX();

const discreteZoomLevel = Math.floor(mapView.zoomLevel);
const discreteZoomEnv = new MapEnv({ $zoom: discreteZoomLevel }, mapView.env);

const textElementBuilder = new TextElementBuilder(discreteZoomEnv, tile.textStyleCache);

if (decodedTile.textPathGeometries !== undefined) {
const textPathGeometries = this.prepareTextPaths(
decodedTile.textPathGeometries,
Expand Down Expand Up @@ -519,52 +517,15 @@ export class TileGeometryCreator {
);
}

// Make sorting stable.
const priority =
technique.priority !== undefined
? getPropertyValue(technique.priority, discreteZoomEnv)
: 0;
const fadeNear =
technique.fadeNear !== undefined
? getPropertyValue(technique.fadeNear, discreteZoomEnv)
: technique.fadeNear;
const fadeFar =
technique.fadeFar !== undefined
? getPropertyValue(technique.fadeFar, discreteZoomEnv)
: technique.fadeFar;
const userData = textPath.objInfos;
const featureId = getFeatureId(userData);
const textElement = new TextElement(
ContextualArabicConverter.instance.convert(textPath.text),
path,
textStyleCache.getRenderStyle(technique),
textStyleCache.getLayoutStyle(technique),
priority,
technique.xOffset !== undefined ? technique.xOffset : 0.0,
technique.yOffset !== undefined ? technique.yOffset : 0.0,
featureId,
technique.style,
fadeNear,
fadeFar,
tile.offset
);
textElement.pathLengthSqr = textPath.pathLengthSqr;
textElement.minZoomLevel =
getPropertyValue(technique.minZoomLevel, discreteZoomEnv) ?? undefined;

textElement.maxZoomLevel =
getPropertyValue(technique.maxZoomLevel, discreteZoomEnv) ?? undefined;

textElement.distanceScale =
technique.distanceScale !== undefined
? technique.distanceScale
: DEFAULT_TEXT_DISTANCE_SCALE;
textElement.mayOverlap = technique.mayOverlap === true;
textElement.reserveSpace = technique.reserveSpace !== false;
textElement.kind = technique.kind;
// Get the userData for text element picking.
textElement.userData = textPath.objInfos;
textElement.textFadeTime = technique.textFadeTime;
const textElement = textElementBuilder
.withTechnique(technique)
.build(
textPath.text,
path,
tile.offset,
textPath.objInfos,
textPath.pathLengthSqr
);

tile.addTextElement(textElement);
}
Expand Down Expand Up @@ -596,18 +557,7 @@ export class TileGeometryCreator {
continue;
}

const priority =
technique.priority !== undefined
? getPropertyValue(technique.priority, discreteZoomEnv)
: 0;
const fadeNear =
technique.fadeNear !== undefined
? getPropertyValue(technique.fadeNear, discreteZoomEnv)
: technique.fadeNear;
const fadeFar =
technique.fadeFar !== undefined
? getPropertyValue(technique.fadeFar, discreteZoomEnv)
: technique.fadeFar;
textElementBuilder.withTechnique(technique);

for (let i = 0; i < numPositions; ++i) {
const x = positions.getX(i) + worldOffsetX;
Expand All @@ -619,42 +569,14 @@ export class TileGeometryCreator {
continue;
}

const userData = text.objInfos !== undefined ? text.objInfos[i] : undefined;
const featureId = getFeatureId(userData);

const textElement = new TextElement(
ContextualArabicConverter.instance.convert(label!),
new THREE.Vector3(x, y, z),
textStyleCache.getRenderStyle(technique),
textStyleCache.getLayoutStyle(technique),
priority,
technique.xOffset ?? 0.0,
technique.yOffset ?? 0.0,
featureId,
technique.style,
undefined,
undefined,
tile.offset
const attributes = text.objInfos?.[i];
const point = new THREE.Vector3(x, y, z);
const textElement = textElementBuilder.build(
label!,
point,
tile.offset,
attributes
);

textElement.minZoomLevel =
getPropertyValue(technique.minZoomLevel, discreteZoomEnv) ??
mapView.minZoomLevel;

textElement.maxZoomLevel =
getPropertyValue(technique.maxZoomLevel, discreteZoomEnv) ??
mapView.maxZoomLevel;

textElement.mayOverlap = technique.mayOverlap === true;
textElement.reserveSpace = technique.reserveSpace !== false;
textElement.kind = technique.kind;

textElement.fadeNear = fadeNear;
textElement.fadeFar = fadeFar;
textElement.textFadeTime = technique.textFadeTime;

// Get the userData for text element picking.
textElement.userData = userData;
tile.addTextElement(textElement);
}
}
Expand Down
Loading

0 comments on commit aabe350

Please sign in to comment.