@openglobus/og 0.13.3 → 0.13.6

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.
Files changed (45) hide show
  1. package/dist/@openglobus/og.esm.js +2 -2
  2. package/dist/@openglobus/og.esm.js.map +1 -1
  3. package/dist/@openglobus/og.umd.js +2 -2
  4. package/dist/@openglobus/og.umd.js.map +1 -1
  5. package/package.json +1 -1
  6. package/src/og/Events.js +188 -188
  7. package/src/og/Globe.js +1 -0
  8. package/src/og/control/KeyboardNavigation.js +48 -2
  9. package/src/og/control/TouchNavigation.js +340 -319
  10. package/src/og/control/ZoomControl.js +1 -1
  11. package/src/og/ellipsoid/Ellipsoid.js +1 -1
  12. package/src/og/entity/Billboard.js +165 -165
  13. package/src/og/entity/BillboardHandler.js +1 -1
  14. package/src/og/entity/GeoObject.js +4 -0
  15. package/src/og/entity/GeoObjectHandler.js +22 -33
  16. package/src/og/entity/Geometry.js +319 -319
  17. package/src/og/entity/Label.js +348 -346
  18. package/src/og/entity/LabelHandler.js +44 -37
  19. package/src/og/input/input.js +7 -1
  20. package/src/og/layer/KML.js +181 -12
  21. package/src/og/layer/Layer.js +4 -2
  22. package/src/og/renderer/RendererEvents.js +1065 -1051
  23. package/src/og/scene/Planet.js +45 -27
  24. package/src/og/shaders/billboard.js +8 -0
  25. package/src/og/shaders/label.js +56 -13
  26. package/src/og/terrain/EmptyTerrain.js +159 -146
  27. package/src/og/terrain/Geoid.js +246 -241
  28. package/src/og/terrain/GlobusTerrain.js +17 -18
  29. package/src/og/terrain/MapboxTerrain.js +292 -294
  30. package/src/og/utils/FontAtlas.js +25 -15
  31. package/src/og/utils/PlainSegmentWorker.js +38 -26
  32. package/src/og/utils/TextureAtlas.js +291 -280
  33. package/types/control/KeyboardNavigation.d.ts +3 -0
  34. package/types/entity/GeoObject.d.ts +1 -0
  35. package/types/entity/Label.d.ts +1 -0
  36. package/types/entity/LabelHandler.d.ts +1 -1
  37. package/types/input/input.d.ts +6 -0
  38. package/types/layer/KML.d.ts +26 -1
  39. package/types/renderer/RendererEvents.d.ts +2 -0
  40. package/types/scene/Planet.d.ts +5 -0
  41. package/types/terrain/EmptyTerrain.d.ts +3 -1
  42. package/types/terrain/Geoid.d.ts +1 -10
  43. package/types/terrain/GlobusTerrain.d.ts +0 -1
  44. package/types/terrain/MapboxTerrain.d.ts +1 -1
  45. package/types/utils/TextureAtlas.d.ts +2 -0
@@ -1,242 +1,247 @@
1
- /* This file is mostly a straight translation of
2
- * GeographicLib/src/Geoid.cpp from C++ to JavaScript
3
- * by Kim Vandry <vandry@TZoNE.ORG>
4
- *
5
- * @license
6
- * **
7
- * * \file Geoid.cpp
8
- * * \brief Implementation for GeographicLib::Geoid class
9
- * *
10
- * * Copyright (c) Charles Karney (2009) <charles@karney.com>
11
- * * and licensed under the LGPL. For more information, see
12
- * * http://geographiclib.sourceforge.net/
13
- * **********************************************************************
14
- *
15
- * Geoid height grade not supported
16
- * The files can be downloaded from here:
17
- * http://geographiclib.sourceforge.net/1.18/geoid.html
18
- */
19
-
20
- //window.myGeoid = new Geoid();
21
-
22
- //Geoid.loadModel("./res/egm84-30.pgm")
23
- // .then(function (model) {
24
- // myGeoid.setModel(model);
25
-
26
- // globe.planet.renderer.events.on("lclick", (e) => {
27
- // let c = globe.planet.getLonLatFromPixelTerrain(e);
28
- // let h = myGeoid.getHeight(c.lon, c.lat);
29
- // console.log(`${c.lat} ${c.lon} h=${h}`);
30
- // });
31
- // })
32
- // .catch(function (err) {
33
- // // If we get here, the model failed to load
34
- // console.log(err);
35
- // });
36
-
37
- 'use strict';
38
-
39
- class Geoid {
40
- constructor(options = {}) {
41
-
42
- this.model = options.model || null;
43
- this.src = options.src || null;
44
-
45
- this._cached_ix = null;
46
- this._cached_iy = null;
47
- this._v00 = null;
48
- this._v01 = null;
49
- this._v10 = null;
50
- this._v11 = null;
51
- this._t = null;
52
- }
53
-
54
- static loadModel(url) {
55
-
56
- return fetch(url, {})
57
-
58
- .then((r) => {
59
- if (!r.ok) {
60
- throw Error("Geoid model file: HTTP error " + r.status);
61
- }
62
- return r.arrayBuffer();
63
- })
64
-
65
- .then((r) => {
66
- if (r) {
67
- return new Uint8Array(r);
68
- } else {
69
- throw Error("Geoid model file: no data from " + url);
70
- }
71
- })
72
-
73
- .then(function (rawfile) {
74
-
75
- if (!((rawfile[0] === 80) && (rawfile[1] === 53) && (
76
- ((rawfile[2] === 13) && (rawfile[3] === 10)) ||
77
- (rawfile[2] === 10)
78
- ))) {
79
- throw new Error("Geoid model file: no PGM header");
80
- }
81
-
82
- var i = (rawfile[2] === 13) ? 4 : 3;
83
- var offset = null;
84
- var scale = null;
85
-
86
- function getline() {
87
- var start = i;
88
- for (var j = i; ; j++) {
89
- if (j >= rawfile.length) {
90
- throw new Error("Geoid model file: missing newline in header");
91
- }
92
- if (rawfile[j] === 10) {
93
- i = j + 1;
94
- break;
95
- }
96
- }
97
- if ((j > start) && (rawfile[j - 1] === 13)) j--;
98
- return String.fromCharCode.apply(null, rawfile.slice(start, j));
99
- }
100
-
101
- var m, s;
102
- for (; ;) {
103
- s = getline();
104
- if (s[0] !== '#') break;
105
- m = s.match(/^# Offset (.*)$/);
106
- if (m) {
107
- offset = parseInt(m[1], 10);
108
- if (!isFinite(offset)) {
109
- throw new Error("Geoid model file: bad offset " + m[1]);
110
- }
111
- } else {
112
- m = s.match(/^# Scale (.*)$/);
113
- if (m) {
114
- scale = parseFloat(m[1]);
115
- if (!isFinite(scale)) {
116
- throw new Error("Geoid model file: bad scale " + m[1]);
117
- }
118
- }
119
- }
120
- }
121
-
122
- m = s.match(/^\s*(\d+)\s+(\d+)\s*$/);
123
-
124
- var width = null;
125
- var height = null;
126
-
127
- if (m) {
128
- width = parseInt(m[1], 10);
129
- height = parseInt(m[2], 10);
130
- }
131
-
132
- if (!(m && (width >= 0) && (height >= 0))) {
133
- throw new Error("Geoid model file: bad PGM width&height line");
134
- }
135
-
136
- var levels = parseInt(getline());
137
-
138
- if (levels != 65535) {
139
- throw new Error("Geoid model file: PGM file must have 65535 gray levels");
140
- }
141
- if (offset === null) {
142
- throw new Error("Geoid model file: PGM file does not contain offset");
143
- }
144
- if (scale === null) {
145
- throw new Error("Geoid model file: PGM file does not contain scale");
146
- }
147
- if ((width < 2) || (height < 2)) {
148
- throw new Error("Geoid model file: Raster size too small");
149
- }
150
-
151
- var payload_len = rawfile.length - i;
152
-
153
- if (payload_len !== (width * height * 2)) {
154
- throw new Error("Geoid model file: File has the wrong length");
155
- }
156
-
157
- return {
158
- scale: scale,
159
- offset: offset,
160
- width: width,
161
- height: height,
162
- rlonres: width / 360,
163
- rlatres: (height - 1) / 180,
164
- i: i,
165
- rawfile: rawfile
166
- };
167
- });
168
- }
169
-
170
- setModel(model) {
171
- this.model = model;
172
- }
173
-
174
- _rawval(ix, iy) {
175
- let model = this.model;
176
-
177
- if (iy < 0) {
178
- iy = -iy;
179
- ix += model.width / 2;
180
- } else if (iy >= model.height) {
181
- iy = 2 * (model.height - 1) - iy;
182
- ix += model.width / 2;
183
- }
184
-
185
- if (ix < 0) {
186
- ix += model.width;
187
- } else if (ix >= model.width) {
188
- ix -= model.width;
189
- }
190
-
191
- var k = (iy * model.width + ix) * 2 + model.i;
192
-
193
- return (model.rawfile[k] << 8) | model.rawfile[k + 1];
194
- }
195
-
196
- getHeightLonLat(lonlat) {
197
- return this.getHeight(lonlat.lon, lonlat.lat);
198
- }
199
-
200
- getHeight(lon, lat) {
201
-
202
- if (!this.model) return 0;
203
-
204
- let model = this.model;
205
-
206
- if (lon < 0) lon += 360.0;
207
-
208
- var fy = (90 - lat) * model.rlatres;
209
- var fx = lon * model.rlonres;
210
- var iy = Math.floor(fy);
211
- var ix = Math.floor(fx);
212
-
213
- fx -= ix;
214
- fy -= iy;
215
-
216
- if (iy === (model.height - 1)) {
217
- iy--;
218
- }
219
-
220
- if ((this._cached_ix !== ix) || (this._cached_iy !== iy)) {
221
-
222
- this._cached_ix = ix;
223
- this._cached_iy = iy;
224
-
225
- this._v00 = this._rawval(ix, iy);
226
- this._v01 = this._rawval(ix + 1, iy);
227
- this._v10 = this._rawval(ix, iy + 1);
228
- this._v11 = this._rawval(ix + 1, iy + 1);
229
- }
230
-
231
- let h = null;
232
-
233
- var a = (1 - fx) * this._v00 + fx * this._v01;
234
- var b = (1 - fx) * this._v10 + fx * this._v11;
235
-
236
- h = (1 - fy) * a + fy * b;
237
-
238
- return model.offset + model.scale * h;
239
- }
240
- }
241
-
1
+ /* This file is mostly a straight translation of
2
+ * GeographicLib/src/Geoid.cpp from C++ to JavaScript
3
+ * by Kim Vandry <vandry@TZoNE.ORG>
4
+ *
5
+ * @license
6
+ * **
7
+ * * \file Geoid.cpp
8
+ * * \brief Implementation for GeographicLib::Geoid class
9
+ * *
10
+ * * Copyright (c) Charles Karney (2009) <charles@karney.com>
11
+ * * and licensed under the LGPL. For more information, see
12
+ * * http://geographiclib.sourceforge.net/
13
+ * **********************************************************************
14
+ *
15
+ * Geoid height grade not supported
16
+ * The files can be downloaded from here:
17
+ * http://geographiclib.sourceforge.net/1.18/geoid.html
18
+ */
19
+
20
+ //window.myGeoid = new Geoid();
21
+
22
+ //Geoid.loadModel("./res/egm84-30.pgm")
23
+ // .then(function (model) {
24
+ // myGeoid.setModel(model);
25
+
26
+ // globe.planet.renderer.events.on("lclick", (e) => {
27
+ // let c = globe.planet.getLonLatFromPixelTerrain(e);
28
+ // let h = myGeoid.getHeight(c.lon, c.lat);
29
+ // console.log(`${c.lat} ${c.lon} h=${h}`);
30
+ // });
31
+ // })
32
+ // .catch(function (err) {
33
+ // // If we get here, the model failed to load
34
+ // console.log(err);
35
+ // });
36
+
37
+ 'use strict';
38
+
39
+ class Geoid {
40
+ constructor(options = {}) {
41
+
42
+ this.model = options.model || null;
43
+ this.src = options.src || null;
44
+
45
+ this._cached_ix = null;
46
+ this._cached_iy = null;
47
+ this._v00 = null;
48
+ this._v01 = null;
49
+ this._v10 = null;
50
+ this._v11 = null;
51
+ this._t = null;
52
+ }
53
+
54
+ static loadModel(url) {
55
+ if (!url) {
56
+ return new Promise((resolve) => {
57
+ resolve(null);
58
+ });
59
+ } else
60
+
61
+ return fetch(url, {})
62
+
63
+ .then((r) => {
64
+ if (!r.ok) {
65
+ throw Error("Geoid model file: HTTP error " + r.status);
66
+ }
67
+ return r.arrayBuffer();
68
+ })
69
+
70
+ .then((r) => {
71
+ if (r) {
72
+ return new Uint8Array(r);
73
+ } else {
74
+ throw Error("Geoid model file: no data from " + url);
75
+ }
76
+ })
77
+
78
+ .then(function (rawfile) {
79
+
80
+ if (!((rawfile[0] === 80) && (rawfile[1] === 53) && (
81
+ ((rawfile[2] === 13) && (rawfile[3] === 10)) ||
82
+ (rawfile[2] === 10)
83
+ ))) {
84
+ throw new Error("Geoid model file: no PGM header");
85
+ }
86
+
87
+ var i = (rawfile[2] === 13) ? 4 : 3;
88
+ var offset = null;
89
+ var scale = null;
90
+
91
+ function getline() {
92
+ var start = i;
93
+ for (var j = i; ; j++) {
94
+ if (j >= rawfile.length) {
95
+ throw new Error("Geoid model file: missing newline in header");
96
+ }
97
+ if (rawfile[j] === 10) {
98
+ i = j + 1;
99
+ break;
100
+ }
101
+ }
102
+ if ((j > start) && (rawfile[j - 1] === 13)) j--;
103
+ return String.fromCharCode.apply(null, rawfile.slice(start, j));
104
+ }
105
+
106
+ var m, s;
107
+ for (; ;) {
108
+ s = getline();
109
+ if (s[0] !== '#') break;
110
+ m = s.match(/^# Offset (.*)$/);
111
+ if (m) {
112
+ offset = parseInt(m[1], 10);
113
+ if (!isFinite(offset)) {
114
+ throw new Error("Geoid model file: bad offset " + m[1]);
115
+ }
116
+ } else {
117
+ m = s.match(/^# Scale (.*)$/);
118
+ if (m) {
119
+ scale = parseFloat(m[1]);
120
+ if (!isFinite(scale)) {
121
+ throw new Error("Geoid model file: bad scale " + m[1]);
122
+ }
123
+ }
124
+ }
125
+ }
126
+
127
+ m = s.match(/^\s*(\d+)\s+(\d+)\s*$/);
128
+
129
+ var width = null;
130
+ var height = null;
131
+
132
+ if (m) {
133
+ width = parseInt(m[1], 10);
134
+ height = parseInt(m[2], 10);
135
+ }
136
+
137
+ if (!(m && (width >= 0) && (height >= 0))) {
138
+ throw new Error("Geoid model file: bad PGM width&height line");
139
+ }
140
+
141
+ var levels = parseInt(getline());
142
+
143
+ if (levels != 65535) {
144
+ throw new Error("Geoid model file: PGM file must have 65535 gray levels");
145
+ }
146
+ if (offset === null) {
147
+ throw new Error("Geoid model file: PGM file does not contain offset");
148
+ }
149
+ if (scale === null) {
150
+ throw new Error("Geoid model file: PGM file does not contain scale");
151
+ }
152
+ if ((width < 2) || (height < 2)) {
153
+ throw new Error("Geoid model file: Raster size too small");
154
+ }
155
+
156
+ var payload_len = rawfile.length - i;
157
+
158
+ if (payload_len !== (width * height * 2)) {
159
+ throw new Error("Geoid model file: File has the wrong length");
160
+ }
161
+
162
+ return {
163
+ scale: scale,
164
+ offset: offset,
165
+ width: width,
166
+ height: height,
167
+ rlonres: width / 360,
168
+ rlatres: (height - 1) / 180,
169
+ i: i,
170
+ rawfile: rawfile
171
+ };
172
+ });
173
+ }
174
+
175
+ setModel(model) {
176
+ this.model = model;
177
+ }
178
+
179
+ _rawval(ix, iy) {
180
+ let model = this.model;
181
+
182
+ if (iy < 0) {
183
+ iy = -iy;
184
+ ix += model.width / 2;
185
+ } else if (iy >= model.height) {
186
+ iy = 2 * (model.height - 1) - iy;
187
+ ix += model.width / 2;
188
+ }
189
+
190
+ if (ix < 0) {
191
+ ix += model.width;
192
+ } else if (ix >= model.width) {
193
+ ix -= model.width;
194
+ }
195
+
196
+ var k = (iy * model.width + ix) * 2 + model.i;
197
+
198
+ return (model.rawfile[k] << 8) | model.rawfile[k + 1];
199
+ }
200
+
201
+ getHeightLonLat(lonlat) {
202
+ return this.getHeight(lonlat.lon, lonlat.lat);
203
+ }
204
+
205
+ getHeight(lon, lat) {
206
+
207
+ if (!this.model) return 0;
208
+
209
+ let model = this.model;
210
+
211
+ if (lon < 0) lon += 360.0;
212
+
213
+ var fy = (90 - lat) * model.rlatres;
214
+ var fx = lon * model.rlonres;
215
+ var iy = Math.floor(fy);
216
+ var ix = Math.floor(fx);
217
+
218
+ fx -= ix;
219
+ fy -= iy;
220
+
221
+ if (iy === (model.height - 1)) {
222
+ iy--;
223
+ }
224
+
225
+ if ((this._cached_ix !== ix) || (this._cached_iy !== iy)) {
226
+
227
+ this._cached_ix = ix;
228
+ this._cached_iy = iy;
229
+
230
+ this._v00 = this._rawval(ix, iy);
231
+ this._v01 = this._rawval(ix + 1, iy);
232
+ this._v10 = this._rawval(ix, iy + 1);
233
+ this._v11 = this._rawval(ix + 1, iy + 1);
234
+ }
235
+
236
+ let h = null;
237
+
238
+ var a = (1 - fx) * this._v00 + fx * this._v01;
239
+ var b = (1 - fx) * this._v10 + fx * this._v11;
240
+
241
+ h = (1 - fy) * a + fy * b;
242
+
243
+ return model.offset + model.scale * h;
244
+ }
245
+ }
246
+
242
247
  export { Geoid };
@@ -54,10 +54,8 @@ class GlobusTerrain extends EmptyTerrain {
54
54
  * @param {string} [name]
55
55
  * @param {*} [options]
56
56
  */
57
- constructor(name, options) {
58
- super();
59
-
60
- options = options || {};
57
+ constructor(name, options = {}) {
58
+ super({ geoidSrc: "//openglobus.org/geoid/egm84-30.pgm", ...options });
61
59
 
62
60
  /**
63
61
  * Events handler.
@@ -116,12 +114,6 @@ class GlobusTerrain extends EmptyTerrain {
116
114
  */
117
115
  this.plainGridSize = options.plainGridSize || 32;
118
116
 
119
- this._geoid =
120
- options.geoid ||
121
- new Geoid({
122
- src: options.geoidSrc || "//openglobus.org/geoid/egm84-30.pgm"
123
- });
124
-
125
117
  this._extent = createExtent(
126
118
  options.extent,
127
119
  new Extent(new LonLat(-180.0, -90.0), new LonLat(180.0, 90.0))
@@ -167,10 +159,6 @@ class GlobusTerrain extends EmptyTerrain {
167
159
  this._fetchCache = {};
168
160
  }
169
161
 
170
- getGeoid() {
171
- return this._geoid;
172
- }
173
-
174
162
  isBlur(segment) {
175
163
  if (segment.tileZoom >= 8) {
176
164
  return true;
@@ -216,17 +204,20 @@ class GlobusTerrain extends EmptyTerrain {
216
204
  }
217
205
 
218
206
  this._fetchCache[tileIndex].then((response) => {
207
+
208
+ let extent = mercator.getTileExtent(x, y, z);
209
+
219
210
  if (response.status === "ready") {
220
211
  let cache = {
221
- heights: this._createHeights(response.data),
222
- extent: mercator.getTileExtent(x, y, z)
212
+ heights: this._createHeights(response.data, tileIndex, x, y, z, extent),
213
+ extent: extent
223
214
  };
224
215
  this._elevationCache[tileIndex] = cache;
225
216
  callback(this._getGroundHeightMerc(merc, cache));
226
217
  } else if (response.status === "error") {
227
218
  let cache = {
228
219
  heights: null,
229
- extent: mercator.getTileExtent(x, y, z)
220
+ extent: extent
230
221
  };
231
222
  this._elevationCache[tileIndex] = cache;
232
223
  callback(this._geoid.getHeightLonLat(lonLat));
@@ -374,12 +365,20 @@ class GlobusTerrain extends EmptyTerrain {
374
365
  },
375
366
  (response) => {
376
367
  if (response.status === "ready") {
377
- let heights = this._createHeights(response.data, segment);
368
+
369
+ let heights = this._createHeights(response.data,
370
+ segment.tileIndex,
371
+ segment.tileX, segment.tileY, segment.tileZoom,
372
+ segment.getExtent()
373
+ );
374
+
378
375
  this._elevationCache[segment.tileIndex] = {
379
376
  heights: heights,
380
377
  extent: segment.getExtent()
381
378
  };
379
+
382
380
  this._applyElevationsData(segment, heights);
381
+
383
382
  } else if (response.status === "abort") {
384
383
  segment.terrainIsLoading = false;
385
384
  } else if (response.status === "error") {