@openglobus/og 0.15.4 → 0.15.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -7
- package/dist/@openglobus/og.esm.js +2 -2
- package/dist/@openglobus/og.esm.js.map +1 -1
- package/dist/@openglobus/og.umd.js +2 -2
- package/dist/@openglobus/og.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/og/LonLat.js +207 -193
- package/src/og/camera/Camera.js +4 -16
- package/src/og/camera/PlanetCamera.js +12 -6
- package/src/og/control/KeyboardNavigation.js +153 -169
- package/src/og/control/MouseNavigation.js +0 -20
- package/src/og/control/SimpleNavigation.js +10 -10
- package/src/og/ellipsoid/Ellipsoid.js +20 -3
- package/src/og/layer/Vector.js +7 -6
- package/src/og/layer/XYZ.js +2 -2
- package/src/og/quadTree/EntityCollectionNode.js +8 -2
- package/src/og/renderer/Renderer.js +1 -0
- package/src/og/scene/Planet.js +9 -5
- package/src/og/segment/Segment.js +37 -44
- package/types/LonLat.d.ts +8 -0
- package/types/camera/PlanetCamera.d.ts +1 -1
- package/types/ellipsoid/Ellipsoid.d.ts +13 -1
- package/types/layer/XYZ.d.ts +1 -1
- package/types/segment/Segment.d.ts +2 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openglobus/og",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.5",
|
|
4
4
|
"description": "[OpenGlobus](https://www.openglobus.org/) is a javascript library designed to display interactive 3d maps and planets with map tiles, imagery and vector data, markers and 3d objects. It uses the WebGL technology, open source and completely free.",
|
|
5
5
|
"directories": {
|
|
6
6
|
"example": "./sandbox"
|
package/src/og/LonLat.js
CHANGED
|
@@ -1,193 +1,207 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module og/LonLat
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
import * as mercator from "./mercator.js";
|
|
8
|
-
|
|
9
|
-
const HALF_PI = Math.PI * 0.5;
|
|
10
|
-
const INV_PI_BY_180 = 180.0 / Math.PI;
|
|
11
|
-
const INV_PI_BY_360 = INV_PI_BY_180 * 2.0;
|
|
12
|
-
const PI_BY_360 = Math.PI / 360.0;
|
|
13
|
-
const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Represents a geographical point with a certain latitude, longitude and height.
|
|
17
|
-
* @class
|
|
18
|
-
* @param {number} [lon] - Longitude.
|
|
19
|
-
* @param {number} [lat] - Latitude.
|
|
20
|
-
* @param {number} [height] - Height over the surface.
|
|
21
|
-
*/
|
|
22
|
-
export class LonLat {
|
|
23
|
-
/**
|
|
24
|
-
* @param {number} [lon] - Longitude.
|
|
25
|
-
* @param {number} [lat] - Latitude.
|
|
26
|
-
* @param {number} [height] - Height over the surface.
|
|
27
|
-
*/
|
|
28
|
-
constructor(lon = 0
|
|
29
|
-
/**
|
|
30
|
-
* Longitude.
|
|
31
|
-
* @public
|
|
32
|
-
* @type {number}
|
|
33
|
-
*/
|
|
34
|
-
this.lon = lon;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Latitude.
|
|
38
|
-
* @public
|
|
39
|
-
* @type {number}
|
|
40
|
-
*/
|
|
41
|
-
this.lat = lat;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Height.
|
|
45
|
-
* @public
|
|
46
|
-
* @type {number}
|
|
47
|
-
*/
|
|
48
|
-
this.height = height;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
isZero() {
|
|
52
|
-
return this.lon === 0.0 && this.lat === 0.0 && this.height === 0.0;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Creates coordinates array.
|
|
57
|
-
* @static
|
|
58
|
-
* @param{Array.<Array<number>>} arr - Coordinates array data. (exactly 3 entries)
|
|
59
|
-
* @return{Array.<LonLat>} the same coordinates array but each element is LonLat instance.
|
|
60
|
-
*/
|
|
61
|
-
static join(arr) {
|
|
62
|
-
var res = [];
|
|
63
|
-
for (var i = 0; i < arr.length; i++) {
|
|
64
|
-
var ai = arr[i];
|
|
65
|
-
res[i] = new LonLat(ai[0], ai[1], ai[2]);
|
|
66
|
-
}
|
|
67
|
-
return res;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Creates an object by coordinate array.
|
|
72
|
-
* @static
|
|
73
|
-
* @param {Array.<number>} arr - Coordiante array, where first is longitude, second is latitude and third is a height. (exactly 3 entries)
|
|
74
|
-
* @returns {LonLat} -
|
|
75
|
-
*/
|
|
76
|
-
static createFromArray(arr) {
|
|
77
|
-
return new LonLat(arr[0], arr[1], arr[2]);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Converts degrees to mercator coordinates.
|
|
82
|
-
* @static
|
|
83
|
-
* @param {number} lon - Degrees longitude.
|
|
84
|
-
* @param {number} lat - Degrees latitude.
|
|
85
|
-
* @param {number} [height] - Height.
|
|
86
|
-
* @returns {LonLat} -
|
|
87
|
-
*/
|
|
88
|
-
static forwardMercator(lon, lat, height) {
|
|
89
|
-
return new LonLat(
|
|
90
|
-
lon * mercator.POLE_BY_180,
|
|
91
|
-
Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI,
|
|
92
|
-
height
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Converts
|
|
98
|
-
* @static
|
|
99
|
-
* @param {
|
|
100
|
-
* @param {
|
|
101
|
-
* @
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
*
|
|
114
|
-
* @
|
|
115
|
-
* @param {number} [
|
|
116
|
-
* @
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
*
|
|
129
|
-
* @
|
|
130
|
-
* @param {
|
|
131
|
-
* @
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.
|
|
136
|
-
this.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
*
|
|
143
|
-
* @
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module og/LonLat
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
import * as mercator from "./mercator.js";
|
|
8
|
+
|
|
9
|
+
const HALF_PI = Math.PI * 0.5;
|
|
10
|
+
const INV_PI_BY_180 = 180.0 / Math.PI;
|
|
11
|
+
const INV_PI_BY_360 = INV_PI_BY_180 * 2.0;
|
|
12
|
+
const PI_BY_360 = Math.PI / 360.0;
|
|
13
|
+
const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Represents a geographical point with a certain latitude, longitude and height.
|
|
17
|
+
* @class
|
|
18
|
+
* @param {number} [lon] - Longitude.
|
|
19
|
+
* @param {number} [lat] - Latitude.
|
|
20
|
+
* @param {number} [height] - Height over the surface.
|
|
21
|
+
*/
|
|
22
|
+
export class LonLat {
|
|
23
|
+
/**
|
|
24
|
+
* @param {number} [lon] - Longitude.
|
|
25
|
+
* @param {number} [lat] - Latitude.
|
|
26
|
+
* @param {number} [height] - Height over the surface.
|
|
27
|
+
*/
|
|
28
|
+
constructor(lon = 0, lat = 0, height = 0) {
|
|
29
|
+
/**
|
|
30
|
+
* Longitude.
|
|
31
|
+
* @public
|
|
32
|
+
* @type {number}
|
|
33
|
+
*/
|
|
34
|
+
this.lon = lon;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Latitude.
|
|
38
|
+
* @public
|
|
39
|
+
* @type {number}
|
|
40
|
+
*/
|
|
41
|
+
this.lat = lat;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Height.
|
|
45
|
+
* @public
|
|
46
|
+
* @type {number}
|
|
47
|
+
*/
|
|
48
|
+
this.height = height;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
isZero() {
|
|
52
|
+
return this.lon === 0.0 && this.lat === 0.0 && this.height === 0.0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Creates coordinates array.
|
|
57
|
+
* @static
|
|
58
|
+
* @param{Array.<Array<number>>} arr - Coordinates array data. (exactly 3 entries)
|
|
59
|
+
* @return{Array.<LonLat>} the same coordinates array but each element is LonLat instance.
|
|
60
|
+
*/
|
|
61
|
+
static join(arr) {
|
|
62
|
+
var res = [];
|
|
63
|
+
for (var i = 0; i < arr.length; i++) {
|
|
64
|
+
var ai = arr[i];
|
|
65
|
+
res[i] = new LonLat(ai[0], ai[1], ai[2]);
|
|
66
|
+
}
|
|
67
|
+
return res;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Creates an object by coordinate array.
|
|
72
|
+
* @static
|
|
73
|
+
* @param {Array.<number>} arr - Coordiante array, where first is longitude, second is latitude and third is a height. (exactly 3 entries)
|
|
74
|
+
* @returns {LonLat} -
|
|
75
|
+
*/
|
|
76
|
+
static createFromArray(arr) {
|
|
77
|
+
return new LonLat(arr[0], arr[1], arr[2]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Converts degrees to mercator coordinates.
|
|
82
|
+
* @static
|
|
83
|
+
* @param {number} lon - Degrees longitude.
|
|
84
|
+
* @param {number} lat - Degrees latitude.
|
|
85
|
+
* @param {number} [height] - Height.
|
|
86
|
+
* @returns {LonLat} -
|
|
87
|
+
*/
|
|
88
|
+
static forwardMercator(lon, lat, height) {
|
|
89
|
+
return new LonLat(
|
|
90
|
+
lon * mercator.POLE_BY_180,
|
|
91
|
+
Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI,
|
|
92
|
+
height
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Converts degrees to mercator coordinates.
|
|
98
|
+
* @static
|
|
99
|
+
* @param {LonLat} lonLat - Input geodetic degree coordinates
|
|
100
|
+
* @param {LonLat} res - Output mercator coordinates
|
|
101
|
+
* @returns {LonLat} - Output mercator coordinates
|
|
102
|
+
*/
|
|
103
|
+
static forwardMercatorRes(lonLat, res) {
|
|
104
|
+
res.lon = lonLat.lon * mercator.POLE_BY_180;
|
|
105
|
+
res.lat = Math.log(Math.tan((90.0 + lonLat.lat) * PI_BY_360)) * mercator.POLE_BY_PI,
|
|
106
|
+
res.height = lonLat.height;
|
|
107
|
+
return res;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Converts mercator to degrees coordinates.
|
|
112
|
+
* @static
|
|
113
|
+
* @param {number} x - Mercator longitude.
|
|
114
|
+
* @param {number} y - Mercator latitude.
|
|
115
|
+
* @param {number} [height] - Height.
|
|
116
|
+
* @returns {LonLat} -
|
|
117
|
+
*/
|
|
118
|
+
static inverseMercator(x, y, height = 0) {
|
|
119
|
+
return new LonLat(
|
|
120
|
+
x * mercator.INV_POLE_BY_180,
|
|
121
|
+
INV_PI_BY_360 * Math.atan(Math.exp(y * mercator.PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,
|
|
122
|
+
height
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Sets coordinates.
|
|
128
|
+
* @public
|
|
129
|
+
* @param {number} [lon] - Longitude.
|
|
130
|
+
* @param {number} [lat] - Latitude.
|
|
131
|
+
* @param {number} [height] - Height.
|
|
132
|
+
* @returns {LonLat} -
|
|
133
|
+
*/
|
|
134
|
+
set(lon = 0, lat = 0, height = 0) {
|
|
135
|
+
this.lon = lon;
|
|
136
|
+
this.lat = lat;
|
|
137
|
+
this.height = height;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Copy coordinates.
|
|
143
|
+
* @public
|
|
144
|
+
* @param {LonLat} [lonLat] - Coordinates to copy.
|
|
145
|
+
* @returns {LonLat} -
|
|
146
|
+
*/
|
|
147
|
+
copy(lonLat) {
|
|
148
|
+
this.lon = lonLat.lon;
|
|
149
|
+
this.lat = lonLat.lat;
|
|
150
|
+
this.height = lonLat.height;
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Clone the coordiante.
|
|
156
|
+
* @public
|
|
157
|
+
* @returns {LonLat} -
|
|
158
|
+
*/
|
|
159
|
+
clone() {
|
|
160
|
+
return new LonLat(this.lon, this.lat, this.height);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Converts to mercator coordinates.
|
|
165
|
+
* @public
|
|
166
|
+
* @returns {LonLat} -
|
|
167
|
+
*/
|
|
168
|
+
forwardMercator() {
|
|
169
|
+
return LonLat.forwardMercator(this.lon, this.lat, this.height);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
forwardMercatorEPS01() {
|
|
173
|
+
var lat = this.lat;
|
|
174
|
+
if (lat > 89.9) {
|
|
175
|
+
lat = 89.9;
|
|
176
|
+
} else if (lat < -89.9) {
|
|
177
|
+
lat = -89.9;
|
|
178
|
+
}
|
|
179
|
+
return new LonLat(
|
|
180
|
+
this.lon * mercator.POLE_BY_180,
|
|
181
|
+
Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Converts from mercator coordinates.
|
|
187
|
+
* @public
|
|
188
|
+
* @returns {LonLat} -
|
|
189
|
+
*/
|
|
190
|
+
inverseMercator() {
|
|
191
|
+
return LonLat.inverseMercator(this.lon, this.lat, this.height);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Compares coordinates.
|
|
196
|
+
* @public
|
|
197
|
+
* @param {LonLat} b - Coordinate to compare with.
|
|
198
|
+
* @returns {boolean} -
|
|
199
|
+
*/
|
|
200
|
+
equal(b) {
|
|
201
|
+
if (b.height) {
|
|
202
|
+
return this.lon === b.lon && this.lat === b.lat && this.height === b.height;
|
|
203
|
+
} else {
|
|
204
|
+
return this.lon === b.lon && this.lat === b.lat;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
package/src/og/camera/Camera.js
CHANGED
|
@@ -255,22 +255,10 @@ class Camera {
|
|
|
255
255
|
Vec3.doubleToTwoFloat32Array(eye, this.eyeHigh, this.eyeLow);
|
|
256
256
|
|
|
257
257
|
this._viewMatrix.set([
|
|
258
|
-
u.x,
|
|
259
|
-
v.
|
|
260
|
-
n.
|
|
261
|
-
|
|
262
|
-
u.y,
|
|
263
|
-
v.y,
|
|
264
|
-
n.y,
|
|
265
|
-
0.0,
|
|
266
|
-
u.z,
|
|
267
|
-
v.z,
|
|
268
|
-
n.z,
|
|
269
|
-
0.0,
|
|
270
|
-
-eye.dot(u),
|
|
271
|
-
-eye.dot(v),
|
|
272
|
-
-eye.dot(n),
|
|
273
|
-
1.0
|
|
258
|
+
u.x, v.x, n.x, 0.0,
|
|
259
|
+
u.y, v.y, n.y, 0.0,
|
|
260
|
+
u.z, v.z, n.z, 0.0,
|
|
261
|
+
-eye.dot(u), -eye.dot(v), -eye.dot(n), 1.0
|
|
274
262
|
]);
|
|
275
263
|
|
|
276
264
|
// do not cleanup, someday it will be using
|
|
@@ -13,6 +13,7 @@ import { Ray } from "../math/Ray.js";
|
|
|
13
13
|
import { Vec3 } from "../math/Vec3.js";
|
|
14
14
|
import * as mercator from "../mercator.js";
|
|
15
15
|
import { Camera } from "./Camera.js";
|
|
16
|
+
import { Ellipsoid } from "../ellipsoid/index.js";
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Planet camera.
|
|
@@ -122,7 +123,7 @@ class PlanetCamera extends Camera {
|
|
|
122
123
|
this._flying = false;
|
|
123
124
|
this._checkTerrainCollision = true;
|
|
124
125
|
|
|
125
|
-
this._velCart = new Vec3(0.0,0.0,0.0);
|
|
126
|
+
this._velCart = new Vec3(0.0, 0.0, 0.0);
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
setTerrainCollisionActivity(isActive) {
|
|
@@ -144,16 +145,17 @@ class PlanetCamera extends Camera {
|
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
super.update();
|
|
147
|
-
|
|
148
|
+
|
|
148
149
|
this.eyeNorm = this.eye.normal();
|
|
149
150
|
this.slope = this._b.dot(this.eyeNorm);
|
|
151
|
+
|
|
150
152
|
this.events.dispatch(this.events.viewchange, this);
|
|
151
153
|
}
|
|
152
154
|
|
|
153
155
|
updateGeodeticPosition() {
|
|
154
|
-
this.
|
|
156
|
+
this.planet.ellipsoid.cartesianToLonLatRes(this.eye, this._lonLat);
|
|
155
157
|
if (Math.abs(this._lonLat.lat) <= mercator.MAX_LAT) {
|
|
156
|
-
this.
|
|
158
|
+
LonLat.forwardMercatorRes(this._lonLat, this._lonLatMerc);
|
|
157
159
|
}
|
|
158
160
|
}
|
|
159
161
|
|
|
@@ -163,11 +165,14 @@ class PlanetCamera extends Camera {
|
|
|
163
165
|
* @param {number} alt - Altitude over the terrain.
|
|
164
166
|
*/
|
|
165
167
|
setAltitude(alt) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
|
|
169
|
+
let t = this._terrainPoint;
|
|
170
|
+
let n = this.planet.ellipsoid.getSurfaceNormal3v(this.eye);
|
|
171
|
+
|
|
168
172
|
this.eye.x = n.x * alt + t.x;
|
|
169
173
|
this.eye.y = n.y * alt + t.y;
|
|
170
174
|
this.eye.z = n.z * alt + t.z;
|
|
175
|
+
|
|
171
176
|
this._terrainAltitude = alt;
|
|
172
177
|
}
|
|
173
178
|
|
|
@@ -633,6 +638,7 @@ class PlanetCamera extends Camera {
|
|
|
633
638
|
if (this._terrainAltitude < this.minAltitude && this._checkTerrainCollision) {
|
|
634
639
|
this.setAltitude(this.minAltitude);
|
|
635
640
|
}
|
|
641
|
+
return this._terrainPoint;
|
|
636
642
|
}
|
|
637
643
|
}
|
|
638
644
|
|