@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
package/src/og/Globe.js CHANGED
@@ -13,6 +13,7 @@ import { isEmpty } from "./utils/shared.js";
13
13
 
14
14
  import { EarthCoordinates } from "./control/EarthCoordinates.js";
15
15
  import { MouseNavigation } from "./control/MouseNavigation.js";
16
+ import { EarthNavigation } from "./control/EarthNavigation.js";
16
17
  import { TouchNavigation } from "./control/TouchNavigation.js";
17
18
  import { Sun } from "./control/Sun.js";
18
19
  import { ZoomControl } from "./control/ZoomControl.js";
@@ -81,7 +82,8 @@ class Globe {
81
82
  * @public
82
83
  * @type {Element}
83
84
  */
84
- this.div = document.getElementById(options.target);
85
+ this.div =
86
+ document.getElementById(options.target) || document.querySelector(options.target);
85
87
  this.div.appendChild(this._canvas);
86
88
  this.div.classList.add("ogViewport");
87
89
 
@@ -151,7 +153,9 @@ class Globe {
151
153
  ellipsoid: options.ellipsoid,
152
154
  maxGridSize: options.maxGridSize,
153
155
  useNightTexture: options.useNightTexture,
154
- useSpecularTexture: options.useSpecularTexture
156
+ useSpecularTexture: options.useSpecularTexture,
157
+ minAltitude: options.minAltitude,
158
+ maxAltitude: options.maxAltitude
155
159
  });
156
160
  }
157
161
 
@@ -170,7 +174,11 @@ class Globe {
170
174
  } else {
171
175
  this.planet.addControls([
172
176
  new ZoomControl(),
173
- new MouseNavigation(),
177
+ options.useEarthNavigation
178
+ ? new EarthNavigation()
179
+ : new MouseNavigation({
180
+ minSlope: options.minSlope
181
+ }),
174
182
  new TouchNavigation(),
175
183
  new EarthCoordinates(),
176
184
  new ScaleControl(),
package/src/og/LonLat.js CHANGED
@@ -19,166 +19,172 @@ const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;
19
19
  * @param {number} [lat] - Latitude.
20
20
  * @param {number} [height] - Height over the surface.
21
21
  */
22
- const LonLat = function (lon, lat, height) {
22
+ export class LonLat {
23
23
 
24
24
  /**
25
- * Longitude.
26
- * @public
27
- * @type {number}
25
+ * @param {number} [lon]
26
+ * @param {number} [lat]
27
+ * @param {number} [height]
28
28
  */
29
- this.lon = lon || 0;
29
+ constructor(lon, lat, height) {
30
+
31
+ /**
32
+ * Longitude.
33
+ * @public
34
+ * @type {number}
35
+ */
36
+ this.lon = lon || 0;
37
+
38
+ /**
39
+ * Latitude.
40
+ * @public
41
+ * @type {number}
42
+ */
43
+ this.lat = lat || 0;
44
+
45
+ /**
46
+ * Height.
47
+ * @public
48
+ * @type {number}
49
+ */
50
+ this.height = height || 0;
51
+ };
52
+
53
+ isZero() {
54
+ return this.lon === 0.0 && this.lat === 0.0 && this.height === 0.0;
55
+ };
30
56
 
31
57
  /**
32
- * Latitude.
33
- * @public
34
- * @type {number}
58
+ * Creates coordinates array.
59
+ * @static
60
+ * @param{Array.<Array<number>>} arr - Coordinates array data. (exactly 3 entries)
61
+ * @return{Array.<og.LonLat>} the same coordinates array but each element is LonLat instance.
35
62
  */
36
- this.lat = lat || 0;
63
+ static join(arr) {
64
+ var res = [];
65
+ for (var i = 0; i < arr.length; i++) {
66
+ var ai = arr[i];
67
+ res[i] = new LonLat(ai[0], ai[1], ai[2]);
68
+ }
69
+ return res;
70
+ };
37
71
 
38
72
  /**
39
- * Height.
40
- * @public
41
- * @type {number}
73
+ * Creates an object by coordinate array.
74
+ * @static
75
+ * @param {Array.<number>} arr - Coordiante array, where first is longitude, second is latitude and third is a height. (exactly 3 entries)
76
+ * @returns {og.LonLat} -
42
77
  */
43
- this.height = height || 0;
44
- };
45
-
46
- LonLat.prototype.isZero = function () {
47
- return this.lon === 0.0 && this.lat === 0.0 && this.height === 0.0;
48
- };
49
-
50
- /**
51
- * Creates coordinates array.
52
- * @static
53
- * @param{Array.<Array<number,number,number>>} arr - Coordinates array data.
54
- * @return{Array.<og.LonLat>} the same coordinates array but each element is LonLat instance.
55
- */
56
- LonLat.join = function (arr) {
57
- var res = [];
58
- for (var i = 0; i < arr.length; i++) {
59
- var ai = arr[i];
60
- res[i] = new LonLat(ai[0], ai[1], ai[2]);
61
- }
62
- return res;
63
- };
78
+ static createFromArray(arr) {
79
+ return new LonLat(arr[0], arr[1], arr[2]);
80
+ };
64
81
 
65
- /**
66
- * Creates an object by coordinate array.
67
- * @static
68
- * @param {Array.<number,number,number>} arr - Coordiante array, where first is longitude, second is latitude and third is a height.
69
- * @returns {og.LonLat} -
70
- */
71
- LonLat.createFromArray = function (arr) {
72
- return new LonLat(arr[0], arr[1], arr[2]);
73
- };
74
-
75
- /**
76
- * Converts degrees to mercator coordinates.
77
- * @static
78
- * @param {number} lon - Degrees longitude.
79
- * @param {number} lat - Degrees latitude.
80
- * @param {number} [height] - Height.
81
- * @returns {og.LonLat} -
82
- */
83
- LonLat.forwardMercator = function (lon, lat, height) {
84
- return new LonLat(lon * mercator.POLE_BY_180,
85
- Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI,
86
- height);
87
- };
82
+ /**
83
+ * Converts degrees to mercator coordinates.
84
+ * @static
85
+ * @param {number} lon - Degrees longitude.
86
+ * @param {number} lat - Degrees latitude.
87
+ * @param {number} [height] - Height.
88
+ * @returns {og.LonLat} -
89
+ */
90
+ static forwardMercator(lon, lat, height) {
91
+ return new LonLat(lon * mercator.POLE_BY_180,
92
+ Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI,
93
+ height);
94
+ };
88
95
 
89
- /**
90
- * Converts mercator to degrees coordinates.
91
- * @static
92
- * @param {number} x - Mercator longitude.
93
- * @param {number} y - Mercator latitude.
94
- * @param {number} [height] - Height.
95
- * @returns {og.LonLat} -
96
- */
97
- LonLat.inverseMercator = function (x, y, height) {
98
- return new LonLat(x * mercator.INV_POLE_BY_180,
99
- INV_PI_BY_360 * Math.atan(Math.exp(y * mercator.PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,
100
- height);
101
- };
96
+ /**
97
+ * Converts mercator to degrees coordinates.
98
+ * @static
99
+ * @param {number} x - Mercator longitude.
100
+ * @param {number} y - Mercator latitude.
101
+ * @param {number} [height] - Height.
102
+ * @returns {og.LonLat} -
103
+ */
104
+ static inverseMercator(x, y, height) {
105
+ return new LonLat(x * mercator.INV_POLE_BY_180,
106
+ INV_PI_BY_360 * Math.atan(Math.exp(y * mercator.PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,
107
+ height);
108
+ };
102
109
 
103
- /**
104
- * Sets coordinates.
105
- * @public
106
- * @param {number} [lon] - Longitude.
107
- * @param {number} [lat] - Latitude.
108
- * @param {number} [height] - Height.
109
- * @returns {og.LonLat} -
110
- */
111
- LonLat.prototype.set = function (lon, lat, height) {
112
- this.lon = lon || 0;
113
- this.lat = lat || 0;
114
- this.height = height || 0;
115
- return this;
116
- };
110
+ /**
111
+ * Sets coordinates.
112
+ * @public
113
+ * @param {number} [lon] - Longitude.
114
+ * @param {number} [lat] - Latitude.
115
+ * @param {number} [height] - Height.
116
+ * @returns {og.LonLat} -
117
+ */
118
+ set(lon, lat, height) {
119
+ this.lon = lon || 0;
120
+ this.lat = lat || 0;
121
+ this.height = height || 0;
122
+ return this;
123
+ };
117
124
 
118
- /**
119
- * Copy coordinates.
120
- * @public
121
- * @param {og.LonLat} [lonLat] - Coordinates to copy.
122
- * @returns {og.LonLat} -
123
- */
124
- LonLat.prototype.copy = function (lonLat) {
125
- this.lon = lonLat.lon;
126
- this.lat = lonLat.lat;
127
- this.height = lonLat.height;
128
- return this;
129
- };
125
+ /**
126
+ * Copy coordinates.
127
+ * @public
128
+ * @param {og.LonLat} [lonLat] - Coordinates to copy.
129
+ * @returns {og.LonLat} -
130
+ */
131
+ copy(lonLat) {
132
+ this.lon = lonLat.lon;
133
+ this.lat = lonLat.lat;
134
+ this.height = lonLat.height;
135
+ return this;
136
+ };
130
137
 
131
- /**
132
- * Clone the coordiante.
133
- * @public
134
- * @returns {og.LonLat} -
135
- */
136
- LonLat.prototype.clone = function () {
137
- return new LonLat(this.lon, this.lat, this.height);
138
- };
138
+ /**
139
+ * Clone the coordiante.
140
+ * @public
141
+ * @returns {og.LonLat} -
142
+ */
143
+ clone() {
144
+ return new LonLat(this.lon, this.lat, this.height);
145
+ };
139
146
 
140
- /**
141
- * Converts to mercator coordinates.
142
- * @public
143
- * @returns {og.LonLat} -
144
- */
145
- LonLat.prototype.forwardMercator = function () {
146
- return LonLat.forwardMercator(this.lon, this.lat, this.height);
147
- };
148
-
149
- LonLat.prototype.forwardMercatorEPS01 = function () {
150
- var lat = this.lat;
151
- if (lat > 89.9) {
152
- lat = 89.9;
153
- } else if (lat < -89.9) {
154
- lat = -89.9;
155
- }
156
- return new LonLat(
157
- this.lon * mercator.POLE_BY_180,
158
- Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI);
159
- };
147
+ /**
148
+ * Converts to mercator coordinates.
149
+ * @public
150
+ * @returns {og.LonLat} -
151
+ */
152
+ forwardMercator() {
153
+ return LonLat.forwardMercator(this.lon, this.lat, this.height);
154
+ };
155
+
156
+ forwardMercatorEPS01() {
157
+ var lat = this.lat;
158
+ if (lat > 89.9) {
159
+ lat = 89.9;
160
+ } else if (lat < -89.9) {
161
+ lat = -89.9;
162
+ }
163
+ return new LonLat(
164
+ this.lon * mercator.POLE_BY_180,
165
+ Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI);
166
+ };
160
167
 
161
- /**
162
- * Converts from mercator coordinates.
163
- * @public
164
- * @returns {og.LonLat} -
165
- */
166
- LonLat.prototype.inverseMercator = function () {
167
- return LonLat.inverseMercator(this.lon, this.lat, this.height);
168
- };
168
+ /**
169
+ * Converts from mercator coordinates.
170
+ * @public
171
+ * @returns {og.LonLat} -
172
+ */
173
+ inverseMercator() {
174
+ return LonLat.inverseMercator(this.lon, this.lat, this.height);
175
+ };
169
176
 
170
- /**
171
- * Compares coordinates.
172
- * @public
173
- * @param {og.LonLat} b - Coordinate to compare with.
174
- * @returns {boolean} -
175
- */
176
- LonLat.prototype.equal = function (b) {
177
- if (b.height) {
178
- return this.lon === b.lon && this.lat === b.lat && this.height === b.height;
179
- } else {
180
- return this.lon === b.lon && this.lat === b.lat;
181
- }
182
- };
183
-
184
- export { LonLat };
177
+ /**
178
+ * Compares coordinates.
179
+ * @public
180
+ * @param {og.LonLat} b - Coordinate to compare with.
181
+ * @returns {boolean} -
182
+ */
183
+ equal(b) {
184
+ if (b.height) {
185
+ return this.lon === b.lon && this.lat === b.lat && this.height === b.height;
186
+ } else {
187
+ return this.lon === b.lon && this.lat === b.lat;
188
+ }
189
+ };
190
+ }
package/src/og/Popup.js CHANGED
@@ -72,7 +72,7 @@ class Popup {
72
72
 
73
73
  setScreen(p) {
74
74
  if (this._planet) {
75
- this.el.style.transform = "translate(" + (p.x - this.clientWidth * 0.5) + "px, " + (p.y - this._planet.renderer.handler.canvas.height - this.clientHeight * 0.5) + "px)"
75
+ this.el.style.transform = "translate(" + (p.x - this.clientWidth * 0.5) + "px, " + (p.y - this._planet.renderer.handler.canvas.height - this._tipEl.clientHeight) + "px)"
76
76
  }
77
77
  }
78
78
 
@@ -98,6 +98,7 @@ class Popup {
98
98
  this.el = this._renderTemplate(params);
99
99
  this._contentEl = this.el.querySelector(".og-popup-content");
100
100
  this._titleEl = this.el.querySelector(".og-popup-title")
101
+ this._tipEl = this.el.querySelector(".og-popup-tip-container")
101
102
  this.setOffset(this._offset[0], this._offset[1]);
102
103
  this.setContent(this._content);
103
104
  this.setTitle(this._title);
@@ -2,17 +2,17 @@
2
2
  * @module og/camera/PlanetCamera
3
3
  */
4
4
 
5
- 'use strict';
6
-
7
- import * as math from '../math.js';
8
- import * as mercator from '../mercator.js';
9
- import { Camera } from './Camera.js';
10
- import { Vec3 } from '../math/Vec3.js';
11
- import { Key } from '../Lock.js';
12
- import { LonLat } from '../LonLat.js';
13
- import { Ray } from '../math/Ray.js';
14
- import { Quat } from '../math/Quat.js';
15
- import { Mat4 } from '../math/Mat4.js';
5
+ "use strict";
6
+
7
+ import * as math from "../math.js";
8
+ import * as mercator from "../mercator.js";
9
+ import { Camera } from "./Camera.js";
10
+ import { Vec3 } from "../math/Vec3.js";
11
+ import { Key } from "../Lock.js";
12
+ import { LonLat } from "../LonLat.js";
13
+ import { Ray } from "../math/Ray.js";
14
+ import { Quat } from "../math/Quat.js";
15
+ import { Mat4 } from "../math/Mat4.js";
16
16
 
17
17
  /**
18
18
  * Planet camera.
@@ -24,17 +24,28 @@ import { Mat4 } from '../math/Mat4.js';
24
24
  * @param {number} [options.viewAngle=37] - Camera angle of view. Default is 35.0
25
25
  * @param {number} [options.near] - Camera near plane distance. Default is 1.0
26
26
  * @param {number} [options.far] - Camera far plane distance. Deafult is og.math.MAX
27
- * @param {number} [options.minAltitude] - Minimal altitude for the camera. Deafult is 50
27
+ * @param {number} [options.minAltitude] - Minimal altitude for the camera. Deafult is 1
28
+ * @param {number} [options.maxAltitude] - Maximal altitude for the camera. Deafult is 20000000
28
29
  * @param {og.Vec3} [options.eye] - Camera eye position. Default (0,0,0)
29
30
  * @param {og.Vec3} [options.look] - Camera look position. Default (0,0,0)
30
31
  * @param {og.Vec3} [options.up] - Camera eye position. Default (0,1,0)
31
32
  */
32
33
  class PlanetCamera extends Camera {
33
34
  constructor(planet, options) {
34
- super(planet.renderer,
35
- Object.assign({}, {
36
- frustums: /*[[100, 10000000]]*/[[1, 100 + 0.075], [100, 1000 + 0.075], [1000, 1e6 + 10000], [1e6, 1e9]] //[[1, 1e3 + 100], [1e3, 1e6 + 10000], [1e6, 1e9]]*/
37
- }, options)
35
+ super(
36
+ planet.renderer,
37
+ Object.assign(
38
+ {},
39
+ {
40
+ frustums: /*[[100, 10000000]]*/ [
41
+ [1, 100 + 0.075],
42
+ [100, 1000 + 0.075],
43
+ [1000, 1e6 + 10000],
44
+ [1e6, 1e9]
45
+ ] //[[1, 1e3 + 100], [1e3, 1e6 + 10000], [1e6, 1e9]]*/
46
+ },
47
+ options
48
+ )
38
49
  );
39
50
  /**
40
51
  * Assigned camera's planet.
@@ -50,6 +61,13 @@ class PlanetCamera extends Camera {
50
61
  */
51
62
  this.minAltitude = options.minAltitude || 1;
52
63
 
64
+ /**
65
+ * Maximal alltitude that camera can reach over the globe.
66
+ * @public
67
+ * @type {number}
68
+ */
69
+ this.maxAltitude = options.maxAltitude || 20000000;
70
+
53
71
  /**
54
72
  * Current geographical degree position.
55
73
  * @protected
@@ -112,6 +130,13 @@ class PlanetCamera extends Camera {
112
130
  */
113
131
  update() {
114
132
  this.events.stopPropagation();
133
+
134
+ let maxAlt = this.maxAltitude + this.planet.ellipsoid._a;
135
+
136
+ if (this.eye.length() > maxAlt) {
137
+ this.eye.copy(this.eye.normal().scale(maxAlt));
138
+ }
139
+
115
140
  super.update();
116
141
  this.updateGeodeticPosition();
117
142
  this.eyeNorm = this.eye.normal();
@@ -191,7 +216,6 @@ class PlanetCamera extends Camera {
191
216
  * @returns {og.Vec3}
192
217
  */
193
218
  getExtentPosition(extent, height) {
194
-
195
219
  var north = extent.getNorth();
196
220
  var south = extent.getSouth();
197
221
  var east = extent.getEast();
@@ -273,10 +297,18 @@ class PlanetCamera extends Camera {
273
297
  * @param {Number} [ampl] - Altitude amplitude factor.
274
298
  * @param {cameraCallback} [completeCallback] - Callback that calls after flying when flying is finished.
275
299
  * @param {cameraCallback} [startCallback] - Callback that calls befor the flying begins.
300
+ * @param [frameCallback]
276
301
  */
277
302
  flyExtent(extent, height, up, ampl, completeCallback, startCallback, frameCallback) {
278
- this.flyCartesian(this.getExtentPosition(extent, height), Vec3.ZERO,
279
- up, ampl, completeCallback, startCallback, frameCallback);
303
+ this.flyCartesian(
304
+ this.getExtentPosition(extent, height),
305
+ Vec3.ZERO,
306
+ up,
307
+ ampl,
308
+ completeCallback,
309
+ startCallback,
310
+ frameCallback
311
+ );
280
312
  }
281
313
 
282
314
  viewDistance(cartesian, distance = 10000.0) {
@@ -293,7 +325,14 @@ class PlanetCamera extends Camera {
293
325
  this.update();
294
326
  }
295
327
 
296
- flyDistance(cartesian, distance = 10000.0, ampl = 0.0, completeCallback, startCallback, frameCallback) {
328
+ flyDistance(
329
+ cartesian,
330
+ distance = 10000.0,
331
+ ampl = 0.0,
332
+ completeCallback,
333
+ startCallback,
334
+ frameCallback
335
+ ) {
297
336
  let p0 = this.eye.add(this.getForward().scaleTo(distance));
298
337
  let _rot = Quat.getRotationBetweenVectors(p0.normal(), cartesian.normal());
299
338
  if (_rot.isZero()) {
@@ -302,7 +341,15 @@ class PlanetCamera extends Camera {
302
341
  } else {
303
342
  let newPos = cartesian.add(_rot.mulVec3(this.getBackward()).scale(distance)),
304
343
  newUp = _rot.mulVec3(this.getUp());
305
- this.flyCartesian(newPos, cartesian, newUp, ampl, completeCallback, startCallback, frameCallback);
344
+ this.flyCartesian(
345
+ newPos,
346
+ cartesian,
347
+ newUp,
348
+ ampl,
349
+ completeCallback,
350
+ startCallback,
351
+ frameCallback
352
+ );
306
353
  }
307
354
  }
308
355
 
@@ -315,9 +362,9 @@ class PlanetCamera extends Camera {
315
362
  * @param {Number} [ampl=1.0] - Altitude amplitude factor.
316
363
  * @param {cameraCallback} [completeCallback] - Callback that calls after flying when flying is finished.
317
364
  * @param {cameraCallback} [startCallback] - Callback that calls befor the flying begins.
365
+ * @param [frameCallback]
318
366
  */
319
367
  flyCartesian(cartesian, look, up, ampl = 1.0, completeCallback, startCallback, frameCallback) {
320
-
321
368
  this.stopFlying();
322
369
 
323
370
  this._completeCallback = completeCallback;
@@ -333,13 +380,17 @@ class PlanetCamera extends Camera {
333
380
  look = this.planet.ellipsoid.lonLatToCartesian(look);
334
381
  }
335
382
 
336
- var ground_a = this.planet.ellipsoid.lonLatToCartesian(new LonLat(this._lonLat.lon, this._lonLat.lat));
383
+ var ground_a = this.planet.ellipsoid.lonLatToCartesian(
384
+ new LonLat(this._lonLat.lon, this._lonLat.lat)
385
+ );
337
386
  var v_a = this._v,
338
387
  n_a = this._n;
339
388
 
340
389
  var lonlat_b = this.planet.ellipsoid.cartesianToLonLat(cartesian);
341
390
  var up_b = up || Vec3.UP;
342
- var ground_b = this.planet.ellipsoid.lonLatToCartesian(new LonLat(lonlat_b.lon, lonlat_b.lat, 0));
391
+ var ground_b = this.planet.ellipsoid.lonLatToCartesian(
392
+ new LonLat(lonlat_b.lon, lonlat_b.lat, 0)
393
+ );
343
394
  var eye_b = cartesian;
344
395
  var n_b = Vec3.sub(eye_b, look);
345
396
  var u_b = up_b.cross(n_b);
@@ -350,7 +401,7 @@ class PlanetCamera extends Camera {
350
401
  var an = ground_a.normal();
351
402
  var bn = ground_b.normal();
352
403
  var anbn = 1.0 - an.dot(bn);
353
- var hM_a = ampl * math.SQRT_HALF * Math.sqrt((anbn) > 0.0 ? anbn : 0.0);
404
+ var hM_a = ampl * math.SQRT_HALF * Math.sqrt(anbn > 0.0 ? anbn : 0.0);
354
405
 
355
406
  var maxHeight = 6639613;
356
407
  var currMaxHeight = Math.max(this._lonLat.height, lonlat_b.height);
@@ -370,7 +421,11 @@ class PlanetCamera extends Camera {
370
421
  var g_i = ground_a.smerp(ground_b, d).normalize();
371
422
  var ground_i = this.planet.getRayIntersectionEllipsoid(new Ray(zero, g_i));
372
423
  var t = 1 - d;
373
- var height_i = this._lonLat.height * d * d * d + max_h * 3 * d * d * t + max_h * 3 * d * t * t + lonlat_b.height * t * t * t;
424
+ var height_i =
425
+ this._lonLat.height * d * d * d +
426
+ max_h * 3 * d * d * t +
427
+ max_h * 3 * d * t * t +
428
+ lonlat_b.height * t * t * t;
374
429
 
375
430
  var eye_i = ground_i.addA(g_i.scale(height_i));
376
431
  var up_i = v_a.smerp(v_b, d);
@@ -406,7 +461,14 @@ class PlanetCamera extends Camera {
406
461
  */
407
462
  flyLonLat(lonlat, look, up, ampl, completeCallback, startCallback) {
408
463
  var _lonlat = new LonLat(lonlat.lon, lonlat.lat, lonlat.height || this._lonLat.height);
409
- this.flyCartesian(this.planet.ellipsoid.lonLatToCartesian(_lonlat), look, up, ampl, completeCallback, startCallback);
464
+ this.flyCartesian(
465
+ this.planet.ellipsoid.lonLatToCartesian(_lonlat),
466
+ look,
467
+ up,
468
+ ampl,
469
+ completeCallback,
470
+ startCallback
471
+ );
410
472
  }
411
473
 
412
474
  /**
@@ -414,7 +476,6 @@ class PlanetCamera extends Camera {
414
476
  * @public
415
477
  */
416
478
  stopFlying() {
417
-
418
479
  this.planet.layerLock.free(this._keyLock);
419
480
  this.planet.terrainLock.free(this._keyLock);
420
481
  this.planet._normalMapCreator.free(this._keyLock);
@@ -477,7 +538,7 @@ class PlanetCamera extends Camera {
477
538
  this.update();
478
539
  }
479
540
 
480
- rotateVertical(angle, center, isLimited) {
541
+ rotateVertical(angle, center, minSlope = 0) {
481
542
  var rot = new Mat4().setRotation(this._u, angle);
482
543
  var tr = new Mat4().setIdentity().translate(center);
483
544
  var ntr = new Mat4().setIdentity().translate(center.negateTo());
@@ -491,9 +552,16 @@ class PlanetCamera extends Camera {
491
552
  let eyeNorm = eye.normal();
492
553
  let slope = n.dot(eyeNorm);
493
554
 
494
- if (isLimited) {
495
- if (slope > 0.1 && v.dot(eyeNorm) > 0 ||
496
- this.slope <= 0.1 || this._v.dot(this.eye.normal()) <= 0.0) {
555
+ if (minSlope) {
556
+ let dSlope = slope - this.slope;
557
+
558
+ if (slope < minSlope && dSlope < 0) return;
559
+
560
+ if (
561
+ (slope > 0.1 && v.dot(eyeNorm) > 0) ||
562
+ this.slope <= 0.1 ||
563
+ this._v.dot(this.eye.normal()) <= 0.0
564
+ ) {
497
565
  this.eye = eye;
498
566
  this._v = v;
499
567
  this._u = u;
@@ -544,8 +612,12 @@ class PlanetCamera extends Camera {
544
612
 
545
613
  checkTerrainCollision() {
546
614
  this._terrainAltitude = this._lonLat.height;
547
- if (this._lonLat.height < 1000000 && this._insideSegment && this._insideSegment.planet) {
548
- this._terrainAltitude = this._insideSegment.getTerrainPoint(this.eye, this._insideSegmentPosition, this._terrainPoint);
615
+ if (this._insideSegment && this._insideSegment.planet) {
616
+ this._terrainAltitude = this._insideSegment.getTerrainPoint(
617
+ this.eye,
618
+ this._insideSegmentPosition,
619
+ this._terrainPoint
620
+ );
549
621
  if (this._terrainAltitude < this.minAltitude) {
550
622
  this.setAltitude(this.minAltitude);
551
623
  }
@@ -559,7 +631,10 @@ class PlanetCamera extends Camera {
559
631
 
560
632
  getHeading() {
561
633
  let u = this.eye.normal();
562
- let f = Vec3.proj_b_to_plane(this.slope >= 0.97 ? this.getUp() : this.getForward(), u).normalize(),
634
+ let f = Vec3.proj_b_to_plane(
635
+ this.slope >= 0.97 ? this.getUp() : this.getForward(),
636
+ u
637
+ ).normalize(),
563
638
  n = Vec3.proj_b_to_plane(Vec3.UP, u).normalize();
564
639
  let res = Math.sign(u.dot(f.cross(n))) * Math.acos(f.dot(n)) * math.DEGREES;
565
640
  if (res < 0.0) {
@@ -567,7 +642,6 @@ class PlanetCamera extends Camera {
567
642
  }
568
643
  return res;
569
644
  }
645
+ }
570
646
 
571
- };
572
-
573
- export { PlanetCamera };
647
+ export { PlanetCamera };