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

Commit

Permalink
Fix the visibility of techniques using min/maxZoomLevel.
Browse files Browse the repository at this point in the history
This change uses the MapView zoom level to hide objects with their
visibility constrained using min/maxZoomLevel.

Signed-off-by: Roberto Raggi <roberto.raggi@here.com>
  • Loading branch information
robertoraggi committed Nov 11, 2020
1 parent 40a856b commit 8afcd67
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 33 deletions.
18 changes: 10 additions & 8 deletions @here/harp-datasource-protocol/lib/TechniqueParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ export interface BaseTechniqueParams {
* See https://threejs.org/docs/#api/en/materials/Material.side.
*/
side?: DynamicProperty<number>;

/**
* Minimal zoom level. If the current zoom level is smaller, the technique will not be used.
*/
minZoomLevel?: DynamicProperty<number>;

/**
* Maximum zoom level. If the current zoom level is larger, the technique will not be used.
*/
maxZoomLevel?: DynamicProperty<number>;
}

export enum TextureCoordinateType {
Expand Down Expand Up @@ -1335,14 +1345,6 @@ export interface TextTechniqueParams extends BaseTechniqueParams {
* Priority of text, defaults to `0`. Elements with highest priority get placed first.
*/
priority?: DynamicProperty<number>;
/**
* Minimal zoom level. If the current zoom level is smaller, the technique will not be used.
*/
minZoomLevel?: number;
/**
* Maximum zoom level. If the current zoom level is larger, the technique will not be used.
*/
maxZoomLevel?: number;
/**
* Scaling factor of the text. Defaults to 0.5, reducing the size ot 50% in the distance.
*/
Expand Down
1 change: 1 addition & 0 deletions @here/harp-mapview/lib/MapView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3498,6 +3498,7 @@ export class MapView extends EventDispatcher {
this.m_tileObjectRenderer.render(
tile,
zoomLevel,
this.zoomLevel,
this.m_camera.position,
this.m_sceneRoot
);
Expand Down
56 changes: 44 additions & 12 deletions @here/harp-mapview/lib/TileObjectsRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ export class TileObjectRenderer {

constructor(private readonly m_env: MapEnv, private readonly m_renderer: THREE.WebGLRenderer) {}

render(tile: Tile, zoomLevel: number, cameraPosition: Vector3, rootNode: Object3D) {
render(
tile: Tile,
storageLevel: number,
zoomLevel: number,
cameraPosition: Vector3,
rootNode: Object3D
) {
const worldOffsetX = tile.computeWorldOffsetX();
if (tile.willRender(zoomLevel)) {
if (tile.willRender(storageLevel)) {
for (const object of tile.objects) {
const mapObjectAdapter = MapObjectAdapter.get(object);
if (!this.processTileObject(tile, object, mapObjectAdapter)) {
if (
!this.processTileObject(tile, storageLevel, zoomLevel, object, mapObjectAdapter)
) {
continue;
}

Expand Down Expand Up @@ -183,11 +191,17 @@ export class TileObjectRenderer {
*
* @returns `true` if object shall be used in scene, `false` otherwise
*/
private processTileObject(tile: Tile, object: TileObject, mapObjectAdapter?: MapObjectAdapter) {
private processTileObject(
tile: Tile,
storageLevel: number,
zoomLevel: number,
object: TileObject,
mapObjectAdapter?: MapObjectAdapter
) {
if (!object.visible) {
return false;
}
if (!this.processTileObjectFeatures(tile, object)) {
if (!this.processTileObjectFeatures(tile, storageLevel, zoomLevel, object)) {
return false;
}

Expand All @@ -201,16 +215,34 @@ export class TileObjectRenderer {
}

/**
* Process the features owned by the given [[TileObject]].
* Process the features owned by the given `TileObject`.
*
* @param tile - The {@link Tile} owning the [[TileObject]]'s features.
* @param object - The [[TileObject]] to process.
* @returns `false` if the given [[TileObject]] should not be added to the scene.
* @param tile - The {@link Tile} owning the `TileObject`'s features.
* @param storageLevel - The storage level of the `Tile` containing the object,
* @param zoomLevel - The current zoom level of `MapView`.
* @param object - The `TileObject` to process.
* @returns `false` if the given `TileObject` should not be added to the scene.
*/
private processTileObjectFeatures(tile: Tile, object: TileObject): boolean {
const technique: IndexedTechnique = object.userData.technique;
private processTileObjectFeatures(
tile: Tile,
storageLevel: number,
zoomLevel: number,
object: TileObject
): boolean {
const technique: IndexedTechnique | undefined = object.userData.technique;

const minZoomLevel = getPropertyValue(technique?.minZoomLevel, this.m_env);
const maxZoomLevel = getPropertyValue(technique?.maxZoomLevel, this.m_env);

if (typeof minZoomLevel === "number" && zoomLevel < minZoomLevel) {
return false;
}

if (typeof maxZoomLevel === "number" && zoomLevel > maxZoomLevel) {
return false;
}

if (!technique || technique.enabled === undefined) {
if (technique?.enabled === undefined) {
// Nothing to do, there's no technique.
return true;
}
Expand Down
24 changes: 12 additions & 12 deletions @here/harp-mapview/lib/geometry/TileGeometryCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,13 @@ export class TileGeometryCreator {
);
textElement.pathLengthSqr = textPath.pathLengthSqr;
textElement.minZoomLevel =
technique.minZoomLevel !== undefined
? technique.minZoomLevel
: mapView.minZoomLevel;
getPropertyValue(technique.minZoomLevel, discreteZoomEnv) ??
mapView.minZoomLevel;

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

textElement.distanceScale =
technique.distanceScale !== undefined
? technique.distanceScale
Expand Down Expand Up @@ -640,13 +640,13 @@ export class TileGeometryCreator {
);

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

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

textElement.mayOverlap = technique.mayOverlap === true;
textElement.reserveSpace = technique.reserveSpace !== false;
textElement.kind = technique.kind;
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-vectortile-datasource/lib/OmvDebugLabelsTile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export class OmvDebugLabelsTile extends Tile {
xOffset,
yOffset
);
labelElement.minZoomLevel = minZoomLevel;
labelElement.minZoomLevel = getPropertyValue(minZoomLevel, env);
labelElement.mayOverlap = true;
labelElement.reserveSpace = false;
labelElement.alwaysOnTop = true;
Expand Down

0 comments on commit 8afcd67

Please sign in to comment.