This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HARP-10793: Add styleSetName and category to MapAnchors and removed M…
…apView.worldAnchors (#1610)
- Loading branch information
Showing
6 changed files
with
195 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* Copyright (C) 2017-2020 HERE Europe B.V. | ||
* Licensed under Apache 2.0, see full license in LICENSE | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { StylePriority } from "@here/harp-datasource-protocol"; | ||
import { | ||
GeoCoordinates, | ||
GeoCoordLike, | ||
isGeoCoordinatesLike, | ||
isVector3Like, | ||
Projection, | ||
Vector3Like | ||
} from "@here/harp-geoutils"; | ||
|
||
import * as THREE from "three"; | ||
|
||
/** | ||
* An interface describing [[THREE.Object3D]]s anchored on given [[GeoCoordinates]]. | ||
* | ||
* Example: | ||
* ```typescript | ||
* const mesh: MapAnchor<THREE.Mesh> = new THREE.Mesh(geometry, material); | ||
* mesh.anchor = new GeoCoordinates(latitude, longitude, altitude); | ||
* mapView.mapAnchors.add(mesh); | ||
* ``` | ||
*/ | ||
export type MapAnchor<T extends THREE.Object3D = THREE.Object3D> = T & { | ||
/** | ||
* The position of this [[MapAnchor]] in [[GeoCoordinates]]. | ||
* @deprecated Use [[anchor]] instead. | ||
*/ | ||
geoPosition?: GeoCoordinates; | ||
|
||
/** | ||
* The anchor of this Object3D in [[GeoCoordinates]] or world coordinates. | ||
*/ | ||
anchor?: GeoCoordLike | Vector3Like; | ||
|
||
/** | ||
* Flag defining if the object may be picked. | ||
* | ||
* @note By default all objects are pickable even if this flag is undefined. | ||
*/ | ||
pickable?: boolean; | ||
|
||
/** | ||
* The styleSet that owns this map object. | ||
* | ||
* @remarks | ||
* This property is used together with [[Theme.priorities]] to compute the render | ||
* order of this map object. | ||
*/ | ||
styleSet?: string; | ||
|
||
/** | ||
* The category of this style. | ||
* | ||
* @remarks | ||
* This property is used together with [[Theme.priorities]] to compute the render | ||
* order of this mao object. | ||
*/ | ||
category?: string; | ||
}; | ||
|
||
/** | ||
* Container holding [[MapAnchor]] objects. | ||
*/ | ||
export class MapAnchors { | ||
private m_anchors: MapAnchor[] = []; | ||
|
||
/** | ||
* All currently added [[MapAnchor]]s. | ||
*/ | ||
get children() { | ||
return this.m_anchors; | ||
} | ||
|
||
/** | ||
* Add a [[MapAnchor]]. | ||
* @param mapAnchor [[MapAnchor]] instance to add. | ||
*/ | ||
add(mapAnchor: MapAnchor) { | ||
this.m_anchors.push(mapAnchor); | ||
} | ||
|
||
/** | ||
* Remove a [[MapAnchor]]. | ||
* @param mapAnchor - [[MapAnchor]] instance to remove. | ||
* | ||
* @note This method is potentially slow when removing a lot of anchors. | ||
* [[clear]]ing and [[add]]ing anchors should be considered in that case. | ||
*/ | ||
remove(mapAnchor: MapAnchor) { | ||
const index = this.m_anchors.findIndex(element => element === mapAnchor); | ||
if (index > -1) { | ||
this.m_anchors.splice(index, 1); | ||
} | ||
} | ||
|
||
/** | ||
* Remove all [[MapAnchor]]s. | ||
*/ | ||
clear() { | ||
this.m_anchors.length = 0; | ||
} | ||
|
||
/** | ||
* Update the map anchors. | ||
* @param projection - Current projection | ||
* @param cameraPosition - Current camera position | ||
* @param rootNode - Node where the objects will be inserted | ||
* @param priorities - Optional theme priority list | ||
* | ||
* @internal | ||
* @hidden | ||
*/ | ||
update( | ||
projection: Projection, | ||
cameraPosition: THREE.Vector3, | ||
rootNode: THREE.Object3D, | ||
priorities?: StylePriority[] | ||
) { | ||
const worldPosition = new THREE.Vector3(); | ||
|
||
this.m_anchors.forEach((mapAnchor: MapAnchor) => { | ||
if (mapAnchor.styleSet !== undefined) { | ||
const priority = priorities?.findIndex( | ||
entry => | ||
entry.group === mapAnchor.styleSet && entry.category === mapAnchor.category | ||
); | ||
|
||
if (priority !== undefined && priority !== -1) { | ||
mapAnchor.renderOrder = (priority + 1) * 10; | ||
} | ||
} | ||
|
||
const anchor = | ||
// tslint:disable-next-line: deprecation | ||
mapAnchor.geoPosition !== undefined ? mapAnchor.geoPosition : mapAnchor.anchor; | ||
if (anchor !== undefined) { | ||
if (isVector3Like(anchor)) { | ||
worldPosition.set(anchor.x, anchor.y, anchor.z); | ||
} else if (isGeoCoordinatesLike(anchor)) { | ||
projection.projectPoint(anchor, worldPosition); | ||
} | ||
mapAnchor.position.copy(worldPosition).sub(cameraPosition); | ||
} | ||
|
||
rootNode.add(mapAnchor); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.