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

Commit

Permalink
HARP-14862: add tile coordinates to pick results (#2220)
Browse files Browse the repository at this point in the history
Change-Id: Ie66a291dbad257fca2f61c74cd6f372e6e9f7dcc
Signed-off-by: Daniele Bacarella <daniele.bacarella@here.com>
  • Loading branch information
dbacarel committed Jun 18, 2021
1 parent f0176d0 commit 81f8e59
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
14 changes: 10 additions & 4 deletions @here/harp-mapview/lib/PickHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { GeometryType, getFeatureId, Technique } from "@here/harp-datasource-protocol";
import { OrientedBox3 } from "@here/harp-geoutils";
import { OrientedBox3, TileKey } from "@here/harp-geoutils";
import * as THREE from "three";

import { IntersectParams } from "./IntersectParams";
Expand Down Expand Up @@ -114,6 +114,11 @@ export interface PickResult {
* not be modified.
*/
userData?: any;

/**
* The tile key containing the picked object.
*/
tileKey?: TileKey;
}

const tmpV3 = new THREE.Vector3();
Expand Down Expand Up @@ -211,7 +216,7 @@ export class PickHandler {
);

for (const intersect of intersects) {
pickListener.addResult(this.createResult(intersect));
pickListener.addResult(this.createResult(intersect, tile));
}
}

Expand Down Expand Up @@ -248,13 +253,14 @@ export class PickHandler {
return this.m_pickingRaycaster;
}

private createResult(intersection: THREE.Intersection): PickResult {
private createResult(intersection: THREE.Intersection, tile?: Tile): PickResult {
const pickResult: PickResult = {
type: PickObjectType.Unspecified,
point: intersection.point,
distance: intersection.distance,
dataSourceName: intersection.object.userData?.dataSource,
intersection
intersection,
tileKey: tile?.tileKey
};

if (
Expand Down
43 changes: 40 additions & 3 deletions @here/harp-mapview/test/PickHandlerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { TileKey } from "@here/harp-geoutils";
import { expect } from "chai";
import * as sinon from "sinon";
import * as THREE from "three";
Expand All @@ -15,11 +16,11 @@ import { Tile } from "../lib/Tile";
describe("PickHandler", function () {
let pickHandler: PickHandler;
let mapViewMock: MapView;

let tile: Tile;
beforeEach(function () {
const size = new THREE.Vector2(800, 600);
const camera = new THREE.PerspectiveCamera();
const tile = ({
tile = ({
boundingBox: {
extents: new THREE.Vector3(1252344.2714, 1252344.2714, 11064),
position: new THREE.Vector3(21289852.6142, 26299229.6999, 11064),
Expand All @@ -28,7 +29,8 @@ describe("PickHandler", function () {
zAxis: new THREE.Vector3(0, 0, 1)
},
computeWorldOffsetX: () => 0,
dependencies: []
dependencies: [],
tileKey: TileKey.fromRowColumnLevel(1, 2, 3)
} as unknown) as Tile;

mapViewMock = ({
Expand Down Expand Up @@ -291,5 +293,40 @@ describe("PickHandler", function () {
name: "abruzzo"
});
});

it("returns an array of PickResult objects each having the expected properties", function () {
sinon
.stub(mapViewMock, "getWorldPositionAt")
.callsFake(() => new THREE.Vector3(21604645.272347387, 25315004.93397993, 0));

raycasterFromScreenPointStub.callsFake((x: number, y: number) => {
const raycaster = raycasterFromScreenPointStub.wrappedMethod.call(
pickHandler,
x,
y
);

sinon
.stub(raycaster, "intersectObjects")
.callsFake((objects, recursive, target: THREE.Intersection[] = []) => {
target.push({
point: new THREE.Vector3(174781.2243, 62415.6655, -2160787.9966),
distance: 2168613.8654252696,
object: ({
userData: {}
} as any) as THREE.Object3D
});

return target;
});

return raycaster;
});

const results = pickHandler.intersectMapObjects(467, 276);
expect(results).not.to.be.empty;
expect(results[0].tileKey).to.equal(tile.tileKey);
// TODO: expand to other properties in PickResult
});
});
});

0 comments on commit 81f8e59

Please sign in to comment.