@openglobus/og 0.10.4 → 0.11.1

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 (172) hide show
  1. package/css/og.css +1 -1
  2. package/package.json +11 -9
  3. package/src/og/Extent.js +274 -273
  4. package/src/og/Globe.js +11 -3
  5. package/src/og/LonLat.js +152 -146
  6. package/src/og/Popup.js +2 -1
  7. package/src/og/camera/PlanetCamera.js +112 -38
  8. package/src/og/control/EarthNavigation.js +259 -0
  9. package/src/og/control/MouseNavigation.js +68 -40
  10. package/src/og/entity/EntityCollection.js +1 -1
  11. package/src/og/entity/LabelHandler.js +366 -74
  12. package/src/og/entity/Polyline.js +3 -2
  13. package/src/og/layer/CanvasTiles.js +32 -30
  14. package/src/og/layer/KML.js +159 -0
  15. package/src/og/layer/Vector.js +5 -0
  16. package/src/og/layer/index.js +2 -1
  17. package/src/og/math/Vec2.js +448 -448
  18. package/src/og/math/Vec3.js +759 -757
  19. package/src/og/math/Vec4.js +216 -215
  20. package/src/og/quadTree/Node.js +67 -13
  21. package/src/og/renderer/RendererEvents.js +21 -16
  22. package/src/og/scene/Planet.js +25 -10
  23. package/src/og/segment/Segment.js +3 -3
  24. package/src/og/segment/SegmentLonLat.js +7 -0
  25. package/src/og/terrain/GlobusTerrain.js +4 -0
  26. package/src/og/utils/FontAtlas.js +1 -0
  27. package/src/og/utils/GeoImageCreator.js +123 -121
  28. package/src/og/utils/Loader.js +81 -80
  29. package/src/og/utils/NormalMapCreator.js +320 -318
  30. package/src/og/utils/VectorTileCreator.js +251 -250
  31. package/src/og/webgl/Framebuffer.js +265 -264
  32. package/src/og/webgl/Handler.js +1022 -1001
  33. package/src/og/webgl/Multisample.js +169 -168
  34. package/src/og/webgl/ProgramController.js +113 -112
  35. package/types/Clock.d.ts +90 -0
  36. package/types/Deferred.d.ts +6 -0
  37. package/types/Events.d.ts +73 -0
  38. package/types/Extent.d.ts +162 -0
  39. package/types/Globe.d.ts +80 -0
  40. package/types/ImageCanvas.d.ts +121 -0
  41. package/types/Lock.d.ts +12 -0
  42. package/types/LonLat.d.ts +108 -0
  43. package/types/Popup.d.ts +38 -0
  44. package/types/QueueArray.d.ts +15 -0
  45. package/types/Rectangle.d.ts +74 -0
  46. package/types/Stack.d.ts +15 -0
  47. package/types/ajax.d.ts +24 -0
  48. package/types/arial.d.ts +48 -0
  49. package/types/astro/astro.d.ts +38 -0
  50. package/types/astro/earth.d.ts +6 -0
  51. package/types/astro/jd.d.ts +254 -0
  52. package/types/bv/Box.d.ts +25 -0
  53. package/types/bv/Sphere.d.ts +32 -0
  54. package/types/bv/index.d.ts +3 -0
  55. package/types/camera/Camera.d.ts +303 -0
  56. package/types/camera/Frustum.d.ts +129 -0
  57. package/types/camera/PlanetCamera.d.ts +222 -0
  58. package/types/camera/index.d.ts +3 -0
  59. package/types/cons.d.ts +40 -0
  60. package/types/control/CompassButton.d.ts +17 -0
  61. package/types/control/Control.d.ts +101 -0
  62. package/types/control/DebugInfo.d.ts +16 -0
  63. package/types/control/EarthCoordinates.d.ts +47 -0
  64. package/types/control/GeoImageDragControl.d.ts +6 -0
  65. package/types/control/KeyboardNavigation.d.ts +22 -0
  66. package/types/control/LayerSwitcher.d.ts +23 -0
  67. package/types/control/Lighting.d.ts +16 -0
  68. package/types/control/ScaleControl.d.ts +22 -0
  69. package/types/control/ShowFps.d.ts +12 -0
  70. package/types/control/SimpleNavigation.d.ts +28 -0
  71. package/types/control/Sun.d.ts +52 -0
  72. package/types/control/ToggleWireframe.d.ts +12 -0
  73. package/types/control/ZoomControl.d.ts +28 -0
  74. package/types/control/index.d.ts +15 -0
  75. package/types/ellipsoid/Ellipsoid.d.ts +142 -0
  76. package/types/ellipsoid/index.d.ts +3 -0
  77. package/types/ellipsoid/wgs84.d.ts +5 -0
  78. package/types/entity/BaseBillboard.d.ts +208 -0
  79. package/types/entity/Billboard.d.ts +94 -0
  80. package/types/entity/BillboardHandler.d.ts +74 -0
  81. package/types/entity/Entity.d.ts +330 -0
  82. package/types/entity/EntityCollection.d.ts +303 -0
  83. package/types/entity/Geometry.d.ts +72 -0
  84. package/types/entity/GeometryHandler.d.ts +76 -0
  85. package/types/entity/Label.d.ts +194 -0
  86. package/types/entity/LabelHandler.d.ts +24 -0
  87. package/types/entity/PointCloud.d.ts +174 -0
  88. package/types/entity/PointCloudHandler.d.ts +38 -0
  89. package/types/entity/Polyline.d.ts +303 -0
  90. package/types/entity/PolylineHandler.d.ts +18 -0
  91. package/types/entity/Ray.d.ts +123 -0
  92. package/types/entity/RayHandler.d.ts +67 -0
  93. package/types/entity/ShapeHandler.d.ts +22 -0
  94. package/types/entity/Strip.d.ts +118 -0
  95. package/types/entity/StripHandler.d.ts +38 -0
  96. package/types/entity/index.d.ts +8 -0
  97. package/types/index.core.d.ts +65 -0
  98. package/types/index.d.ts +45 -0
  99. package/types/index.webgl.d.ts +7 -0
  100. package/types/inherits.d.ts +4 -0
  101. package/types/input/input.d.ts +34 -0
  102. package/types/layer/BaseGeoImage.d.ts +106 -0
  103. package/types/layer/CanvasTiles.d.ts +75 -0
  104. package/types/layer/GeoImage.d.ts +65 -0
  105. package/types/layer/GeoTexture2d.d.ts +8 -0
  106. package/types/layer/GeoVideo.d.ts +80 -0
  107. package/types/layer/KML.d.ts +58 -0
  108. package/types/layer/WMS.d.ts +66 -0
  109. package/types/layer/XYZ.d.ts +126 -0
  110. package/types/layer/index.d.ts +10 -0
  111. package/types/light/LightSource.d.ts +177 -0
  112. package/types/math/Mat3.d.ts +53 -0
  113. package/types/math/Mat4.d.ts +157 -0
  114. package/types/math/Plane.d.ts +17 -0
  115. package/types/math/Vec2.d.ts +308 -0
  116. package/types/math/Vec3.d.ts +459 -0
  117. package/types/math/Vec4.d.ts +161 -0
  118. package/types/math/coder.d.ts +42 -0
  119. package/types/math/index.d.ts +11 -0
  120. package/types/math.d.ts +261 -0
  121. package/types/mercator.d.ts +92 -0
  122. package/types/proj/EPSG3857.d.ts +5 -0
  123. package/types/proj/EPSG4326.d.ts +5 -0
  124. package/types/quadTree/quadTree.d.ts +40 -0
  125. package/types/renderer/RendererEvents.d.ts +230 -0
  126. package/types/res/images.d.ts +3 -0
  127. package/types/scene/Axes.d.ts +11 -0
  128. package/types/scene/BaseNode.d.ts +60 -0
  129. package/types/scene/Planet.d.ts +572 -0
  130. package/types/scene/RenderNode.d.ts +143 -0
  131. package/types/scene/SkyBox.d.ts +10 -0
  132. package/types/scene/index.d.ts +4 -0
  133. package/types/segment/segmentHelper.d.ts +13 -0
  134. package/types/shaders/billboard.d.ts +3 -0
  135. package/types/shaders/depth.d.ts +2 -0
  136. package/types/shaders/drawnode.d.ts +7 -0
  137. package/types/shaders/label.d.ts +4 -0
  138. package/types/shaders/pointCloud.d.ts +2 -0
  139. package/types/shaders/polyline.d.ts +3 -0
  140. package/types/shaders/ray.d.ts +2 -0
  141. package/types/shaders/screenFrame.d.ts +2 -0
  142. package/types/shaders/shape.d.ts +4 -0
  143. package/types/shaders/skybox.d.ts +2 -0
  144. package/types/shaders/toneMapping.d.ts +2 -0
  145. package/types/shapes/BaseShape.d.ts +247 -0
  146. package/types/shapes/Sphere.d.ts +41 -0
  147. package/types/terrain/BilTerrain.d.ts +8 -0
  148. package/types/terrain/EmptyTerrain.d.ts +72 -0
  149. package/types/terrain/Geoid.d.ts +26 -0
  150. package/types/terrain/GlobusTerrain.d.ts +153 -0
  151. package/types/terrain/MapboxTerrain.d.ts +8 -0
  152. package/types/terrain/index.d.ts +5 -0
  153. package/types/utils/FontAtlas.d.ts +14 -0
  154. package/types/utils/GeoImageCreator.d.ts +29 -0
  155. package/types/utils/ImagesCacheManager.d.ts +10 -0
  156. package/types/utils/Loader.d.ts +25 -0
  157. package/types/utils/NormalMapCreator.d.ts +39 -0
  158. package/types/utils/PlainSegmentWorker.d.ts +10 -0
  159. package/types/utils/TerrainWorker.d.ts +9 -0
  160. package/types/utils/TextureAtlas.d.ts +111 -0
  161. package/types/utils/VectorTileCreator.d.ts +16 -0
  162. package/types/utils/colorTable.d.ts +143 -0
  163. package/types/utils/earcut.d.ts +6 -0
  164. package/types/utils/shared.d.ts +230 -0
  165. package/types/webgl/Framebuffer.d.ts +135 -0
  166. package/types/webgl/Handler.d.ts +372 -0
  167. package/types/webgl/Multisample.d.ts +89 -0
  168. package/types/webgl/Program.d.ts +155 -0
  169. package/types/webgl/ProgramController.d.ts +84 -0
  170. package/types/webgl/callbacks.d.ts +1 -0
  171. package/types/webgl/index.d.ts +6 -0
  172. package/types/webgl/types.d.ts +2 -0
@@ -2,10 +2,10 @@
2
2
  * @module og/layer/CanvasTiles
3
3
  */
4
4
 
5
- 'use strict';
5
+ "use strict";
6
6
 
7
- import * as quadTree from '../quadTree/quadTree.js';
8
- import { Layer } from './Layer.js';
7
+ import * as quadTree from "../quadTree/quadTree.js";
8
+ import { Layer } from "./Layer.js";
9
9
 
10
10
  /**
11
11
  * Maximum tiles per frame.
@@ -92,7 +92,7 @@ class CanvasTiles extends Layer {
92
92
  }
93
93
  this._pendingsQueue = [];
94
94
  // this._pendingsQueue.clear();
95
- };
95
+ }
96
96
 
97
97
  /**
98
98
  * Sets layer visibility.
@@ -119,11 +119,12 @@ class CanvasTiles extends Layer {
119
119
  * @param {og.planetSegment.Material} material -
120
120
  */
121
121
  loadMaterial(material) {
122
-
123
122
  var seg = material.segment;
124
123
 
125
124
  if (this._isBaseLayer) {
126
- material.texture = seg._isNorth ? seg.planet.solidTextureOne : seg.planet.solidTextureTwo;
125
+ material.texture = seg._isNorth
126
+ ? seg.planet.solidTextureOne
127
+ : seg.planet.solidTextureTwo;
127
128
  } else {
128
129
  material.texture = seg.planet.transparentTexture;
129
130
  }
@@ -149,33 +150,32 @@ class CanvasTiles extends Layer {
149
150
  this._counter++;
150
151
  var that = this;
151
152
  if (this.drawTile) {
152
-
153
153
  /**
154
154
  * Tile custom draw function.
155
155
  * @callback og.layer.CanvasTiles~drawTileCallback
156
156
  * @param {og.planetSegment.Material} material
157
157
  * @param {applyCanvasCallback} applyCanvasCallback
158
158
  */
159
- setTimeout(function () {
160
- var e = that.events.load;
161
- if (e.handlers.length) {
162
- that.events.dispatch(e, material);
159
+ var e = that.events.load;
160
+ if (e.handlers.length) {
161
+ that.events.dispatch(e, material);
162
+ }
163
+ that.drawTile(
164
+ material,
165
+ /**
166
+ * Apply canvas.
167
+ * @callback applyCanvasCallback
168
+ * @param {Object} canvas -
169
+ */
170
+ function (canvas) {
171
+ that._counter--;
172
+ CanvasTiles.__requestsCounter--;
173
+ if (material.isLoading) {
174
+ material.applyImage(canvas);
175
+ }
176
+ that._dequeueRequest();
163
177
  }
164
- that.drawTile(material,
165
- /**
166
- * Apply canvas.
167
- * @callback applyCanvasCallback
168
- * @param {Object} canvas -
169
- */
170
- function (canvas) {
171
- that._counter--;
172
- CanvasTiles.__requestsCounter--;
173
- if (material.isLoading) {
174
- material.applyImage(canvas);
175
- }
176
- that._dequeueRequest();
177
- });
178
- }, 50);
178
+ );
179
179
  } else {
180
180
  material.textureNotExists();
181
181
  }
@@ -214,7 +214,10 @@ class CanvasTiles extends Layer {
214
214
  while (this._pendingsQueue.length) {
215
215
  var pmat = this._pendingsQueue.pop();
216
216
  if (pmat.segment.node) {
217
- if (pmat.segment.initialized && pmat.segment.node.getState() === quadTree.RENDERING) {
217
+ if (
218
+ pmat.segment.initialized &&
219
+ pmat.segment.node.getState() === quadTree.RENDERING
220
+ ) {
218
221
  return pmat;
219
222
  }
220
223
  pmat.isLoading = false;
@@ -227,7 +230,6 @@ class CanvasTiles extends Layer {
227
230
  if (material.isReady) {
228
231
  return [0, 0, 1, 1];
229
232
  } else {
230
-
231
233
  !material.isLoading && this.loadMaterial(material);
232
234
 
233
235
  var segment = material.segment;
@@ -278,10 +280,10 @@ class CanvasTiles extends Layer {
278
280
  material.textureExists = false;
279
281
 
280
282
  if (material.image) {
281
- material.image.src = '';
283
+ material.image.src = "";
282
284
  material.image = null;
283
285
  }
284
286
  }
285
- };
287
+ }
286
288
 
287
289
  export { CanvasTiles };
@@ -0,0 +1,159 @@
1
+ /**
2
+ * @module og/layer/KML
3
+ */
4
+
5
+ 'use strict';
6
+ import { Entity } from '../entity/Entity.js';
7
+ import { Extent } from '../Extent.js';
8
+ import { LonLat } from '../LonLat.js';
9
+ import { Vector } from './Vector.js';
10
+
11
+ /**
12
+ * Layer to render KMLs files
13
+ * @class
14
+ * @extends {og.Vector}
15
+ */
16
+ export class KML extends Vector {
17
+
18
+ /**
19
+ *
20
+ * @param {string} name
21
+ * @param {*} [options]
22
+ */
23
+ constructor(name, options = {}) {
24
+ super(name, options);
25
+ this._extent = null;
26
+ this._billboard = options.billboard || { src: 'https://openglobus.org/examples/billboards/carrot.png' };
27
+ this._color = options.color || '#6689db';
28
+ }
29
+
30
+ get instanceName() {
31
+ return 'KML';
32
+ }
33
+
34
+ /**
35
+ * @private
36
+ */
37
+ _extractCoordonatesFromKml(xmlDoc) {
38
+ const raw = Array.from(xmlDoc.getElementsByTagName('coordinates'));
39
+ const coordinates = raw.map(item => item.textContent.trim().replace(/\n/g, ' ').split(' ').map(co => co.split(',').map(parseFloat)));
40
+ return coordinates;
41
+ }
42
+
43
+ /**
44
+ * Creates billboards or polylines from array of lonlat.
45
+ * @private
46
+ * @param {Array} coordonates
47
+ * @param {string} color
48
+ * @returns {Array<og.Entity>}
49
+ */
50
+ _convertCoordonatesIntoEntities(coordinates, color, billboard) {
51
+ const extent = new Extent(new LonLat(180.0, 90.0), new LonLat(-180.0, -90.0));
52
+ const addToExtent = (c) => {
53
+ const lon = c[0], lat = c[1];
54
+ if (lon < extent.southWest.lon) extent.southWest.lon = lon;
55
+ if (lat < extent.southWest.lat) extent.southWest.lat = lat;
56
+ if (lon > extent.northEast.lon) extent.northEast.lon = lon;
57
+ if (lat > extent.northEast.lat) extent.northEast.lat = lat;
58
+ };
59
+ const _pathes = [];
60
+ coordinates.forEach(kmlFile => kmlFile.forEach(p => _pathes.push(p)));
61
+ const entities = _pathes.map(path => {
62
+ if (path.length === 1) {
63
+ const lonlat = path[0];
64
+ const _entity = new Entity({ lonlat, billboard });
65
+ addToExtent(lonlat);
66
+ return _entity;
67
+ } else if (path.length > 1) {
68
+ const pathLonLat = path.map(item => {
69
+ addToExtent(item);
70
+ return new LonLat(item[0], item[1], item[2]);
71
+ });
72
+ const _entity = new Entity({ polyline: { pathLonLat: [pathLonLat], thickness: 3, color, isClosed: false } });
73
+ return _entity;
74
+ }
75
+ });
76
+ return { entities, extent };
77
+ }
78
+
79
+ /**
80
+ * @private
81
+ */
82
+ _getXmlContent(file) {
83
+ return new Promise(resolve => {
84
+ const fileReader = new FileReader();
85
+ fileReader.onload = async i => resolve((new DOMParser()).parseFromString(i.target.result, 'text/xml'));
86
+ fileReader.readAsText(file);
87
+ });
88
+ };
89
+
90
+ /**
91
+ * @private
92
+ */
93
+ _expandExtents(extent1, extent2) {
94
+ if (!extent1) return extent2;
95
+ if (extent2.southWest.lon < extent1.southWest.lon) extent1.southWest.lon = extent2.southWest.lon;
96
+ if (extent2.southWest.lat < extent1.southWest.lat) extent1.southWest.lat = extent2.southWest.lat;
97
+ if (extent2.northEast.lon > extent1.northEast.lon) extent1.northEast.lon = extent2.northEast.lon;
98
+ if (extent2.northEast.lat > extent1.northEast.lat) extent1.northEast.lat = extent2.northEast.lat;
99
+ return extent1;
100
+ }
101
+
102
+ /**
103
+ * @public
104
+ * @param {File[]} kmls
105
+ * @returns {Promise}
106
+ */
107
+ async addKmlFromFiles(kmls) {
108
+ const kmlObjs = await Promise.all(kmls.map(this._getXmlContent));
109
+ const coordonates = kmlObjs.map(this._extractCoordonatesFromKml);
110
+ const { entities, extent } = this._convertCoordonatesIntoEntities(coordonates, this._color, this._billboard);
111
+ this._extent = this._expandExtents(this._extent, extent);
112
+ entities.forEach(this.add.bind(this));
113
+ return { entities, extent };
114
+ }
115
+
116
+ /**
117
+ * @param {string} color
118
+ * @public
119
+ */
120
+ setColor(color) {
121
+ this._color = color;
122
+ this._billboard.color = color;
123
+ }
124
+
125
+ /**
126
+ * @private
127
+ */
128
+ _getKmlFromUrl(url) {
129
+ return new Promise((resolve, reject) => {
130
+ const request = new XMLHttpRequest();
131
+ request.open('GET', url, true);
132
+ request.responseType = 'document';
133
+ request.overrideMimeType('text/xml');
134
+ request.onload = () => {
135
+ if (request.readyState === request.DONE && request.status === 200) {
136
+ resolve(request.responseXML);
137
+ } else {
138
+ reject(new Error('no valid kml file'));
139
+ }
140
+ };
141
+ request.send();
142
+ });
143
+ };
144
+
145
+ /**
146
+ * @public
147
+ * @param {string} url - Url of the KML to display. './myFile.kml' or 'http://mySite/myFile.kml' for example.
148
+ * @returns {Promise}
149
+ */
150
+ async addKmlFromUrl(url) {
151
+ const kml = await this._getKmlFromUrl(url);
152
+ const coordonates = this._extractCoordonatesFromKml(kml);
153
+ const { entities, extent } = this._convertCoordonatesIntoEntities([coordonates], this._color, this._billboard);
154
+ this._extent = this._expandExtents(this._extent, extent);
155
+ entities.forEach(this.add.bind(this));
156
+ return { entities, extent };
157
+ }
158
+
159
+ };
@@ -68,6 +68,11 @@ function _entitiesConstructor(entities) {
68
68
  * @fires og.layer.Vector#visibilitychange
69
69
  */
70
70
  class Vector extends Layer {
71
+
72
+ /**
73
+ * @param {string} name
74
+ * @param {*} [options]
75
+ */
71
76
  constructor(name, options = {}) {
72
77
 
73
78
  super(name, options);
@@ -2,9 +2,10 @@ import { CanvasTiles } from './CanvasTiles.js';
2
2
  import { GeoImage } from './GeoImage.js';
3
3
  import { GeoTexture2d } from './GeoTexture2d.js';
4
4
  import { GeoVideo } from './GeoVideo.js';
5
+ import { KML } from './KML.js';
5
6
  import { Layer } from './Layer.js';
6
7
  import { Vector } from './Vector.js';
7
8
  import { WMS } from './WMS.js';
8
9
  import { XYZ } from './XYZ.js';
9
10
 
10
- export { CanvasTiles, GeoImage, GeoTexture2d, GeoVideo, Layer, Vector, WMS, XYZ };
11
+ export { CanvasTiles, GeoImage, GeoTexture2d, GeoVideo, KML, Layer, Vector, WMS, XYZ };