Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* If "overloaded" is `true`:
*
* Maximum time in milliseconds available for rendering. If value is <= 0, or if the camera is not
* moving, it is ignored. See [[TextElementsRenderer.isDynamicFrame]].
*/
const OVERLOAD_PLACE_TIME_LIMIT = 10;
/**
* Minimum number of pixels per character. Used during estimation if there is enough screen space
* available to render a text.
*/
const MIN_AVERAGE_CHAR_WIDTH = 5;
const logger = LoggerManager.instance.create("TextElementsRenderer", { level: LogLevel.Log });
// Development flag: Enable debug print.
const PRINT_LABEL_DEBUG_INFO: boolean = false;
const updateStats = PRINT_LABEL_DEBUG_INFO ? new UpdateStats(logger) : undefined;
const placementStats = PRINT_LABEL_DEBUG_INFO ? new PlacementStats(logger) : undefined;
const tempBox = new THREE.Box2();
const tempBoxes: THREE.Box2[] = [];
const tempBox2D = new Math2D.Box();
const tempPosition = new THREE.Vector3();
const tempScreenPosition = new THREE.Vector2();
const tempScreenPoints: THREE.Vector2[] = [];
const tempPoiScreenPosition = new THREE.Vector2();
const tempTextOffset = new THREE.Vector2();
/*
* Copyright (C) 2017-2019 HERE Europe B.V.
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
import { assert, LoggerManager, LogLevel } from "@here/harp-utils";
import { TextElement } from "./TextElement";
import { TextElementGroup } from "./TextElementGroup";
import { TextElementFilter, TextElementGroupState } from "./TextElementGroupState";
import { TextElementState } from "./TextElementState";
import { TextElementType } from "./TextElementType";
const logger = LoggerManager.instance.create("TextElementsStateCache", { level: LogLevel.Log });
/**
* Label distance tolerance squared in meters. Point labels with the same name that are closer in
* world space than this value are treated as the same label. Used to identify duplicate labels in
* overlapping tiles and label replacements at different storage levels.
*/
function getDedupSqDistTolerance(zoomLevel: number) {
// Defining here a minimum tolerance of 10m at zoom level 13 or higher.
const minSqTol = 100;
const minSqTolLevel = 13;
const maxLevelDelta = 4;
const levelDelta = Math.min(
maxLevelDelta,
minSqTolLevel - Math.min(minSqTolLevel, Math.floor(zoomLevel))
);
// Distance tolerance computed applying a factor over an arbitrary minimum tolerance for a
entry.resolver(undefined, response.response);
}
} else if (WorkerServiceProtocol.isInitializedMessage(event.data)) {
const readyPromise = this.getReadyPromise(event.data.service);
if (++readyPromise.count === this.m_workerPromises.length) {
readyPromise.resolve();
}
} else if (isLoggingMessage(event.data)) {
switch (event.data.level) {
case LogLevel.Trace:
this.m_workerChannelLogger.trace(...event.data.message);
break;
case LogLevel.Debug:
this.m_workerChannelLogger.debug(...event.data.message);
break;
case LogLevel.Log:
this.m_workerChannelLogger.log(...event.data.message);
break;
case LogLevel.Info:
this.m_workerChannelLogger.info(...event.data.message);
break;
case LogLevel.Warn:
this.m_workerChannelLogger.warn(...event.data.message);
break;
case LogLevel.Error:
this.m_workerChannelLogger.error(...event.data.message);
break;
}
} else {
this.eventHandler(event);
}
};