@openglobus/og 0.11.8 → 0.12.4

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 (197) hide show
  1. package/css/og.css +2 -0
  2. package/dist/@openglobus/og.css +1 -0
  3. package/dist/@openglobus/og.esm.js +21 -0
  4. package/dist/@openglobus/og.esm.js.map +1 -0
  5. package/dist/@openglobus/og.umd.js +21 -0
  6. package/dist/@openglobus/og.umd.js.map +1 -0
  7. package/package.json +11 -11
  8. package/src/og/Globe.js +18 -6
  9. package/src/og/camera/Camera.js +70 -79
  10. package/src/og/camera/PlanetCamera.js +25 -30
  11. package/src/og/control/DebugInfo.js +2 -2
  12. package/src/og/control/EarthNavigation.js +26 -17
  13. package/src/og/control/MouseNavigation.js +11 -13
  14. package/src/og/control/MouseWheelZoomControl.js +5 -5
  15. package/src/og/control/Sun.js +3 -3
  16. package/src/og/entity/Entity.js +742 -742
  17. package/src/og/entity/GeoObjectHandler.js +138 -134
  18. package/src/og/entity/LabelHandler.js +2 -1
  19. package/src/og/layer/CanvasTiles.js +8 -11
  20. package/src/og/layer/KML.js +19 -12
  21. package/src/og/layer/Layer.js +9 -2
  22. package/src/og/layer/XYZ.js +27 -28
  23. package/src/og/math/Vec3.js +18 -2
  24. package/src/og/quadTree/Node.js +48 -93
  25. package/src/og/quadTree/quadTree.js +1 -1
  26. package/src/og/renderer/Renderer.js +3 -5
  27. package/src/og/scene/Planet.js +147 -127
  28. package/src/og/segment/Segment.js +63 -136
  29. package/src/og/shaders/drawnode.js +132 -221
  30. package/src/og/shaders/geoObject.js +15 -6
  31. package/src/og/terrain/EmptyTerrain.js +3 -2
  32. package/src/og/terrain/GlobusTerrain.js +2 -0
  33. package/src/og/utils/Loader.js +1 -1
  34. package/src/og/utils/PlainSegmentWorker.js +0 -13
  35. package/src/og/webgl/Handler.js +13 -9
  36. package/types/Clock.d.ts +94 -0
  37. package/types/Deferred.d.ts +6 -0
  38. package/types/Events.d.ts +77 -0
  39. package/types/Extent.d.ts +166 -0
  40. package/types/Globe.d.ts +85 -0
  41. package/types/ImageCanvas.d.ts +123 -0
  42. package/types/Lock.d.ts +12 -0
  43. package/types/LonLat.d.ts +108 -0
  44. package/types/Popup.d.ts +42 -0
  45. package/types/QueueArray.d.ts +19 -0
  46. package/types/Rectangle.d.ts +80 -0
  47. package/types/Stack.d.ts +19 -0
  48. package/types/ajax.d.ts +24 -0
  49. package/types/arial.d.ts +48 -0
  50. package/types/astro/astro.d.ts +38 -0
  51. package/types/astro/earth.d.ts +7 -0
  52. package/types/astro/jd.d.ts +254 -0
  53. package/types/bv/Box.d.ts +30 -0
  54. package/types/bv/Sphere.d.ts +38 -0
  55. package/types/bv/index.d.ts +3 -0
  56. package/types/camera/Camera.d.ts +312 -0
  57. package/types/camera/Frustum.d.ts +133 -0
  58. package/types/camera/PlanetCamera.d.ts +219 -0
  59. package/types/camera/index.d.ts +3 -0
  60. package/types/cons.d.ts +40 -0
  61. package/types/control/CompassButton.d.ts +17 -0
  62. package/types/control/Control.d.ts +104 -0
  63. package/types/control/DebugInfo.d.ts +15 -0
  64. package/types/control/EarthCoordinates.d.ts +47 -0
  65. package/types/control/EarthNavigation.d.ts +43 -0
  66. package/types/control/GeoImageDragControl.d.ts +6 -0
  67. package/types/control/KeyboardNavigation.d.ts +21 -0
  68. package/types/control/LayerSwitcher.d.ts +21 -0
  69. package/types/control/Lighting.d.ts +16 -0
  70. package/types/control/MouseNavigation.d.ts +48 -0
  71. package/types/control/MouseWheelZoomControl.d.ts +45 -0
  72. package/types/control/ScaleControl.d.ts +22 -0
  73. package/types/control/ShowFps.d.ts +11 -0
  74. package/types/control/SimpleNavigation.d.ts +25 -0
  75. package/types/control/Sun.d.ts +50 -0
  76. package/types/control/ToggleWireframe.d.ts +12 -0
  77. package/types/control/TouchNavigation.d.ts +48 -0
  78. package/types/control/ZoomControl.d.ts +27 -0
  79. package/types/control/index.d.ts +18 -0
  80. package/types/ellipsoid/Ellipsoid.d.ts +146 -0
  81. package/types/ellipsoid/index.d.ts +3 -0
  82. package/types/ellipsoid/wgs84.d.ts +6 -0
  83. package/types/entity/BaseBillboard.d.ts +215 -0
  84. package/types/entity/Billboard.d.ts +94 -0
  85. package/types/entity/BillboardHandler.d.ts +79 -0
  86. package/types/entity/Entity.d.ts +348 -0
  87. package/types/entity/EntityCollection.d.ts +317 -0
  88. package/types/entity/GeoObject.d.ts +111 -0
  89. package/types/entity/GeoObjectHandler.d.ts +81 -0
  90. package/types/entity/Geometry.d.ts +74 -0
  91. package/types/entity/GeometryHandler.d.ts +76 -0
  92. package/types/entity/Label.d.ts +189 -0
  93. package/types/entity/LabelHandler.d.ts +31 -0
  94. package/types/entity/LabelWorker.d.ts +11 -0
  95. package/types/entity/PointCloud.d.ts +174 -0
  96. package/types/entity/PointCloudHandler.d.ts +38 -0
  97. package/types/entity/Polyline.d.ts +306 -0
  98. package/types/entity/PolylineHandler.d.ts +18 -0
  99. package/types/entity/Ray.d.ts +124 -0
  100. package/types/entity/RayHandler.d.ts +67 -0
  101. package/types/entity/ShapeHandler.d.ts +22 -0
  102. package/types/entity/Strip.d.ts +119 -0
  103. package/types/entity/StripHandler.d.ts +38 -0
  104. package/types/entity/index.d.ts +8 -0
  105. package/types/index.core.d.ts +65 -0
  106. package/types/index.d.ts +45 -0
  107. package/types/index.webgl.d.ts +7 -0
  108. package/types/input/KeyboardHandler.d.ts +10 -0
  109. package/types/input/MouseHandler.d.ts +5 -0
  110. package/types/input/TouchHandler.d.ts +5 -0
  111. package/types/input/input.d.ts +34 -0
  112. package/types/layer/BaseGeoImage.d.ts +94 -0
  113. package/types/layer/CanvasTiles.d.ts +67 -0
  114. package/types/layer/GeoImage.d.ts +52 -0
  115. package/types/layer/GeoTexture2d.d.ts +8 -0
  116. package/types/layer/GeoVideo.d.ts +55 -0
  117. package/types/layer/KML.d.ts +68 -0
  118. package/types/layer/Layer.d.ts +311 -0
  119. package/types/layer/Material.d.ts +45 -0
  120. package/types/layer/Vector.d.ts +208 -0
  121. package/types/layer/WMS.d.ts +61 -0
  122. package/types/layer/XYZ.d.ts +119 -0
  123. package/types/layer/index.d.ts +10 -0
  124. package/types/light/LightSource.d.ts +178 -0
  125. package/types/math/Line2.d.ts +11 -0
  126. package/types/math/Line3.d.ts +10 -0
  127. package/types/math/Mat3.d.ts +65 -0
  128. package/types/math/Mat4.d.ts +176 -0
  129. package/types/math/Plane.d.ts +18 -0
  130. package/types/math/Quat.d.ts +379 -0
  131. package/types/math/Ray.d.ts +82 -0
  132. package/types/math/Vec2.d.ts +309 -0
  133. package/types/math/Vec3.d.ts +467 -0
  134. package/types/math/Vec4.d.ts +162 -0
  135. package/types/math/coder.d.ts +43 -0
  136. package/types/math/index.d.ts +11 -0
  137. package/types/math.d.ts +261 -0
  138. package/types/mercator.d.ts +92 -0
  139. package/types/proj/EPSG3857.d.ts +6 -0
  140. package/types/proj/EPSG4326.d.ts +6 -0
  141. package/types/proj/Proj.d.ts +42 -0
  142. package/types/quadTree/EntityCollectionNode.d.ts +34 -0
  143. package/types/quadTree/Node.d.ts +60 -0
  144. package/types/quadTree/quadTree.d.ts +40 -0
  145. package/types/renderer/Renderer.d.ts +290 -0
  146. package/types/renderer/RendererEvents.d.ts +237 -0
  147. package/types/res/images.d.ts +3 -0
  148. package/types/scene/Axes.d.ts +11 -0
  149. package/types/scene/BaseNode.d.ts +60 -0
  150. package/types/scene/Planet.d.ts +576 -0
  151. package/types/scene/RenderNode.d.ts +142 -0
  152. package/types/scene/SkyBox.d.ts +10 -0
  153. package/types/scene/index.d.ts +4 -0
  154. package/types/segment/Segment.d.ts +275 -0
  155. package/types/segment/SegmentLonLat.d.ts +17 -0
  156. package/types/segment/Slice.d.ts +10 -0
  157. package/types/segment/segmentHelper.d.ts +13 -0
  158. package/types/shaders/billboard.d.ts +3 -0
  159. package/types/shaders/depth.d.ts +2 -0
  160. package/types/shaders/drawnode.d.ts +7 -0
  161. package/types/shaders/geoObject.d.ts +3 -0
  162. package/types/shaders/label.d.ts +4 -0
  163. package/types/shaders/pointCloud.d.ts +2 -0
  164. package/types/shaders/polyline.d.ts +3 -0
  165. package/types/shaders/ray.d.ts +2 -0
  166. package/types/shaders/screenFrame.d.ts +2 -0
  167. package/types/shaders/shape.d.ts +4 -0
  168. package/types/shaders/skybox.d.ts +2 -0
  169. package/types/shaders/toneMapping.d.ts +2 -0
  170. package/types/shapes/BaseShape.d.ts +250 -0
  171. package/types/shapes/Sphere.d.ts +41 -0
  172. package/types/terrain/BilTerrain.d.ts +7 -0
  173. package/types/terrain/EmptyTerrain.d.ts +73 -0
  174. package/types/terrain/Geoid.d.ts +26 -0
  175. package/types/terrain/GlobusTerrain.d.ts +116 -0
  176. package/types/terrain/MapboxTerrain.d.ts +7 -0
  177. package/types/terrain/index.d.ts +5 -0
  178. package/types/utils/FontAtlas.d.ts +15 -0
  179. package/types/utils/GeoImageCreator.d.ts +30 -0
  180. package/types/utils/ImagesCacheManager.d.ts +10 -0
  181. package/types/utils/Loader.d.ts +25 -0
  182. package/types/utils/NormalMapCreator.d.ts +39 -0
  183. package/types/utils/PlainSegmentWorker.d.ts +10 -0
  184. package/types/utils/TerrainWorker.d.ts +9 -0
  185. package/types/utils/TextureAtlas.d.ts +111 -0
  186. package/types/utils/VectorTileCreator.d.ts +16 -0
  187. package/types/utils/colorTable.d.ts +143 -0
  188. package/types/utils/earcut.d.ts +6 -0
  189. package/types/utils/shared.d.ts +231 -0
  190. package/types/webgl/Framebuffer.d.ts +135 -0
  191. package/types/webgl/Handler.d.ts +417 -0
  192. package/types/webgl/Multisample.d.ts +89 -0
  193. package/types/webgl/Program.d.ts +161 -0
  194. package/types/webgl/ProgramController.d.ts +89 -0
  195. package/types/webgl/callbacks.d.ts +1 -0
  196. package/types/webgl/index.d.ts +6 -0
  197. package/types/webgl/types.d.ts +2 -0
@@ -14,7 +14,8 @@ const VERTEX_BUFFER = 0,
14
14
  DIRECTION_BUFFER = 5,
15
15
  PITCH_ROLL_BUFFER = 6,
16
16
  SIZE_BUFFER = 7,
17
- PICKINGCOLOR_BUFFER = 8;
17
+ PICKINGCOLOR_BUFFER = 8,
18
+ VISIBLE_BUFFER = 9;
18
19
 
19
20
  const setParametersToArray = (arr = [], index = 0, length, itemSize, ...params) => {
20
21
  const currIndex = index * length;
@@ -48,6 +49,7 @@ class GeoObjectHandler {
48
49
  this._normalsArr = [[]];
49
50
  this._indicesArr = [[]];
50
51
  this._pickingColorArr = [[]];
52
+ this._vehicleVisibleArr = [[]];
51
53
 
52
54
  this._pitchRollBuffer = [];
53
55
  this._sizeBuffer = [];
@@ -59,6 +61,7 @@ class GeoObjectHandler {
59
61
  this._normalsBuffer = [];
60
62
  this._indicesBuffer = [];
61
63
  this._pickingColorBuffer = [];
64
+ this._vehicleVisibleBuffer = [];
62
65
 
63
66
  this.__staticId = GeoObjectHandler._staticCounter++;
64
67
  this._buffersUpdateCallbacks = [];
@@ -71,6 +74,7 @@ class GeoObjectHandler {
71
74
  this._buffersUpdateCallbacks[VERTEX_BUFFER] = this.createVertexBuffer;
72
75
  this._buffersUpdateCallbacks[SIZE_BUFFER] = this.createSizeBuffer;
73
76
  this._buffersUpdateCallbacks[PITCH_ROLL_BUFFER] = this.createPitchRollBuffer;
77
+ this._buffersUpdateCallbacks[VISIBLE_BUFFER] = this.createVisibleBuffer;
74
78
 
75
79
  this._changedBuffers = new Array(this._buffersUpdateCallbacks.length);
76
80
 
@@ -87,7 +91,7 @@ class GeoObjectHandler {
87
91
  for (let i = 0, len = this._vertexArr.length; i < len; i++) {
88
92
  this._vertexBuffer && h.gl.deleteBuffer(this._vertexBuffer[i]);
89
93
  this._vertexArr[i] = makeArrayTyped(this._vertexArr[i]);
90
- this._vertexBuffer[i] = h.createArrayBuffer(this._vertexArr[i], 3, len / 3);
94
+ this._vertexBuffer[i] = h.createArrayBuffer(this._vertexArr[i], 3, this._vertexArr[i].length / 3);
91
95
  }
92
96
  }
93
97
 
@@ -96,7 +100,16 @@ class GeoObjectHandler {
96
100
  for (let i = 0, len = this._pitchRollArr.length; i < len; i++) {
97
101
  this._pitchRollBuffer && h.gl.deleteBuffer(this._pitchRollBuffer[i]);
98
102
  this._pitchRollArr[i] = makeArrayTyped(this._pitchRollArr[i]);
99
- this._pitchRollBuffer[i] = h.createArrayBuffer(this._pitchRollArr[i], 2, len / 2);
103
+ this._pitchRollBuffer[i] = h.createArrayBuffer(this._pitchRollArr[i], 2, this._pitchRollArr[i].length / 2);
104
+ }
105
+ }
106
+
107
+ createVisibleBuffer() {
108
+ const h = this._renderer.handler;
109
+ for (let i = 0, len = this._vehicleVisibleArr.length; i < len; i++) {
110
+ this._vehicleVisibleBuffer && h.gl.deleteBuffer(this._vehicleVisibleBuffer[i]);
111
+ this._vehicleVisibleArr[i] = makeArrayTyped(this._vehicleVisibleArr[i]);
112
+ this._vehicleVisibleBuffer[i] = h.createArrayBuffer(this._vehicleVisibleArr[i], 1, this._vehicleVisibleArr[i].length);
100
113
  }
101
114
  }
102
115
 
@@ -105,7 +118,7 @@ class GeoObjectHandler {
105
118
  for (let i = 0, len = this._sizeArr.length; i < len; i++) {
106
119
  this._sizeBuffer && h.gl.deleteBuffer(this._sizeBuffer[i]);
107
120
  this._sizeArr[i] = makeArrayTyped(this._sizeArr[i]);
108
- this._sizeBuffer[i] = h.createArrayBuffer(this._sizeArr[i], 1, len);
121
+ this._sizeBuffer[i] = h.createArrayBuffer(this._sizeArr[i], 1, this._sizeArr[i].length);
109
122
  }
110
123
  }
111
124
 
@@ -114,14 +127,10 @@ class GeoObjectHandler {
114
127
  for (let i = 0, len = this._positionHighArr.length; i < len; i++) {
115
128
  this._positionHighBuffer && h.gl.deleteBuffer(this._positionHighBuffer[i]);
116
129
  this._positionHighArr[i] = makeArrayTyped(this._positionHighArr[i]);
117
- this._positionHighBuffer[i] = h.createArrayBuffer(this._positionHighArr[i], 3, len / 3);
130
+ this._positionHighBuffer[i] = h.createArrayBuffer(this._positionHighArr[i], 3, this._positionHighArr[i].length / 3);
118
131
  this._positionLowBuffer && h.gl.deleteBuffer(this._positionLowBuffer[i]);
119
132
  this._positionLowArr[i] = makeArrayTyped(this._positionLowArr[i]);
120
- this._positionLowBuffer[i] = h.createArrayBuffer(
121
- this._positionLowArr[i],
122
- 3,
123
- this._positionLowArr[i].length / 3
124
- );
133
+ this._positionLowBuffer[i] = h.createArrayBuffer(this._positionLowArr[i], 3, this._positionLowArr[i].length / 3);
125
134
  }
126
135
  }
127
136
 
@@ -130,7 +139,7 @@ class GeoObjectHandler {
130
139
  for (let i = 0, len = this._rgbaArr.length; i < len; i++) {
131
140
  this._rgbaBuffer && h.gl.deleteBuffer(this._rgbaBuffer[i]);
132
141
  this._rgbaArr[i] = makeArrayTyped(this._rgbaArr[i]);
133
- this._rgbaBuffer[i] = h.createArrayBuffer(this._rgbaArr[i], 4, len / 4);
142
+ this._rgbaBuffer[i] = h.createArrayBuffer(this._rgbaArr[i], 4, this._rgbaArr[i].length / 4);
134
143
  }
135
144
  }
136
145
 
@@ -139,7 +148,7 @@ class GeoObjectHandler {
139
148
  for (let i = 0, len = this._directionArr.length; i < len; i++) {
140
149
  this._directionBuffer && h.gl.deleteBuffer(this._directionBuffer[i]);
141
150
  this._directionArr[i] = makeArrayTyped(this._directionArr[i]);
142
- this._directionBuffer[i] = h.createArrayBuffer(this._directionArr[i], 3, len / 3);
151
+ this._directionBuffer[i] = h.createArrayBuffer(this._directionArr[i], 3, this._directionArr[i].length / 3);
143
152
  }
144
153
  }
145
154
 
@@ -148,7 +157,7 @@ class GeoObjectHandler {
148
157
  for (let i = 0, len = this._normalsArr.length; i < len; i++) {
149
158
  this._normalsBuffer && h.gl.deleteBuffer(this._normalsBuffer[i]);
150
159
  this._normalsArr[i] = makeArrayTyped(this._normalsArr[i]);
151
- this._normalsBuffer[i] = h.createArrayBuffer(this._normalsArr[i], 3, len / 3);
160
+ this._normalsBuffer[i] = h.createArrayBuffer(this._normalsArr[i], 3, this._normalsArr[i].length / 3);
152
161
  }
153
162
  }
154
163
 
@@ -157,11 +166,7 @@ class GeoObjectHandler {
157
166
  for (let i = 0, len = this._indicesArr.length; i < len; i++) {
158
167
  this._indicesBuffer && h.gl.deleteBuffer(this._indicesBuffer[i]);
159
168
  this._indicesArr[i] = makeArrayTyped(this._indicesArr[i], Uint16Array);
160
- this._indicesBuffer[i] = h.createElementArrayBuffer(
161
- this._indicesArr[i],
162
- 1,
163
- this._indicesArr[i].length
164
- );
169
+ this._indicesBuffer[i] = h.createElementArrayBuffer(this._indicesArr[i], 1, this._indicesArr[i].length);
165
170
  }
166
171
  }
167
172
 
@@ -170,7 +175,7 @@ class GeoObjectHandler {
170
175
  for (let i = 0, len = this._pickingColorArr.length; i < len; i++) {
171
176
  this._pickingColorBuffer && h.gl.deleteBuffer(this._pickingColorBuffer[i]);
172
177
  this._pickingColorArr[i] = makeArrayTyped(this._pickingColorArr[i]);
173
- this._pickingColorBuffer[i] = h.createArrayBuffer(this._pickingColorArr[i], 3, len / 3);
178
+ this._pickingColorBuffer[i] = h.createArrayBuffer(this._pickingColorArr[i], 3, this._pickingColorArr[i].length / 3);
174
179
  }
175
180
  }
176
181
 
@@ -215,14 +220,15 @@ class GeoObjectHandler {
215
220
  if (!alreadyAdded) {
216
221
  this._instancedTags.set(tag, {
217
222
  iCounts: 1,
223
+ maxIndex: Math.max(...geoObject._indices),
218
224
  index: this._instancedTags.size
219
225
  });
220
226
  } else {
221
227
  const prevState = this._instancedTags.get(tag),
222
228
  nextCount = prevState.iCounts + 1;
223
229
  this._instancedTags.set(tag, {
224
- iCounts: nextCount,
225
- index: prevState.index
230
+ ...prevState,
231
+ iCounts: nextCount
226
232
  });
227
233
  }
228
234
  const tagData = this._instancedTags.get(tag),
@@ -232,8 +238,9 @@ class GeoObjectHandler {
232
238
  * mark object by index for recalc indices array
233
239
  */
234
240
  geoObject._tagIndex = tagData.iCounts - 1;
235
- if (geoObject._visibility) {
236
- if (!alreadyAdded) {
241
+
242
+ if (!this._vertexArr[ti] || this._vertexArr[ti].length !== geoObject._vertices.length) {
243
+
237
244
  this._vertexArr[ti] = concatArrays(
238
245
  this._vertexArr[ti],
239
246
  setParametersToArray(
@@ -256,12 +263,11 @@ class GeoObjectHandler {
256
263
  )
257
264
  );
258
265
  }
259
- } else {
260
- this._vertexArr[ti] = concatArrays(
261
- this._vertexArr[ti],
262
- setParametersToArray([], 0, geoObject._verticesCount * itemSize, 1, 0)
263
- );
264
- }
266
+ this._vehicleVisibleArr[ti] = concatArrays(
267
+ this._vehicleVisibleArr[ti],
268
+ setParametersToArray([], 0, 1, 1, geoObject._visibility ? 1 : 0)
269
+ );
270
+
265
271
  let x = geoObject._positionHigh.x,
266
272
  y = geoObject._positionHigh.y,
267
273
  z = geoObject._positionHigh.z,
@@ -306,8 +312,6 @@ class GeoObjectHandler {
306
312
  setParametersToArray([], 0, itemSize, itemSize, x, y, z, w)
307
313
  );
308
314
 
309
- this._indicesArr[ti] = concatArrays(this._indicesArr[ti], geoObject._indices);
310
-
311
315
  x = geoObject._pitch;
312
316
  y = geoObject._roll;
313
317
 
@@ -324,7 +328,7 @@ class GeoObjectHandler {
324
328
  this._sizeArr[ti],
325
329
  setParametersToArray([], 0, itemSize, itemSize, geoObject.scale)
326
330
  );
327
- this._recalculateIndices();
331
+ this._addIndices(geoObject);
328
332
  }
329
333
 
330
334
  _displayPASS() {
@@ -357,51 +361,26 @@ class GeoObjectHandler {
357
361
  ti = tagData.index;
358
362
 
359
363
  gl.bindBuffer(gl.ARRAY_BUFFER, this._normalsBuffer[ti]);
360
- gl.vertexAttribPointer(
361
- a.aVertexNormal,
362
- this._normalsBuffer[ti].itemSize,
363
- gl.FLOAT,
364
- false,
365
- 0,
366
- 0
367
- );
364
+ gl.vertexAttribPointer(a.aVertexNormal, this._normalsBuffer[ti].itemSize, gl.FLOAT, false, 0, 0);
368
365
 
369
366
  gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer[ti]);
370
- gl.vertexAttribPointer(
371
- a.aVertexPosition,
372
- this._vertexBuffer[ti].itemSize,
373
- gl.FLOAT,
374
- false,
375
- 0,
376
- 0
377
- );
367
+ gl.vertexAttribPointer(a.aVertexPosition, this._vertexBuffer[ti].itemSize, gl.FLOAT, false, 0, 0);
378
368
 
379
369
  gl.bindBuffer(gl.ARRAY_BUFFER, this._directionBuffer[ti]);
380
- gl.vertexAttribPointer(
381
- a.aDirection,
382
- this._directionBuffer[ti].itemSize,
383
- gl.FLOAT,
384
- false,
385
- 0,
386
- 0
387
- );
370
+ gl.vertexAttribPointer(a.aDirection, this._directionBuffer[ti].itemSize, gl.FLOAT, false, 0, 0);
388
371
 
389
372
  gl.bindBuffer(gl.ARRAY_BUFFER, this._sizeBuffer[ti]);
390
373
  gl.vertexAttribPointer(a.aScale, this._sizeBuffer[ti].itemSize, gl.FLOAT, false, 0, 0);
391
374
 
392
375
  gl.bindBuffer(gl.ARRAY_BUFFER, this._pitchRollBuffer[ti]);
393
- gl.vertexAttribPointer(
394
- a.aPitchRoll,
395
- this._pitchRollBuffer[ti].itemSize,
396
- gl.FLOAT,
397
- false,
398
- 0,
399
- 0
400
- );
376
+ gl.vertexAttribPointer(a.aPitchRoll, this._pitchRollBuffer[ti].itemSize, gl.FLOAT, false, 0, 0);
401
377
 
402
378
  gl.bindBuffer(gl.ARRAY_BUFFER, this._rgbaBuffer[ti]);
403
379
  gl.vertexAttribPointer(a.aColor, this._rgbaBuffer[ti].itemSize, gl.FLOAT, false, 0, 0);
404
380
 
381
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._vehicleVisibleBuffer[ti]);
382
+ gl.vertexAttribPointer(a.aDispose, this._vehicleVisibleBuffer[ti].itemSize, gl.FLOAT, false, 0, 0);
383
+
405
384
  gl.bindBuffer(gl.ARRAY_BUFFER, this._positionHighBuffer[ti]);
406
385
  gl.vertexAttribPointer(
407
386
  a.aPositionHigh,
@@ -539,6 +518,9 @@ class GeoObjectHandler {
539
518
  0
540
519
  );
541
520
 
521
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._vehicleVisibleBuffer[ti]);
522
+ gl.vertexAttribPointer(a.aDispose, this._vehicleVisibleBuffer[ti].itemSize, gl.FLOAT, false, 0, 0);
523
+
542
524
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indicesBuffer[ti]);
543
525
 
544
526
  if (tagData.iCounts) {
@@ -561,7 +543,7 @@ class GeoObjectHandler {
561
543
  gl.disable(gl.CULL_FACE);
562
544
  }
563
545
 
564
- _recalculateIndices() {
546
+ _recalculateIndices(startIndex) {
565
547
  const allIndices = this._indicesArr,
566
548
  goArr = this._geoObjects,
567
549
  maxIndicesByTags = new Array(this._instancedTags.size).fill(0);
@@ -590,10 +572,62 @@ class GeoObjectHandler {
590
572
  }
591
573
  }
592
574
 
593
- //todo refactor for support instancing
594
- setVertexArr(index, vertexArr) {
595
- this._vertexArr = [-0.5, 0.0, 0.5, -0.5, 0.0, -0.5, 0.5, 0.0, -0.5, 0.5, 0.0, 0.5];
596
- this._changedBuffers[VERTEX_BUFFER] = true;
575
+ _addIndices(g) {
576
+ let i = g._handlerIndex;
577
+ const allIndices = this._indicesArr,
578
+ gArr = this._geoObjects,
579
+ iLen = g._indices.length,
580
+ tagData = this._instancedTags.get(g.tag),
581
+ maxIndex = tagData.maxIndex,
582
+ ti = tagData.index;
583
+
584
+ allIndices[ti] = concatArrays(allIndices[ti], g._indices);
585
+
586
+ while (gArr[i]) {
587
+ const g = gArr[i];
588
+
589
+ if (g._tagIndex > 0) {
590
+ setParametersToArray(allIndices[ti], g._tagIndex, iLen, iLen, ...g._indices.reduce((acc, cur) => {
591
+ acc.push(cur + ((maxIndex + 1) * g._tagIndex));
592
+ return acc;
593
+ }, []));
594
+ }
595
+ i++;
596
+
597
+ }
598
+
599
+ }
600
+
601
+ _removeIndices(geoObject) {
602
+ const allIndices = this._indicesArr,
603
+ gArr = this._geoObjects,
604
+ iLen = geoObject._indices.length,
605
+ tagData = this._instancedTags.get(geoObject.tag),
606
+ maxIndex = tagData.maxIndex,
607
+ ti = tagData.index,
608
+ count = tagData.iCounts;
609
+
610
+ let i = geoObject._handlerIndex;
611
+
612
+ this._indicesArr[ti] = spliceArray(this._indicesArr[ti], geoObject._tagIndex * geoObject._indicesCount, geoObject._indicesCount);
613
+
614
+ while (gArr[i]) {
615
+ if (geoObject.tag === gArr[i].tag) {
616
+ if (count !== 0) {
617
+ const startI = (gArr[i]._tagIndex - 1) * iLen;
618
+ let stopI = startI + geoObject._indicesCount;
619
+ while (stopI > startI) {
620
+ this._indicesArr[ti][stopI - 1] = allIndices[ti][stopI - 1] - maxIndex - 1;
621
+ stopI--;
622
+ }
623
+ } else {
624
+ allIndices[ti] = geoObject._indices;
625
+ }
626
+ }
627
+ i++;
628
+
629
+ }
630
+
597
631
  }
598
632
 
599
633
  setDirectionArr(index, direction) {
@@ -606,27 +640,17 @@ class GeoObjectHandler {
606
640
  length = itemSize;
607
641
  }
608
642
 
609
- setParametersToArray(
610
- this._directionArr[ti],
611
- ob._tagIndex,
612
- length,
613
- itemSize,
614
- direction.x,
615
- direction.y,
616
- direction.z
617
- );
643
+ setParametersToArray(this._directionArr[ti], ob._tagIndex, length, itemSize, direction.x, direction.y, direction.z);
618
644
  this._changedBuffers[DIRECTION_BUFFER] = true;
619
645
  }
620
646
 
621
647
  setVisibility(index, visibility) {
622
- const ob = this.getObjectByIndex(index);
623
- let vArr;
624
- if (visibility) {
625
- vArr = ob._vertices;
626
- } else {
627
- vArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
628
- }
629
- this.setVertexArr(index, vArr);
648
+ const ob = this.getObjectByIndex(index),
649
+ ti = this.getTagIndexByObjectIndex(index);
650
+
651
+ setParametersToArray(this._vehicleVisibleArr[ti], ob._tagIndex, 1, 1, visibility ? 1 : 0);
652
+
653
+ this._changedBuffers[VISIBLE_BUFFER] = true;
630
654
  }
631
655
 
632
656
  setPositionArr(index, positionHigh, positionLow) {
@@ -639,26 +663,10 @@ class GeoObjectHandler {
639
663
  length = itemSize;
640
664
  }
641
665
 
642
- setParametersToArray(
643
- this._positionHighArr[ti],
644
- ob._tagIndex,
645
- length,
646
- itemSize,
647
- positionHigh.x,
648
- positionHigh.y,
649
- positionHigh.z
650
- );
666
+ setParametersToArray(this._positionHighArr[ti], ob._tagIndex, length, itemSize, positionHigh.x, positionHigh.y, positionHigh.z);
651
667
 
652
668
  // Low
653
- setParametersToArray(
654
- this._positionLowArr[ti],
655
- ob._tagIndex,
656
- length,
657
- itemSize,
658
- positionLow.x,
659
- positionLow.y,
660
- positionLow.z
661
- );
669
+ setParametersToArray(this._positionLowArr[ti], ob._tagIndex, length, itemSize, positionLow.x, positionLow.y, positionLow.z);
662
670
 
663
671
  this._changedBuffers[POSITION_BUFFER] = true;
664
672
  }
@@ -673,16 +681,7 @@ class GeoObjectHandler {
673
681
  length = itemSize;
674
682
  }
675
683
 
676
- setParametersToArray(
677
- this._rgbaArr[ti],
678
- ob._tagIndex,
679
- length,
680
- itemSize,
681
- rgba.x,
682
- rgba.y,
683
- rgba.z,
684
- rgba.w
685
- );
684
+ setParametersToArray(this._rgbaArr[ti], ob._tagIndex, length, itemSize, rgba.x, rgba.y, rgba.z, rgba.w);
686
685
 
687
686
  this._changedBuffers[RGBA_BUFFER] = true;
688
687
  }
@@ -770,17 +769,19 @@ class GeoObjectHandler {
770
769
  this._normalsArr = null;
771
770
  this._indicesArr = null;
772
771
  this._pickingColorArr = null;
773
-
774
- this._pitchRollArr = new Float32Array();
775
- this._sizeArr = new Float32Array();
776
- this._vertexArr = new Float32Array();
777
- this._positionHighArr = new Float32Array();
778
- this._positionLowArr = new Float32Array();
779
- this._rgbaArr = new Float32Array();
780
- this._directionArr = new Float32Array();
781
- this._normalsArr = new Float32Array();
782
- this._indicesArr = new Uint16Array();
783
- this._pickingColorArr = new Float32Array();
772
+ this._vehicleVisibleArr = null;
773
+
774
+ this._pitchRollArr = [new Float32Array()];
775
+ this._sizeArr = [new Float32Array()];
776
+ this._vertexArr = [new Float32Array()];
777
+ this._positionHighArr = [new Float32Array()];
778
+ this._positionLowArr = [new Float32Array()];
779
+ this._rgbaArr = [new Float32Array()];
780
+ this._directionArr = [new Float32Array()];
781
+ this._normalsArr = [new Float32Array()];
782
+ this._indicesArr = [new Uint16Array()];
783
+ this._pickingColorArr = [new Float32Array()];
784
+ this._vehicleVisibleArr = [new Int8Array()];
784
785
 
785
786
  this._removeGeoObjects();
786
787
  this._deleteBuffers();
@@ -866,19 +867,20 @@ class GeoObjectHandler {
866
867
  const gi = geoObject._handlerIndex,
867
868
  tag = geoObject.tag,
868
869
  ti = this.getTagIndexByObjectIndex(gi),
869
- prevState = this._instancedTags.get(tag);
870
+ prevState = this._instancedTags.get(tag),
871
+ iCount = prevState.iCounts - 1;
870
872
 
871
873
  this._instancedTags.set(tag, {
872
- iCounts: prevState.iCounts - 1,
873
- index: prevState.index
874
+ ...prevState,
875
+ iCounts: iCount
874
876
  });
875
877
 
876
878
  this._geoObjects.splice(gi, 1);
877
879
 
878
- let i = gi * 4;
880
+ let i = geoObject._tagIndex * 4;
879
881
  this._rgbaArr[ti] = spliceArray(this._rgbaArr[ti], i, 4);
880
882
 
881
- i = gi * 3;
883
+ i = geoObject._tagIndex * 3;
882
884
  if (prevState.iCounts <= 1) {
883
885
  this._vertexArr[ti] = spliceArray(this._vertexArr[ti], 0, geoObject._verticesCount * 3);
884
886
  this._normalsArr[ti] = spliceArray(
@@ -892,14 +894,16 @@ class GeoObjectHandler {
892
894
  this._directionArr[ti] = spliceArray(this._directionArr[ti], i, 3);
893
895
  this._pickingColorArr[ti] = spliceArray(this._pickingColorArr[ti], i, 3);
894
896
 
895
- i = gi * 2;
897
+ i = geoObject._tagIndex * 2;
896
898
  this._pitchRollArr[ti] = spliceArray(this._pitchRollArr[ti], i, 2);
897
- this._indicesArr[ti] = spliceArray(this._indicesArr[ti], i, geoObject._indicesCount);
898
- i = gi * 1;
899
+ i = geoObject._tagIndex;
899
900
  this._sizeArr[ti] = spliceArray(this._sizeArr[ti], i, 1);
901
+ this._vehicleVisibleArr[ti] = spliceArray(this._vehicleVisibleArr[ti], i, 1);
902
+
903
+ this._removeIndices(geoObject);
900
904
 
901
905
  this._reindexGeoObjects(gi, tag);
902
- this._recalculateIndices();
906
+
903
907
  this.refresh();
904
908
 
905
909
  geoObject._handlerIndex = -1;
@@ -469,7 +469,8 @@ class LabelHandler extends BillboardHandler {
469
469
  this.refresh();
470
470
 
471
471
  label._handlerIndex = -1;
472
- label._handler = null;
472
+ label._handler = null;
473
+ label._isReady = false;
473
474
  }
474
475
 
475
476
  setText(index, text, fontIndex, align) {
@@ -98,17 +98,14 @@ class CanvasTiles extends Layer {
98
98
  * @public
99
99
  * @param {boolean} visibility - Layer visibility.
100
100
  */
101
- setVisibility(visibility) {
101
+ setVisibility(visibility) {
102
102
  if (visibility !== this._visibility) {
103
- this._visibility = visibility;
104
- if (this._isBaseLayer && visibility) {
105
- this._planet.setBaseLayer(this);
106
- } else if (!visibility) {
103
+ super.setVisibility(visibility);
104
+
105
+ if (!visibility) {
107
106
  this.abortLoading();
108
107
  }
109
- this._planet.updateVisibleLayers();
110
- this.events.dispatch(this.events.visibilitychange, this);
111
- }
108
+ }
112
109
  }
113
110
 
114
111
  /**
@@ -128,7 +125,7 @@ class CanvasTiles extends Layer {
128
125
  material.texture = seg.planet.transparentTexture;
129
126
  }
130
127
 
131
- if (this._planet.layerLock.isFree()) {
128
+ if (this._planet.layerLock.isFree() || material.segment.tileZoom < 2) {
132
129
  material.isReady = false;
133
130
  material.isLoading = true;
134
131
  if (CanvasTiles.__requestsCounter >= CanvasTiles.MAX_REQUESTS && this._counter) {
@@ -240,12 +237,12 @@ class CanvasTiles extends Layer {
240
237
  var mId = this._id;
241
238
  var psegm = material;
242
239
  while (pn.parentNode) {
240
+ pn = pn.parentNode;
241
+ psegm = pn.segment.materials[mId];
243
242
  if (psegm && psegm.isReady) {
244
243
  notEmpty = true;
245
244
  break;
246
245
  }
247
- pn = pn.parentNode;
248
- psegm = pn.segment.materials[mId];
249
246
  }
250
247
 
251
248
  if (notEmpty) {
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  "use strict";
6
+ import { Billboard } from "../entity/Billboard.js";
6
7
  import { Entity } from "../entity/Entity.js";
7
8
  import { Extent } from "../Extent.js";
8
9
  import { LonLat } from "../LonLat.js";
@@ -40,12 +41,14 @@ export class KML extends Vector {
40
41
  */
41
42
  _extractCoordonatesFromKml(xmlDoc) {
42
43
  const raw = Array.from(xmlDoc.getElementsByTagName("coordinates"));
43
- const coordinates = raw.map((item) =>
44
- item.textContent
45
- .trim()
46
- .replace(/\n/g, " ")
47
- .split(" ")
48
- .map((co) => co.split(",").map(parseFloat))
44
+ const rawText = raw.map(item => item.textContent.trim());
45
+ const coordinates = rawText.map(item =>
46
+ item
47
+ .replace(/\n/g, " ")
48
+ .replace(/\t/g, " ")
49
+ .replace(/ +/g," ")
50
+ .split(" ")
51
+ .map((co) => co.split(",").map(parseFloat))
49
52
  );
50
53
  return coordinates;
51
54
  }
@@ -121,15 +124,17 @@ export class KML extends Vector {
121
124
  /**
122
125
  * @public
123
126
  * @param {File[]} kmls
127
+ * @param {string} [color]
128
+ * @param {Billboard} [billboard]
124
129
  * @returns {Promise<{entities: Entity[], extent: Extent}>}
125
130
  */
126
- async addKmlFromFiles(kmls) {
131
+ async addKmlFromFiles(kmls, color = null, billboard = null) {
127
132
  const kmlObjs = await Promise.all(kmls.map(this._getXmlContent));
128
133
  const coordonates = kmlObjs.map(this._extractCoordonatesFromKml);
129
134
  const { entities, extent } = this._convertCoordonatesIntoEntities(
130
135
  coordonates,
131
- this._color,
132
- this._billboard
136
+ color || this._color,
137
+ billboard || this._billboard
133
138
  );
134
139
  this._extent = this._expandExtents(this._extent, extent);
135
140
  entities.forEach(this.add.bind(this));
@@ -168,15 +173,17 @@ export class KML extends Vector {
168
173
  /**
169
174
  * @public
170
175
  * @param {string} url - Url of the KML to display. './myFile.kml' or 'http://mySite/myFile.kml' for example.
176
+ * @param {string} [color]
177
+ * @param {Billboard} [billboard]
171
178
  * @returns {Promise<{entities: Entity[], extent: Extent}>}
172
179
  */
173
- async addKmlFromUrl(url) {
180
+ async addKmlFromUrl(url, color = null, billboard = null) {
174
181
  const kml = await this._getKmlFromUrl(url);
175
182
  const coordonates = this._extractCoordonatesFromKml(kml);
176
183
  const { entities, extent } = this._convertCoordonatesIntoEntities(
177
184
  [coordonates],
178
- this._color,
179
- this._billboard
185
+ color || this._color,
186
+ billboard || this._billboard
180
187
  );
181
188
  this._extent = this._expandExtents(this._extent, extent);
182
189
  entities.forEach(this.add.bind(this));
@@ -193,7 +193,9 @@ class Layer {
193
193
  */
194
194
  this._pickingColor = new Vec3();
195
195
 
196
- this._pickingEnabled = options.pickingEnabled !== undefined ? options.pickingEnabled : true;
196
+ this._pickingEnabled = options.pickingEnabled !== undefined ? options.pickingEnabled : true;
197
+
198
+ this._isPreloadDone = false;
197
199
 
198
200
  /**
199
201
  * Events handler.
@@ -497,7 +499,12 @@ class Layer {
497
499
  if (this._isBaseLayer && visibility) {
498
500
  this._planet.setBaseLayer(this);
499
501
  }
500
- this._planet.updateVisibleLayers();
502
+ this._planet.updateVisibleLayers();
503
+ if (visibility && !this._isPreloadDone && !this.isVector) {
504
+ this._isPreloadDone = true;
505
+ //TODO: make individual preload
506
+ this._planet._preLoad();
507
+ }
501
508
  }
502
509
  this.events.dispatch(this.events.visibilitychange, this);
503
510
  }