-
Notifications
You must be signed in to change notification settings - Fork 83
/
Marker.ts
109 lines (86 loc) · 2.39 KB
/
Marker.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import * as THREE from "three";
import {ILatLon} from "../../../API";
/**
* @class Marker
*
* @classdesc Represents an abstract marker class that should be extended
* by marker implementations used in the marker component.
*/
export abstract class Marker {
protected _id: string;
protected _geometry: THREE.Object3D;
protected _latLon: ILatLon;
constructor(id: string, latLon: ILatLon) {
this._id = id;
this._latLon = latLon;
}
/**
* Get id.
* @returns {string} The id of the marker.
*/
public get id(): string {
return this._id;
}
/**
* Get geometry.
*
* @ignore
*/
public get geometry(): THREE.Object3D {
return this._geometry;
}
/**
* Get lat lon.
* @returns {ILatLon} The geographic coordinates of the marker.
*/
public get latLon(): ILatLon {
return this._latLon;
}
/** @ignore */
public createGeometry(position: number[]): void {
if (!!this._geometry) {
return;
}
this._createGeometry(position);
// update matrix world if raycasting occurs before first render
this._geometry.updateMatrixWorld(true);
}
/** @ignore */
public disposeGeometry(): void {
if (!this._geometry) {
return;
}
this._disposeGeometry();
this._geometry = undefined;
}
/** @ignore */
public getInteractiveObjects(): THREE.Object3D[] {
if (!this._geometry) {
return [];
}
return this._getInteractiveObjects();
}
/** @ignore */
public lerpAltitude(alt: number, alpha: number): void {
if (!this._geometry) {
return;
}
this._geometry.position.z = (1 - alpha) * this._geometry.position.z + alpha * alt;
}
/** @ignore */
public updatePosition(position: number[], latLon?: ILatLon): void {
if (!!latLon) {
this._latLon.lat = latLon.lat;
this._latLon.lon = latLon.lon;
}
if (!this._geometry) {
return;
}
this._geometry.position.fromArray(position);
this._geometry.updateMatrixWorld(true);
}
protected abstract _createGeometry(position: number[]): void;
protected abstract _disposeGeometry(): void;
protected abstract _getInteractiveObjects(): THREE.Object3D[];
}
export default Marker;