@openglobus/og 0.22.2 → 0.24.0

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 (205) hide show
  1. package/css/og.css +137 -1
  2. package/lib/@openglobus/js/Globe.d.ts +0 -1
  3. package/lib/@openglobus/js/Object3d.d.ts +20 -10
  4. package/lib/@openglobus/js/camera/Camera.d.ts +57 -15
  5. package/lib/@openglobus/js/camera/Frustum.d.ts +3 -0
  6. package/lib/@openglobus/js/camera/PlanetCamera.d.ts +13 -0
  7. package/lib/@openglobus/js/control/CameraLock.d.ts +38 -0
  8. package/lib/@openglobus/js/control/MouseNavigation.d.ts +62 -51
  9. package/lib/@openglobus/js/control/OldMouseNavigation.d.ts +64 -0
  10. package/lib/@openglobus/js/control/SimpleNavigation.d.ts +27 -10
  11. package/lib/@openglobus/js/control/geoObjectEditor/ArrowEntity.d.ts +15 -0
  12. package/lib/@openglobus/js/control/geoObjectEditor/AxisTrackEntity.d.ts +9 -0
  13. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditor.d.ts +13 -0
  14. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +69 -0
  15. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +78 -9
  16. package/lib/@openglobus/js/control/geoObjectEditor/MoveAxisEntity.d.ts +17 -0
  17. package/lib/@openglobus/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
  18. package/lib/@openglobus/js/control/geoObjectEditor/RotateEntity.d.ts +9 -0
  19. package/lib/@openglobus/js/control/geoObjectEditor/colors.d.ts +8 -0
  20. package/lib/@openglobus/js/control/index.d.ts +3 -2
  21. package/lib/@openglobus/js/entity/Entity.d.ts +282 -19
  22. package/lib/@openglobus/js/entity/EntityCollection.d.ts +8 -9
  23. package/lib/@openglobus/js/entity/GeoObject.d.ts +135 -39
  24. package/lib/@openglobus/js/entity/GeoObjectHandler.d.ts +39 -63
  25. package/lib/@openglobus/js/entity/InstanceData.d.ts +76 -0
  26. package/lib/@openglobus/js/entity/Polyline.d.ts +19 -6
  27. package/lib/@openglobus/js/entity/PolylineHandler.d.ts +7 -0
  28. package/lib/@openglobus/js/index.d.ts +2 -1
  29. package/lib/@openglobus/js/input/MouseHandler.d.ts +1 -0
  30. package/lib/@openglobus/js/layer/Vector.d.ts +4 -0
  31. package/lib/@openglobus/js/light/LightSource.d.ts +1 -139
  32. package/lib/@openglobus/js/math/Mat3.d.ts +1 -1
  33. package/lib/@openglobus/js/math/Mat4.d.ts +10 -1
  34. package/lib/@openglobus/js/math/Plane.d.ts +3 -1
  35. package/lib/@openglobus/js/math/Quat.d.ts +47 -33
  36. package/lib/@openglobus/js/math/Ray.d.ts +10 -14
  37. package/lib/@openglobus/js/math/Vec2.d.ts +22 -0
  38. package/lib/@openglobus/js/math/Vec3.d.ts +15 -0
  39. package/lib/@openglobus/js/math.d.ts +2 -2
  40. package/lib/@openglobus/js/quadTree/EntityCollectionNode.d.ts +2 -2
  41. package/lib/@openglobus/js/quadTree/Node.d.ts +1 -1
  42. package/lib/@openglobus/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +1 -1
  43. package/lib/@openglobus/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +1 -1
  44. package/lib/@openglobus/js/renderer/Renderer.d.ts +63 -44
  45. package/lib/@openglobus/js/renderer/RendererEvents.d.ts +2 -0
  46. package/lib/@openglobus/js/scene/Planet.d.ts +15 -7
  47. package/lib/@openglobus/js/scene/RenderNode.d.ts +10 -25
  48. package/lib/@openglobus/js/shaders/drawnode.d.ts +1 -0
  49. package/lib/@openglobus/js/shaders/geoObject.d.ts +1 -0
  50. package/lib/@openglobus/js/shaders/utils.d.ts +1 -1
  51. package/lib/@openglobus/js/ui/Checkbox.d.ts +31 -0
  52. package/lib/@openglobus/js/ui/Dialog.d.ts +3 -0
  53. package/lib/@openglobus/js/ui/Input.d.ts +32 -0
  54. package/lib/@openglobus/js/ui/View.d.ts +3 -1
  55. package/lib/@openglobus/js/utils/objParser.d.ts +44 -12
  56. package/lib/@openglobus/js/utils/shared.d.ts +22 -0
  57. package/lib/@openglobus/js/webgl/BaseFramebuffer.d.ts +0 -1
  58. package/lib/@openglobus/js/webgl/Framebuffer.d.ts +35 -8
  59. package/lib/@openglobus/js/webgl/Handler.d.ts +22 -12
  60. package/lib/@openglobus/og.css +1 -1
  61. package/lib/@openglobus/og.esm.js +1 -1
  62. package/lib/@openglobus/og.esm.js.map +1 -1
  63. package/lib/@openglobus/og.umd.js +1 -1
  64. package/lib/@openglobus/og.umd.js.map +1 -1
  65. package/lib/js/Globe.d.ts +0 -1
  66. package/lib/js/Globe.js +4 -2
  67. package/lib/js/Object3d.d.ts +20 -10
  68. package/lib/js/Object3d.js +124 -48
  69. package/lib/js/Popup.js +1 -1
  70. package/lib/js/camera/Camera.d.ts +57 -15
  71. package/lib/js/camera/Camera.js +109 -29
  72. package/lib/js/camera/Frustum.d.ts +3 -0
  73. package/lib/js/camera/Frustum.js +7 -0
  74. package/lib/js/camera/PlanetCamera.d.ts +13 -0
  75. package/lib/js/camera/PlanetCamera.js +52 -5
  76. package/lib/js/control/Atmosphere.js +10 -6
  77. package/lib/js/control/CameraLock.d.ts +38 -0
  78. package/lib/js/control/CameraLock.js +216 -0
  79. package/lib/js/control/Control.js +1 -1
  80. package/lib/js/control/DebugInfo.js +38 -8
  81. package/lib/js/control/KeyboardNavigation.js +9 -9
  82. package/lib/js/control/MouseNavigation.d.ts +62 -51
  83. package/lib/js/control/MouseNavigation.js +361 -305
  84. package/lib/js/control/MouseWheelZoomControl.d.ts +0 -44
  85. package/lib/js/control/MouseWheelZoomControl.js +270 -181
  86. package/lib/js/control/OldMouseNavigation.d.ts +64 -0
  87. package/lib/js/control/OldMouseNavigation.js +368 -0
  88. package/lib/js/control/ScaleControl.js +11 -5
  89. package/lib/js/control/SimpleNavigation.d.ts +27 -10
  90. package/lib/js/control/SimpleNavigation.js +149 -49
  91. package/lib/js/control/Sun.js +6 -6
  92. package/lib/js/control/TouchNavigation.js +11 -8
  93. package/lib/js/control/elevationProfile/ElevationProfileScene.js +6 -5
  94. package/lib/js/control/geoObjectEditor/ArrowEntity.d.ts +15 -0
  95. package/lib/js/control/geoObjectEditor/ArrowEntity.js +59 -0
  96. package/lib/js/control/geoObjectEditor/AxisTrackEntity.d.ts +9 -0
  97. package/lib/js/control/geoObjectEditor/AxisTrackEntity.js +93 -0
  98. package/lib/js/control/geoObjectEditor/GeoObjectEditor.d.ts +13 -0
  99. package/lib/js/control/geoObjectEditor/GeoObjectEditor.js +30 -0
  100. package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +69 -0
  101. package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.js +488 -0
  102. package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +78 -9
  103. package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.js +487 -43
  104. package/lib/js/control/geoObjectEditor/MoveAxisEntity.d.ts +17 -0
  105. package/lib/js/control/geoObjectEditor/MoveAxisEntity.js +107 -0
  106. package/lib/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
  107. package/lib/js/control/geoObjectEditor/MovePlaneEntity.js +31 -0
  108. package/lib/js/control/geoObjectEditor/RotateEntity.d.ts +9 -0
  109. package/lib/js/control/geoObjectEditor/RotateEntity.js +105 -0
  110. package/lib/js/control/geoObjectEditor/colors.d.ts +8 -0
  111. package/lib/js/control/geoObjectEditor/colors.js +8 -0
  112. package/lib/js/control/index.d.ts +3 -2
  113. package/lib/js/control/index.js +3 -2
  114. package/lib/js/control/timeline/TimelineControl.js +2 -0
  115. package/lib/js/control/visibleExtent/Segment.js +4 -4
  116. package/lib/js/entity/Entity.d.ts +282 -19
  117. package/lib/js/entity/Entity.js +497 -62
  118. package/lib/js/entity/EntityCollection.d.ts +8 -9
  119. package/lib/js/entity/EntityCollection.js +48 -45
  120. package/lib/js/entity/GeoObject.d.ts +135 -39
  121. package/lib/js/entity/GeoObject.js +150 -90
  122. package/lib/js/entity/GeoObjectHandler.d.ts +39 -63
  123. package/lib/js/entity/GeoObjectHandler.js +198 -295
  124. package/lib/js/entity/InstanceData.d.ts +76 -0
  125. package/lib/js/entity/InstanceData.js +347 -0
  126. package/lib/js/entity/Polyline.d.ts +19 -6
  127. package/lib/js/entity/Polyline.js +76 -36
  128. package/lib/js/entity/PolylineHandler.d.ts +7 -0
  129. package/lib/js/entity/PolylineHandler.js +26 -1
  130. package/lib/js/index.d.ts +2 -1
  131. package/lib/js/index.js +2 -1
  132. package/lib/js/input/MouseHandler.d.ts +1 -0
  133. package/lib/js/input/MouseHandler.js +12 -1
  134. package/lib/js/layer/Bing.js +2 -2
  135. package/lib/js/layer/Vector.d.ts +4 -0
  136. package/lib/js/layer/Vector.js +16 -0
  137. package/lib/js/light/LightSource.d.ts +1 -139
  138. package/lib/js/light/LightSource.js +21 -227
  139. package/lib/js/math/Mat3.d.ts +1 -1
  140. package/lib/js/math/Mat3.js +1 -1
  141. package/lib/js/math/Mat4.d.ts +10 -1
  142. package/lib/js/math/Mat4.js +17 -1
  143. package/lib/js/math/Plane.d.ts +3 -1
  144. package/lib/js/math/Plane.js +11 -1
  145. package/lib/js/math/Quat.d.ts +47 -33
  146. package/lib/js/math/Quat.js +92 -90
  147. package/lib/js/math/Ray.d.ts +10 -14
  148. package/lib/js/math/Ray.js +56 -33
  149. package/lib/js/math/Vec2.d.ts +22 -0
  150. package/lib/js/math/Vec2.js +32 -0
  151. package/lib/js/math/Vec3.d.ts +15 -0
  152. package/lib/js/math/Vec3.js +30 -1
  153. package/lib/js/math.d.ts +2 -2
  154. package/lib/js/math.js +3 -3
  155. package/lib/js/quadTree/EntityCollectionNode.d.ts +2 -2
  156. package/lib/js/quadTree/EntityCollectionNode.js +8 -8
  157. package/lib/js/quadTree/Node.d.ts +1 -1
  158. package/lib/js/quadTree/Node.js +2 -2
  159. package/lib/js/quadTree/QuadTreeStrategy.js +1 -1
  160. package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +1 -1
  161. package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.js +2 -2
  162. package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +1 -1
  163. package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.js +2 -2
  164. package/lib/js/renderer/Renderer.d.ts +63 -44
  165. package/lib/js/renderer/Renderer.js +267 -266
  166. package/lib/js/renderer/RendererEvents.d.ts +2 -0
  167. package/lib/js/renderer/RendererEvents.js +5 -2
  168. package/lib/js/scene/Planet.d.ts +15 -7
  169. package/lib/js/scene/Planet.js +133 -90
  170. package/lib/js/scene/RenderNode.d.ts +10 -25
  171. package/lib/js/scene/RenderNode.js +70 -58
  172. package/lib/js/segment/Segment.js +4 -4
  173. package/lib/js/shaders/depth.js +2 -5
  174. package/lib/js/shaders/drawnode.d.ts +1 -0
  175. package/lib/js/shaders/drawnode.js +51 -52
  176. package/lib/js/shaders/geoObject.d.ts +1 -0
  177. package/lib/js/shaders/geoObject.js +154 -91
  178. package/lib/js/shaders/polyline.js +68 -51
  179. package/lib/js/shaders/utils.d.ts +1 -1
  180. package/lib/js/shaders/utils.js +11 -0
  181. package/lib/js/terrain/GlobusTerrain.js +2 -2
  182. package/lib/js/ui/Checkbox.d.ts +31 -0
  183. package/lib/js/ui/Checkbox.js +110 -0
  184. package/lib/js/ui/Color.js +2 -1
  185. package/lib/js/ui/Dialog.d.ts +3 -0
  186. package/lib/js/ui/Dialog.js +20 -0
  187. package/lib/js/ui/Input.d.ts +32 -0
  188. package/lib/js/ui/Input.js +107 -0
  189. package/lib/js/ui/View.d.ts +3 -1
  190. package/lib/js/ui/View.js +6 -0
  191. package/lib/js/utils/objParser.d.ts +44 -12
  192. package/lib/js/utils/objParser.js +241 -149
  193. package/lib/js/utils/shared.d.ts +22 -0
  194. package/lib/js/utils/shared.js +34 -0
  195. package/lib/js/webgl/BaseFramebuffer.d.ts +0 -1
  196. package/lib/js/webgl/Framebuffer.d.ts +35 -8
  197. package/lib/js/webgl/Framebuffer.js +136 -29
  198. package/lib/js/webgl/Handler.d.ts +22 -12
  199. package/lib/js/webgl/Handler.js +53 -34
  200. package/lib/js/webgl/Program.js +0 -8
  201. package/package.json +5 -3
  202. package/lib/@openglobus/js/control/EarthNavigation.d.ts +0 -50
  203. package/lib/@openglobus/js/control/MouseWheelZoomControl.d.ts +0 -44
  204. package/lib/js/control/EarthNavigation.d.ts +0 -50
  205. package/lib/js/control/EarthNavigation.js +0 -202
@@ -11,24 +11,37 @@ import { PointCloud } from "./PointCloud";
11
11
  import { Polyline } from "./Polyline";
12
12
  import { Ray } from "./Ray";
13
13
  import { Strip } from "./Strip";
14
+ import { Quat } from "../math/Quat";
15
+ import { clamp } from "../math";
14
16
  /**
15
17
  * Entity instances aggregate multiple forms of visualization into a single high-level object.
16
18
  * They can be created manually and added to entity collection.
17
19
  *
18
20
  * @class
19
- * @param {Object} [options] - Entity options:
20
- * @param {string} [options.name] - A human-readable name to display to users. It does not have to be unique.
21
- * @param {Vec3|Array.<number>} [options.cartesian] - Spatial entities like billboard, label etc. cartesian position.
22
- * @param {LonLat} [options.lonlat] - Geodetic coordinates for an entities like billboard, label etc.
23
- * @param {boolean} [options.aground] - True for entities that have to be placed on the relief.
24
- * @param {boolean} [options.visibility] - Entity visibility.
25
- * @param {*} [options.billboard] - Billboard options(see {@link Billboard}).
26
- * @param {*} [options.label] - Label options(see {@link Label}).
27
- * @param {*} [options.polyline] - Polyline options(see {@link Polyline}).
28
- * @param {*} [options.ray] - Ray options(see {@link Ray}).
29
- * @param {*} [options.pointCloud] - Point cloud options(see {@link PointCloud}).
30
- * @param {*} [options.geometry] - Geometry options (see {@link Geometry}), available for vector layer only.
31
- * @param {*} [options.properties] - Entity custom properties.
21
+ * @param {IEntityParams} [options] - Entity options:
22
+ * @param {string} [options.name] - Name of the entity.
23
+ * @param {any} [options.properties] - Additional properties of the entity.
24
+ * @param {Vec3 | NumberArray3} [options.cartesian] - Cartesian position.
25
+ * @param {LonLat | NumberArray3 | NumberArray2} [options.lonlat] - Geographic coordinates.
26
+ * @param {number} [options.altitude] - Altitude.
27
+ * @param {boolean} [options.visibility] - Visibility flag.
28
+ * @param {Billboard | IBillboardParams} [options.billboard] - Billboard object or parameters.
29
+ * @param {Label | ILabelParams} [options.label] - Label object or parameters.
30
+ * @param {Polyline | IPolylineParams} [options.polyline] - Polyline object or parameters.
31
+ * @param {Ray | IRayParams} [options.ray] - Ray object or parameters.
32
+ * @param {PointCloud | IPointCloudParams} [options.pointCloud] - Point cloud object or parameters.
33
+ * @param {Geometry | IGeometryParams} [options.geometry] - Geometry object or parameters.
34
+ * @param {GeoObject | IGeoObjectParams} [options.geoObject] - Geo object or parameters.
35
+ * @param {Strip | IStripParams} [options.strip] - Strip object or parameters.
36
+ * @param {boolean} [options.independentPicking] - Independent picking flag.
37
+ * @param {boolean} [options.relativePosition] - Parent relative position flag, otherwise position is absolute.
38
+ * @param {number} [options.pitch] - Rotation around local X-axis in radians.
39
+ * @param {number} [options.yaw] - Rotation around local Y-axis in radians.
40
+ * @param {number} [options.roll] - Rotation around local Z-axis in radians.
41
+ * @param {number | Vec3 | NumberArray3} [options.scale] - Scaling factor.
42
+ * @param {boolean} [options.forceGlobalPosition] - Forces global position for the entity make the same position as its parent.
43
+ * @param {boolean} [options.forceGlobalRotation] - Forces global rotation for the entity make the same rotation as its parent.
44
+ * @param {boolean} [options.forceGlobalScale] - Forces global scale for the entity make the same scale as its parent.
32
45
  */
33
46
  class Entity {
34
47
  constructor(options = {}) {
@@ -36,9 +49,15 @@ class Entity {
36
49
  this.__id = Entity.__counter__++;
37
50
  this.properties = options.properties || {};
38
51
  this.properties.name = this.properties.name != undefined ? this.properties.name : "";
39
- this.childrenNodes = [];
52
+ this.childEntities = [];
40
53
  this.parent = null;
54
+ this.forceGlobalPosition = options.forceGlobalPosition || false;
55
+ this.forceGlobalRotation = options.forceGlobalRotation || false;
56
+ this.forceGlobalScale = options.forceGlobalScale || false;
41
57
  this._cartesian = utils.createVector3(options.cartesian);
58
+ this._rootCartesian = new Vec3();
59
+ this._localPosition = utils.createVector3(options.localPosition);
60
+ this._absoluteLocalPosition = new Vec3();
42
61
  this._lonLat = utils.createLonLat(options.lonlat);
43
62
  this._lonLatMerc = new LonLat();
44
63
  this._altitude = options.altitude || 0.0;
@@ -49,6 +68,14 @@ class Entity {
49
68
  this._layerIndex = -1;
50
69
  this._pickingColor = new Vec3(0, 0, 0);
51
70
  this._independentPicking = options.independentPicking || false;
71
+ this._relativePosition = options.relativePosition || false;
72
+ this._pitchRad = options.pitch || 0;
73
+ this._yawRad = options.yaw || 0;
74
+ this._rollRad = options.roll || 0;
75
+ this._scale = utils.createVector3(options.scale, new Vec3(1, 1, 1));
76
+ this._qFrame = Quat.IDENTITY;
77
+ this._qRot = Quat.IDENTITY;
78
+ this._absoluteQRot = Quat.IDENTITY;
52
79
  this._featureConstructorArray = {
53
80
  billboard: [Billboard, this.setBillboard],
54
81
  label: [Label, this.setLabel],
@@ -68,15 +95,90 @@ class Entity {
68
95
  this.geoObject = this._createOptionFeature("geoObject", options.geoObject);
69
96
  this.strip = this._createOptionFeature("strip", options.strip);
70
97
  }
98
+ /**
99
+ * Returns root entity object.
100
+ * @public
101
+ * @return {Entity}
102
+ */
103
+ get rootEntity() {
104
+ let pn = this;
105
+ while (pn) {
106
+ if (!pn.parent) {
107
+ return pn;
108
+ }
109
+ pn = pn.parent;
110
+ }
111
+ return this;
112
+ }
113
+ /**
114
+ * Sets relative position property
115
+ * @param isRelative
116
+ */
117
+ set relativePosition(isRelative) {
118
+ if (isRelative !== this._relativePosition) {
119
+ let cart = this.getAbsoluteCartesian(), pitch = this.getAbsolutePitch(), yaw = this.getAbsoluteYaw(), roll = this.getAbsoluteRoll();
120
+ this._relativePosition = isRelative;
121
+ // probably need to take root this.rootEntity
122
+ if (this.parent) {
123
+ this._rootCartesian.copy(this.parent._rootCartesian);
124
+ }
125
+ if (!isRelative) {
126
+ this.setCartesian3v(cart);
127
+ this.setPitch(pitch);
128
+ this.setYaw(yaw);
129
+ this.setRoll(roll);
130
+ }
131
+ else if (this.parent) {
132
+ this.setAbsoluteCartesian3v(cart);
133
+ this.setAbsolutePitch(pitch);
134
+ this.setAbsoluteYaw(yaw);
135
+ this.setAbsoluteRoll(roll);
136
+ }
137
+ }
138
+ }
139
+ /**
140
+ * Gets relative position property
141
+ * @public
142
+ * @returns{boolean}
143
+ */
144
+ get relativePosition() {
145
+ return this._relativePosition;
146
+ }
147
+ /**
148
+ * Gets current entity collection container.
149
+ * @public
150
+ * @returns {EntityCollection | null}
151
+ */
152
+ get entityCollection() {
153
+ return this._entityCollection;
154
+ }
155
+ /**
156
+ * Gets entity uniq id
157
+ * @public
158
+ * @returns {number}
159
+ */
71
160
  get id() {
72
161
  return this.__id;
73
162
  }
163
+ /**
164
+ * Checks if the given entity is equal to the current entity.
165
+ * @param {Entity} entity - The entity to compare.
166
+ * @returns {boolean} True if entities are equal, otherwise false.
167
+ */
74
168
  isEqual(entity) {
75
169
  return this.__id === entity.__id;
76
170
  }
171
+ /**
172
+ * Gets the layer index of the entity.
173
+ * @returns {number} The layer index.
174
+ */
77
175
  get layerIndex() {
78
176
  return this._layerIndex;
79
177
  }
178
+ /**
179
+ * Gets the instance class name of the entity.
180
+ * @returns {string} The instance name "Entity".
181
+ */
80
182
  get instanceName() {
81
183
  return "Entity";
82
184
  }
@@ -87,6 +189,10 @@ class Entity {
87
189
  }
88
190
  return null;
89
191
  }
192
+ /**
193
+ * Gets the collection index of the entity.
194
+ * @returns {number} The entity collection index.
195
+ */
90
196
  getCollectionIndex() {
91
197
  return this._entityCollectionIndex;
92
198
  }
@@ -94,7 +200,7 @@ class Entity {
94
200
  * Adds current entity into the specified entity collection.
95
201
  * @public
96
202
  * @param {EntityCollection | Vector} collection - Specified entity collection or vector layer.
97
- * @param {Boolean} [rightNow=false] - Entity insertion option for vector layer.
203
+ * @param {boolean} [rightNow=false] - Entity insertion option for vector layer.
98
204
  * @returns {Entity} - This object.
99
205
  */
100
206
  addTo(collection, rightNow = false) {
@@ -102,7 +208,7 @@ class Entity {
102
208
  return this;
103
209
  }
104
210
  /**
105
- * Removes current entity from collection and layer.
211
+ * Removes current entity from its collection or layer.
106
212
  * @public
107
213
  */
108
214
  remove() {
@@ -128,8 +234,8 @@ class Entity {
128
234
  this.ray && this.ray.setVisibility(visibility);
129
235
  // geometry
130
236
  this.geometry && this.geometry.setVisibility(visibility);
131
- for (let i = 0; i < this.childrenNodes.length; i++) {
132
- this.childrenNodes[i].setVisibility(visibility);
237
+ for (let i = 0; i < this.childEntities.length; i++) {
238
+ this.childEntities[i].setVisibility(visibility);
133
239
  }
134
240
  }
135
241
  /**
@@ -148,6 +254,287 @@ class Entity {
148
254
  setCartesian3v(cartesian) {
149
255
  this.setCartesian(cartesian.x, cartesian.y, cartesian.z);
150
256
  }
257
+ /**
258
+ * Gets scale factor
259
+ * @public
260
+ * @returns {Vec3}
261
+ */
262
+ getScale() {
263
+ return this._scale;
264
+ }
265
+ /**
266
+ * Sets XYZ axis scale for the inner object such as GeoObject
267
+ * @public
268
+ * @param {Vec3} scale - Scale factor
269
+ */
270
+ setScale3v(scale) {
271
+ this._scale.copy(scale);
272
+ this.geoObject && this.geoObject.setScale3v(this._scale);
273
+ for (let i = 0; i < this.childEntities.length; i++) {
274
+ let chi = this.childEntities[i];
275
+ if (chi.forceGlobalScale) {
276
+ chi.setScale3v(this._scale);
277
+ }
278
+ else {
279
+ chi.setScale3v(this.childEntities[i].getScale());
280
+ }
281
+ }
282
+ }
283
+ /**
284
+ * Sets scale for the inner object such as GeoObject
285
+ * @public
286
+ * @param {number} val - Scale factor
287
+ */
288
+ setScale(val) {
289
+ this._scale.set(val, val, val);
290
+ this.geoObject && this.geoObject.setScale(val);
291
+ for (let i = 0; i < this.childEntities.length; i++) {
292
+ let chi = this.childEntities[i];
293
+ if (chi.forceGlobalScale) {
294
+ chi.setScale(val);
295
+ }
296
+ else {
297
+ chi.setScale3v(this.childEntities[i].getScale());
298
+ }
299
+ }
300
+ }
301
+ /**
302
+ * Gets the absolute rotation direction of the entity.
303
+ * @public
304
+ * @returns {Quat} The absolute rotation quaternion.
305
+ */
306
+ getAbsoluteRotation() {
307
+ return this._absoluteQRot.clone();
308
+ }
309
+ /**
310
+ * Gets the local rotation of the entity. For the root entity it is equal to the absolute rotation.
311
+ * @public
312
+ * @returns {Quat} The rotation quaternion.
313
+ */
314
+ getRotation() {
315
+ return this._qRot;
316
+ }
317
+ /**
318
+ * Rotates the entity to look at a given point in world coordinates.
319
+ * @public
320
+ * @param {Vec3} cart - The target position to look at.
321
+ */
322
+ setLook3v(cart) {
323
+ let lq = new Quat();
324
+ let p0 = this.getAbsoluteCartesian();
325
+ let rot;
326
+ if (this._entityCollection) {
327
+ let up = this._entityCollection.renderNode.ellipsoid.getSurfaceNormal3v(p0);
328
+ rot = lq.setLookRotation(cart.sub(p0), up).conjugate();
329
+ }
330
+ else {
331
+ rot = lq.setLookRotation(cart.sub(p0), Vec3.UP).conjugate();
332
+ }
333
+ this.setAbsoluteRotation(rot);
334
+ }
335
+ /**
336
+ * Rotates the entity to look at a given geographic coordinate.
337
+ * @public
338
+ * @param {LonLat} lonLat - The longitude and latitude to look at.
339
+ */
340
+ setLookLonLat(lonLat) {
341
+ if (this._entityCollection) {
342
+ let cart = this._entityCollection.renderNode.ellipsoid.lonLatToCartesian(lonLat);
343
+ this.setLook3v(cart);
344
+ }
345
+ }
346
+ /**
347
+ * Sets the absolute rotation of the entity.
348
+ * @public
349
+ * @param {Quat} rot - The new absolute rotation quaternion.
350
+ */
351
+ setAbsoluteRotation(rot) {
352
+ this._absoluteQRot.copy(rot);
353
+ this._updatePitchYawRoll();
354
+ }
355
+ /**
356
+ * Sets the local rotation of the entity.
357
+ * @param {Quat} rot - The new rotation quaternion.
358
+ */
359
+ setRotation(rot) {
360
+ //this._qRot.copy(rot);
361
+ //
362
+ //@todo when necessary
363
+ //
364
+ }
365
+ /**
366
+ * Sets the pitch rotation of the entity.
367
+ * @param {number} val - The new pitch angle in radians.
368
+ */
369
+ setPitch(val) {
370
+ this._pitchRad = val;
371
+ this._updateAbsolutePosition();
372
+ }
373
+ /**
374
+ * Sets the yaw rotation of the entity.
375
+ * @param {number} val - The new yaw angle in radians.
376
+ */
377
+ setYaw(val) {
378
+ this._yawRad = val;
379
+ this._updateAbsolutePosition();
380
+ }
381
+ /**
382
+ * Sets the roll rotation of the entity.
383
+ * @public
384
+ * @param {number} val - The new roll angle in radians.
385
+ */
386
+ setRoll(val) {
387
+ this._rollRad = val;
388
+ this._updateAbsolutePosition();
389
+ }
390
+ /**
391
+ * Gets the pitch angle of the entity.
392
+ * @public
393
+ * @returns {number} The pitch angle in radians.
394
+ */
395
+ getPitch() {
396
+ return this._pitchRad;
397
+ }
398
+ /**
399
+ * Gets the yaw angle of the entity.
400
+ * @public
401
+ * @returns {number} The yaw angle in radians.
402
+ */
403
+ getYaw() {
404
+ return this._yawRad;
405
+ }
406
+ /**
407
+ * Gets the roll angle of the entity.
408
+ * @public
409
+ * @returns {number} The roll angle in radians.
410
+ */
411
+ getRoll() {
412
+ return this._rollRad;
413
+ }
414
+ /**
415
+ * Sets the absolute pitch of the entity.
416
+ * @public
417
+ * @param {number} val - The absolute pitch angle in radians.
418
+ */
419
+ setAbsolutePitch(val) {
420
+ if (this._relativePosition) {
421
+ this._absoluteQRot.setPitchYawRoll(val, this.getAbsoluteYaw(), this.getAbsoluteRoll(), this._qFrame);
422
+ this._updatePitchYawRoll();
423
+ }
424
+ else {
425
+ this.setPitch(val);
426
+ }
427
+ }
428
+ /**
429
+ * Sets the absolute yaw of the entity.
430
+ * @public
431
+ * @param {number} val - The absolute yaw angle in radians.
432
+ */
433
+ setAbsoluteYaw(val) {
434
+ if (this._relativePosition) {
435
+ this._absoluteQRot.setPitchYawRoll(this.getAbsolutePitch(), val, this.getAbsoluteRoll(), this._qFrame);
436
+ this._updatePitchYawRoll();
437
+ }
438
+ else {
439
+ this.setYaw(val);
440
+ }
441
+ }
442
+ /**
443
+ * Sets the absolute roll of the entity.
444
+ * @public
445
+ * @param {number} val - The absolute roll angle in radians.
446
+ */
447
+ setAbsoluteRoll(val) {
448
+ if (this._relativePosition) {
449
+ this._absoluteQRot.setPitchYawRoll(this.getAbsolutePitch(), this.getAbsoluteYaw(), val, this._qFrame);
450
+ this._updatePitchYawRoll();
451
+ }
452
+ else {
453
+ this.setRoll(val);
454
+ }
455
+ }
456
+ /**
457
+ * Gets the absolute pitch angle of the entity.
458
+ * @public
459
+ * @returns {number} The absolute pitch angle in radians.
460
+ */
461
+ getAbsolutePitch() {
462
+ if (this.parent && this._relativePosition) {
463
+ return this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getPitch();
464
+ }
465
+ return this._pitchRad;
466
+ }
467
+ /**
468
+ * Gets the absolute yaw angle of the entity.
469
+ * @public
470
+ * @returns {number} The absolute yaw angle in radians.
471
+ */
472
+ getAbsoluteYaw() {
473
+ if (this.parent && this._relativePosition) {
474
+ return this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getYaw();
475
+ }
476
+ return this._yawRad;
477
+ }
478
+ /**
479
+ * Gets the absolute roll angle of the entity.
480
+ * @public
481
+ * @returns {number} The absolute roll angle in radians.
482
+ */
483
+ getAbsoluteRoll() {
484
+ if (this.parent && this._relativePosition) {
485
+ return this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getRoll();
486
+ }
487
+ return this._rollRad;
488
+ }
489
+ _getScaleByDistance() {
490
+ let scd = 1;
491
+ if (this._entityCollection) {
492
+ let scaleByDistance = this._entityCollection.scaleByDistance;
493
+ let lookLength = 1;
494
+ if (this._entityCollection.renderNode && this._entityCollection.renderNode.renderer) {
495
+ lookLength = this._entityCollection.renderNode.renderer.activeCamera.eye.distance(this._rootCartesian);
496
+ }
497
+ //the same in the shader
498
+ scd = scaleByDistance[2] * clamp(lookLength, scaleByDistance[0], scaleByDistance[1]) / scaleByDistance[0];
499
+ }
500
+ return scd;
501
+ }
502
+ /**
503
+ * Sets the absolute cartesian position of the entity.
504
+ * @public
505
+ * @param {number} x - X coordinate.
506
+ * @param {number} y - Y coordinate.
507
+ * @param {number} z - Z coordinate.
508
+ */
509
+ setAbsoluteCartesian(x, y, z) {
510
+ this.setAbsoluteCartesian3v(new Vec3(x, y, z));
511
+ }
512
+ /**
513
+ * Sets the absolute cartesian position of the entity using a Vec3.
514
+ * @public
515
+ * @param {Vec3} absolutCartesian - The absolute cartesian position.
516
+ */
517
+ setAbsoluteCartesian3v(absolutCartesian) {
518
+ let pos = absolutCartesian;
519
+ if (this.parent && this._relativePosition) {
520
+ let scd = this._getScaleByDistance();
521
+ pos = absolutCartesian.sub(this.parent.getAbsoluteCartesian()).scale(1 / scd);
522
+ pos = this.parent._absoluteQRot.conjugate().mulVec3(pos);
523
+ }
524
+ this.setCartesian3v(pos);
525
+ }
526
+ /**
527
+ * Returns absolute cartesian position.
528
+ * @public
529
+ * @returns {Vec3} -
530
+ */
531
+ getAbsoluteCartesian() {
532
+ if (this.parent && this._relativePosition) {
533
+ let scd = this._getScaleByDistance();
534
+ return this._rootCartesian.add(this._absoluteLocalPosition.scaleTo(scd));
535
+ }
536
+ return this._cartesian.clone();
537
+ }
151
538
  /**
152
539
  * Sets entity cartesian position.
153
540
  * @public
@@ -156,30 +543,73 @@ class Entity {
156
543
  * @param {number} z - 3d space Z - position.
157
544
  */
158
545
  setCartesian(x, y, z) {
159
- let p = this._cartesian;
160
- p.x = x || 0.0;
161
- p.y = y || 0.0;
162
- p.z = z || 0.0;
163
- // billboards
164
- this.billboard && this.billboard.setPosition3v(p);
165
- // geoObject
166
- this.geoObject && this.geoObject.setPosition3v(p);
167
- // labels
168
- this.label && this.label.setPosition3v(p);
169
- for (let i = 0; i < this.childrenNodes.length; i++) {
170
- this.childrenNodes[i].setCartesian(x, y, z);
546
+ this._cartesian.set(x, y, z);
547
+ this._updateAbsolutePosition();
548
+ for (let i = 0; i < this.childEntities.length; i++) {
549
+ let chi = this.childEntities[i];
550
+ if (chi._relativePosition) {
551
+ chi.setCartesian3v(chi.getCartesian());
552
+ }
553
+ else if (chi.forceGlobalPosition) {
554
+ chi.setCartesian(x, y, z);
555
+ }
171
556
  }
172
- let ec = this._entityCollection;
173
- if (ec && ec.renderNode && ec.renderNode.ellipsoid) {
174
- this._lonLat = ec.renderNode.ellipsoid.cartesianToLonLat(p);
175
- if (Math.abs(this._lonLat.lat) < mercator.MAX_LAT) {
176
- this._lonLatMerc = this._lonLat.forwardMercator();
557
+ this._updateLonLat();
558
+ //ec && ec.events.dispatch(ec.events.entitymove, this);
559
+ }
560
+ _updatePitchYawRoll() {
561
+ if (this.parent) {
562
+ this._qRot = this.parent._absoluteQRot.conjugate().mul(this._absoluteQRot);
563
+ this._pitchRad = this._qRot.getPitch();
564
+ this._yawRad = this._qRot.getYaw();
565
+ this._rollRad = this._qRot.getRoll();
566
+ // this._pitch = this._pitchRad * DEGREES;
567
+ // this._yaw = this._yawRad * DEGREES;
568
+ // this._roll = this._rollRad * DEGREES;
569
+ if (this.geoObject) {
570
+ this.geoObject.setRotation(this._absoluteQRot);
571
+ }
572
+ for (let i = 0; i < this.childEntities.length; i++) {
573
+ this.childEntities[i]._updateAbsolutePosition();
574
+ }
575
+ }
576
+ }
577
+ _updateAbsolutePosition() {
578
+ let parent = this.parent;
579
+ if (parent && this._relativePosition) {
580
+ this._qFrame.copy(parent._qFrame);
581
+ this._rootCartesian.copy(parent._rootCartesian);
582
+ this._qRot.setPitchYawRoll(this._pitchRad, this._yawRad, this._rollRad);
583
+ parent._absoluteQRot.mulRes(this._qRot, this._absoluteQRot);
584
+ let rotCart = parent._absoluteQRot.mulVec3(this._cartesian.add(this._localPosition));
585
+ parent._absoluteLocalPosition.addRes(rotCart, this._absoluteLocalPosition);
586
+ }
587
+ else {
588
+ this._qFrame = Quat.IDENTITY;
589
+ if (this._entityCollection && this._entityCollection.renderNode) {
590
+ this._qFrame = this._entityCollection.renderNode.getFrameRotation(this._cartesian);
591
+ }
592
+ if (parent && this.forceGlobalRotation) {
593
+ this._qRot.setPitchYawRoll(parent._pitchRad, parent._yawRad, parent._rollRad, this._qFrame);
177
594
  }
178
595
  else {
179
- this._lonLatMerc.lon = this._lonLatMerc.lat = this._lonLatMerc.height = 0;
596
+ this._qRot.setPitchYawRoll(this._pitchRad, this._yawRad, this._rollRad, this._qFrame);
180
597
  }
598
+ this._absoluteQRot.copy(this._qRot);
599
+ this._rootCartesian.copy(this._cartesian);
600
+ this._absoluteLocalPosition.copy(this._localPosition);
181
601
  }
182
- //ec && ec.events.dispatch(ec.events.entitymove, this);
602
+ if (this.geoObject) {
603
+ this.geoObject.setRotation(this._absoluteQRot);
604
+ this.geoObject.setPosition3v(this._rootCartesian);
605
+ this.geoObject.setLocalPosition3v(this._absoluteLocalPosition);
606
+ }
607
+ this.billboard && this.billboard.setPosition3v(this._rootCartesian);
608
+ this.label && this.label.setPosition3v(this._rootCartesian);
609
+ for (let i = 0, len = this.childEntities.length; i < len; i++) {
610
+ this.childEntities[i]._updateAbsolutePosition();
611
+ }
612
+ this._updateLonLat();
183
613
  }
184
614
  /**
185
615
  * Sets entity cartesian position without event dispatching.
@@ -188,27 +618,25 @@ class Entity {
188
618
  * @param {boolean} skipLonLat - skip geodetic calculation.
189
619
  */
190
620
  _setCartesian3vSilent(cartesian, skipLonLat = false) {
191
- let p = this._cartesian;
192
- p.x = cartesian.x || 0.0;
193
- p.y = cartesian.y || 0.0;
194
- p.z = cartesian.z || 0.0;
195
- // billboards
196
- this.billboard && this.billboard.setPosition3v(p);
197
- // geoObject
198
- this.geoObject && this.geoObject.setPosition3v(p);
199
- // labels
200
- this.label && this.label.setPosition3v(p);
201
- for (let i = 0; i < this.childrenNodes.length; i++) {
202
- this.childrenNodes[i].setCartesian(p.x, p.y, p.z);
621
+ this._cartesian.copy(cartesian);
622
+ this._updateAbsolutePosition();
623
+ for (let i = 0; i < this.childEntities.length; i++) {
624
+ this.childEntities[i].setCartesian(this._cartesian.x, this._cartesian.y, this._cartesian.z);
625
+ }
626
+ if (!skipLonLat) {
627
+ this._updateLonLat();
203
628
  }
629
+ }
630
+ _updateLonLat() {
204
631
  let ec = this._entityCollection;
205
- if (!skipLonLat && ec && ec.renderNode && ec.renderNode.ellipsoid) {
206
- this._lonLat = ec.renderNode.ellipsoid.cartesianToLonLat(p);
632
+ if (ec && ec.renderNode && ec.renderNode.ellipsoid) {
633
+ //let cart = this._rootCartesian.add(this._absoluteLocalPosition);
634
+ this._lonLat = ec.renderNode.ellipsoid.cartesianToLonLat(this.getAbsoluteCartesian());
207
635
  if (Math.abs(this._lonLat.lat) < mercator.MAX_LAT) {
208
636
  this._lonLatMerc = this._lonLat.forwardMercator();
209
637
  }
210
638
  else {
211
- //this._lonLatMerc = null;
639
+ this._lonLatMerc.lon = this._lonLatMerc.lat = 0;
212
640
  }
213
641
  }
214
642
  }
@@ -223,7 +651,7 @@ class Entity {
223
651
  /**
224
652
  * Sets geodetic coordinates of the entity point object.
225
653
  * @public
226
- * @param {LonLat} lonlat - WGS84 coordinates.
654
+ * @param {LonLat} lonlat - coordinates.
227
655
  */
228
656
  setLonLat(lonlat) {
229
657
  let l = this._lonLat;
@@ -238,8 +666,9 @@ class Entity {
238
666
  else {
239
667
  //this._lonLatMerc = null;
240
668
  }
241
- ec.renderNode.ellipsoid.lonLatToCartesianRes(l, this._cartesian);
242
- this.setCartesian3v(this._cartesian);
669
+ let temp = new Vec3();
670
+ ec.renderNode.ellipsoid.lonLatToCartesianRes(l, temp);
671
+ this.setAbsoluteCartesian3v(temp);
243
672
  }
244
673
  }
245
674
  /**
@@ -262,8 +691,9 @@ class Entity {
262
691
  else {
263
692
  this._lonLatMerc.lon = this._lonLatMerc.lat = this._lonLatMerc.height = 0;
264
693
  }
265
- ec.renderNode.ellipsoid.lonLatToCartesianRes(l, this._cartesian);
266
- this.setCartesian3v(this._cartesian);
694
+ let temp = new Vec3();
695
+ ec.renderNode.ellipsoid.lonLatToCartesianRes(l, temp);
696
+ this.setAbsoluteCartesian3v(temp);
267
697
  }
268
698
  }
269
699
  /**
@@ -425,6 +855,11 @@ class Entity {
425
855
  this._entityCollection && this._entityCollection.stripHandler.add(strip);
426
856
  return strip;
427
857
  }
858
+ /**
859
+ * Gets layer container
860
+ * @public
861
+ * @returns {Vector | null}
862
+ */
428
863
  get layer() {
429
864
  return this._layer;
430
865
  }
@@ -448,7 +883,7 @@ class Entity {
448
883
  entity._pickingColor = this._pickingColor;
449
884
  }
450
885
  entity.parent = this;
451
- this.childrenNodes.push(entity);
886
+ this.childEntities.push(entity);
452
887
  this._entityCollection && this._entityCollection.appendChildEntity(entity);
453
888
  }
454
889
  /**
@@ -463,8 +898,8 @@ class Entity {
463
898
  this.ray && this.ray.setPickingColor3v(c);
464
899
  this.strip && this.strip.setPickingColor3v(c);
465
900
  this.geoObject && this.geoObject.setPickingColor3v(c);
466
- for (let i = 0; i < this.childrenNodes.length; i++) {
467
- this.childrenNodes[i].setPickingColor();
901
+ for (let i = 0; i < this.childEntities.length; i++) {
902
+ this.childEntities[i].setPickingColor();
468
903
  }
469
904
  }
470
905
  /**
@@ -504,8 +939,8 @@ class Entity {
504
939
  if (e.northEast.lat > ne.lat)
505
940
  ne.lat = e.northEast.lat;
506
941
  }
507
- for (let i = 0; i < this.childrenNodes.length; i++) {
508
- let e = this.childrenNodes[i].getExtent();
942
+ for (let i = 0; i < this.childEntities.length; i++) {
943
+ let e = this.childEntities[i].getExtent();
509
944
  if (e.southWest.lon < sw.lon)
510
945
  sw.lon = e.southWest.lon;
511
946
  if (e.southWest.lat < sw.lat)