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

HARP-13493: Make maxZoomLevel value in technique non inclusive #2016

Merged
merged 1 commit into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion @here/harp-datasource-protocol/lib/StyleSetEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ export class StyleSetEvaluator {
}
}

if (typeof maxZoomLevel === "number" && zoomLevel > maxZoomLevel) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to document this change in BaseTechniqueParams in @here/harp-datasource-protocol/lib/TechniqueParams.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (typeof maxZoomLevel === "number" && zoomLevel >= maxZoomLevel) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-datasource-protocol/lib/TechniqueParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export interface BaseTechniqueParams {
minZoomLevel?: DynamicProperty<number>;

/**
* Maximum zoom level. If the current zoom level is larger, the technique will not be used.
* Maximum zoom level. If the current zoom level is equal to or greater, the technique will not be used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to check with our Design team before going forward with this change of semantics.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, shouldn't you update the semantics of all the zoom/data level constraints? e.g. DataSource.maxDisplayLevel, DataSource.maxDataLevel, MapView.maxZoomLevel, MapControls.maxZoomLevel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As agreed for the time being we leave the semantic of those properties as-is, both edges inclusive.

*/
maxZoomLevel?: DynamicProperty<number>;
}
Expand Down
34 changes: 24 additions & 10 deletions @here/harp-datasource-protocol/test/StyleSetEvaluatorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ describe("StyleSetEvaluator", function() {
])
);

assert.isNotEmpty(
getMatchingTechniques({ ...defaultProperties, $zoom: 15 }, [
assert.isEmpty(
getMatchingTechniques({ ...defaultProperties, $zoom: 13.9 }, [
{
when: ["==", ["geometry-type"], "Polygon"],
technique: "extruded-polygon",
Expand All @@ -600,11 +600,11 @@ describe("StyleSetEvaluator", function() {
);

assert.isNotEmpty(
getMatchingTechniques({ ...defaultProperties, $zoom: 15 }, [
getMatchingTechniques({ ...defaultProperties, $zoom: 14 }, [
{
when: ["==", ["geometry-type"], "Polygon"],
technique: "extruded-polygon",
minZoomLevel: 15,
minZoomLevel: 14,
maxZoomLevel: 15
}
])
Expand All @@ -615,7 +615,8 @@ describe("StyleSetEvaluator", function() {
{
when: ["==", ["geometry-type"], "Polygon"],
technique: "extruded-polygon",
minZoomLevel: 16
minZoomLevel: 15,
maxZoomLevel: 15
}
])
);
Expand All @@ -625,22 +626,35 @@ describe("StyleSetEvaluator", function() {
{
when: ["==", ["geometry-type"], "Polygon"],
technique: "extruded-polygon",
maxZoomLevel: 14
minZoomLevel: 16
}
])
);

assert.isNotEmpty(
getMatchingTechniques({ ...defaultProperties, $zoom: 15, minLevel: 14, maxLevel: 15 }, [
assert.isEmpty(
getMatchingTechniques({ ...defaultProperties, $zoom: 15 }, [
{
when: ["==", ["geometry-type"], "Polygon"],
technique: "extruded-polygon",
minZoomLevel: ["get", "minLevel"],
maxZoomLevel: ["get", "maxLevel"]
maxZoomLevel: 14
}
])
);

assert.isNotEmpty(
getMatchingTechniques(
{ ...defaultProperties, $zoom: 14.5, minLevel: 14, maxLevel: 15 },
[
{
when: ["==", ["geometry-type"], "Polygon"],
technique: "extruded-polygon",
minZoomLevel: ["get", "minLevel"],
maxZoomLevel: ["get", "maxLevel"]
}
]
)
);

assert.isEmpty(
getMatchingTechniques({ ...defaultProperties, $zoom: 15, maxLevel: 14 }, [
{
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-mapview/lib/TileObjectsRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class TileObjectRenderer {
return false;
}

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

Expand Down
1 change: 1 addition & 0 deletions @here/harp-mapview/lib/text/Placement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export function checkReadyForPlacement(
// updatePoiFromPoiTable, since that function may change those values.
if (
!textElement.visible ||
viewState.zoomLevel === textElement.maxZoomLevel ||
!MathUtils.isClamped(
viewState.zoomLevel,
textElement.minZoomLevel,
Expand Down
91 changes: 89 additions & 2 deletions @here/harp-mapview/test/PlacementTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ import {
WrappingMode
} from "@here/harp-text-canvas";
import { getAppBaseUrl } from "@here/harp-utils";
import { expect } from "chai";
import { assert, expect } from "chai";
import * as path from "path";
import * as sinon from "sinon";
import * as THREE from "three";

import { PoiBuffer } from "../lib/poi/PoiRenderer";
import { ScreenCollisions } from "../lib/ScreenCollisions";
import { placeIcon, PlacementResult, placePointLabel } from "../lib/text/Placement";
import {
checkReadyForPlacement,
placeIcon,
PlacementResult,
placePointLabel,
PrePlacementResult
} from "../lib/text/Placement";
import { RenderState } from "../lib/text/RenderState";
import { LoadingState, TextElement } from "../lib/text/TextElement";
import { TextElementState } from "../lib/text/TextElementState";
Expand Down Expand Up @@ -1330,4 +1336,85 @@ describe("Placement", function() {
expect(result).to.equal(PlacementResult.Ok);
});
});

describe("checkReadyForPlacement", () => {
let textElement: TextElement;
function checkPlacementResult(
textElement: TextElement,
viewState: any = {},
poiManager?: any
) {
return checkReadyForPlacement(
textElement,
undefined,
{
...viewState,
projection: {},
worldCenter: new THREE.Vector3(),
lookAtVector: new THREE.Vector3()
},
poiManager ?? {
updatePoiFromPoiTable: () => true
},
1000
).result;
}

before(async () => {
textElement = await createTextElement(textCanvas, "Test", new THREE.Vector3(), {}, {});
});

it("NotReady while if updatePoiFromPoiTable returns false", async () => {
assert.equal(
checkPlacementResult(
textElement,
{},
{
updatePoiFromPoiTable: () => false
}
),
PrePlacementResult.NotReady
);
});

it("Invisible if textElement is invisible", async () => {
textElement.visible = false;
assert.equal(checkPlacementResult(textElement), PrePlacementResult.Invisible);
});

it("Invisible if textElement is out of zoom range", async () => {
textElement.visible = true;
textElement.minZoomLevel = 6;
textElement.maxZoomLevel = 14;

assert.equal(
checkPlacementResult(textElement, { zoomLevel: 5 }),
PrePlacementResult.Invisible
);

assert.equal(
checkPlacementResult(textElement, { zoomLevel: 7 }),
PrePlacementResult.Ok
);

assert.equal(
checkPlacementResult(textElement, { zoomLevel: 14 }),
PrePlacementResult.Invisible
);

assert.equal(
checkPlacementResult(textElement, { zoomLevel: 14.1 }),
PrePlacementResult.Invisible
);
});

it("Invisible if both min and max zoom range are the same", () => {
textElement.minZoomLevel = 7;
textElement.maxZoomLevel = 7;
assert.equal(
checkPlacementResult(textElement, { zoomLevel: 7 }),
PrePlacementResult.Invisible
);
});
});
});