Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private findDown(
tileKeyCode: number,
displayZoomLevel: number,
renderedTiles: Map,
dataSource: DataSource
) {
const { offset, mortonCode } = TileOffsetUtils.extractOffsetAndMortonKeyFromKey(
tileKeyCode
);
const tileKey = TileKey.fromMortonCode(mortonCode);
const tilingScheme = dataSource.getTilingScheme();
for (const childTileKey of tilingScheme.getSubTileKeys(tileKey)) {
const childTileCode = TileOffsetUtils.getKeyForTileKeyAndOffset(childTileKey, offset);
const childTile = this.m_dataSourceCache.get(
childTileKey.mortonCode(),
offset,
dataSource
);
const nextLevelDiff = Math.abs(childTileKey.level - displayZoomLevel);
if (childTile !== undefined && childTile.hasGeometry) {
// childTile has geometry, so can be reused as fallback
renderedTiles.set(childTileCode, childTile);
childTile.levelOffset = nextLevelDiff;
continue;
checkedTiles: Map,
dataSource: DataSource
): boolean {
const parentCode = TileOffsetUtils.getParentKeyFromKey(tileKeyCode);
// Check if another sibling has already added the parent.
if (renderedTiles.get(parentCode) !== undefined) {
return true;
}
const exists = checkedTiles.get(parentCode)!;
if (exists !== undefined) {
return exists;
}
const { offset, mortonCode } = TileOffsetUtils.extractOffsetAndMortonKeyFromKey(parentCode);
const parentTile = this.m_dataSourceCache.get(mortonCode, offset, dataSource);
const parentTileKey = parentTile ? parentTile.tileKey : TileKey.fromMortonCode(mortonCode);
const nextLevelDiff = Math.abs(displayZoomLevel - parentTileKey.level);
if (parentTile !== undefined && parentTile.hasGeometry) {
checkedTiles.set(parentCode, true);
// parentTile has geometry, so can be reused as fallback
renderedTiles.set(parentCode, parentTile);
// We want to have parent tiles as -ve, hence the minus.
parentTile.levelOffset = -nextLevelDiff;
return true;
} else {
checkedTiles.set(parentCode, false);
}
// Recurse up until the max distance is reached or we go to the parent of all parents.
if (nextLevelDiff < this.options.quadTreeSearchDistanceUp && parentTileKey.level !== 0) {
private handleTileInfoRequest(
request: WorkerDecoderProtocol.TileInfoRequest
): Promise {
const tileKey = TileKey.fromMortonCode(request.tileKey);
const projection = getProjection(request.projection);
return this.m_decoder.getTileInfo(request.data, tileKey, projection).then(tileInfo => {
const transferList: ArrayBuffer[] =
tileInfo !== undefined && tileInfo.transferList !== undefined
? tileInfo.transferList
: [];
return {
response: tileInfo,
transferList
};
});
}
export function getParentKeyFromKey(calculatedKey: number, bitshift: number = 4) {
const { offset, mortonCode } = extractOffsetAndMortonKeyFromKey(calculatedKey, bitshift);
const parentTileKey = TileKey.fromMortonCode(TileKey.parentMortonCode(mortonCode));
return getKeyForTileKeyAndOffset(parentTileKey, offset, bitshift);
}
private handleDecodeTileRequest(
request: WorkerDecoderProtocol.DecodeTileRequest
): Promise {
const tileKey = TileKey.fromMortonCode(request.tileKey);
const projection = getProjection(request.projection);
return this.m_decoder.decodeTile(request.data, tileKey, projection).then(decodedTile => {
const transferList: ArrayBuffer[] = [];
decodedTile.geometries.forEach(geom => {
geom.vertexAttributes.forEach(attr => {
if (attr.buffer instanceof ArrayBuffer) {
transferList.push(attr.buffer);
}
});
if (geom.index && geom.index.buffer instanceof ArrayBuffer) {
transferList.push(geom.index.buffer);
}
if (
private async handleTileRequest(
request: WorkerTilerProtocol.TileRequest
): Promise {
const tileKey = TileKey.fromMortonCode(request.tileKey);
const tile = await this.tiler.getTile(request.index, tileKey);
return { response: tile || {} };
}