Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* 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();
class TileTextElements {
constructor(readonly tile: Tile, readonly group: TextElementGroup) {}
}
class TextElementLists {
constructor(readonly lists: TileTextElements[]) {}
get priority() {
assert(this.lists.length > 0);
static computeIconScreenBox(
poiInfo: PoiInfo,
screenPosition: THREE.Vector2,
scale: number,
zoomLevel: number,
/* out */ screenBox: Math2D.Box = new Math2D.Box()
): Math2D.Box {
assert(poiInfo.poiRenderBatch !== undefined);
assert(poiInfo.poiRenderBatch !== INVALID_RENDER_BATCH);
const width = poiInfo.computedWidth! * scale;
const height = poiInfo.computedHeight! * scale;
const technique = poiInfo.technique;
const iconXOffset = getPropertyValue(technique.iconXOffset, zoomLevel);
const iconYOffset = getPropertyValue(technique.iconYOffset, zoomLevel);
const centerX = screenPosition.x + (typeof iconXOffset === "number" ? iconXOffset : 0);
const centerY = screenPosition.y + (typeof iconYOffset === "number" ? iconYOffset : 0);
screenBox.x = centerX - width / 2;
screenBox.y = centerY - height / 2;
screenBox.w = width;
const maxX = positions.getX(positionIndex + 1);
if (screenX > maxX) {
continue;
}
const minY = positions.getY(positionIndex);
if (screenY < minY) {
continue;
}
const maxY = positions.getY(positionIndex + 2);
if (screenY > maxY) {
continue;
}
const box = new Math2D.Box(minX, minY, maxX - minX, maxY - minY);
if (
imageData !== undefined &&
pickInfos[pickInfoIndex].poiInfo !== undefined &&
pickInfos[pickInfoIndex].poiInfo.uvBox !== undefined &&
this.isPixelTransparent(
imageData,
screenX,
screenY,
box,
pickInfos[pickInfoIndex].poiInfo.uvBox,
canvas
)
) {
continue;
}