itowns 2.34.0 → 2.36.2

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 (68) hide show
  1. package/CONTRIBUTORS.md +1 -0
  2. package/changelog.md +150 -0
  3. package/dist/debug.js +2 -16
  4. package/dist/debug.js.LICENSE.txt +6 -0
  5. package/dist/debug.js.map +1 -1
  6. package/dist/itowns.js +2 -19
  7. package/dist/itowns.js.LICENSE.txt +28 -0
  8. package/dist/itowns.js.map +1 -1
  9. package/examples/3dtiles_basic.html +2 -2
  10. package/examples/config.json +2 -1
  11. package/examples/js/plugins/CSVnVRTParser.js +0 -1
  12. package/examples/layers/JSONLayers/Administrative.json +1 -1
  13. package/examples/layers/JSONLayers/Cada.json +1 -1
  14. package/examples/layers/JSONLayers/EtatMajor.json +1 -1
  15. package/examples/layers/JSONLayers/IGN_MNT.json +1 -1
  16. package/examples/layers/JSONLayers/IGN_MNT_HIGHRES.json +1 -1
  17. package/examples/layers/JSONLayers/Ortho.json +1 -1
  18. package/examples/layers/JSONLayers/WORLD_DTM.json +1 -1
  19. package/examples/misc_camera_traveling.html +148 -0
  20. package/examples/misc_custom_label.html +0 -2
  21. package/examples/plugins_vrt.html +0 -1
  22. package/examples/source_file_geojson_raster.html +0 -3
  23. package/examples/source_file_shapefile.html +0 -1
  24. package/examples/source_stream_wfs_25d.html +8 -16
  25. package/examples/vector_tile_raster_2d.html +2 -2
  26. package/examples/vector_tile_raster_3d.html +2 -2
  27. package/examples/view_25d_map.html +28 -0
  28. package/examples/view_multi_25d.html +1 -1
  29. package/lib/Controls/FirstPersonControls.js +12 -14
  30. package/lib/Controls/FlyControls.js +2 -10
  31. package/lib/Controls/GlobeControls.js +231 -303
  32. package/lib/Controls/PlanarControls.js +5 -16
  33. package/lib/Controls/StateControl.js +362 -96
  34. package/lib/Converter/Feature2Mesh.js +20 -5
  35. package/lib/Converter/Feature2Texture.js +2 -2
  36. package/lib/Converter/convertToTile.js +1 -1
  37. package/lib/Core/AnimationPlayer.js +15 -0
  38. package/lib/Core/Feature.js +39 -38
  39. package/lib/Core/Geographic/Coordinates.js +56 -0
  40. package/lib/Core/Geographic/Crs.js +15 -0
  41. package/lib/Core/Geographic/Extent.js +99 -11
  42. package/lib/Core/Label.js +1 -1
  43. package/lib/Core/Math/Ellipsoid.js +26 -8
  44. package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +1 -1
  45. package/lib/Core/Prefab/PlanarView.js +1 -1
  46. package/lib/Core/Style.js +1 -0
  47. package/lib/Core/TileMesh.js +3 -2
  48. package/lib/Core/View.js +3 -3
  49. package/lib/Layer/ElevationLayer.js +9 -16
  50. package/lib/Layer/LabelLayer.js +7 -1
  51. package/lib/Main.js +1 -1
  52. package/lib/Parser/ShapefileParser.js +1 -2
  53. package/lib/Parser/VectorTileParser.js +1 -1
  54. package/lib/Process/3dTilesProcessing.js +8 -8
  55. package/lib/Process/FeatureProcessing.js +1 -2
  56. package/lib/Process/ObjectRemovalHelper.js +5 -2
  57. package/lib/Renderer/Label2DRenderer.js +15 -11
  58. package/lib/Renderer/LayeredMaterial.js +2 -1
  59. package/lib/Renderer/OBB.js +2 -2
  60. package/lib/Renderer/RasterTile.js +22 -4
  61. package/lib/Renderer/Shader/ShaderChunk.js +3 -3
  62. package/lib/Renderer/c3DEngine.js +14 -2
  63. package/lib/Source/FileSource.js +2 -7
  64. package/lib/Source/VectorTilesSource.js +19 -0
  65. package/lib/ThreeExtended/loaders/GLTFLoader.js +320 -76
  66. package/lib/Utils/CameraUtils.js +8 -8
  67. package/lib/Utils/DEMUtils.js +2 -2
  68. package/package.json +29 -29
@@ -527,14 +527,7 @@ var PlanarControls = /*#__PURE__*/function (_THREE$EventDispatche) {
527
527
  }, {
528
528
  key: "initiateZoom",
529
529
  value: function initiateZoom(event) {
530
- var delta; // mousewheel delta
531
-
532
- if (undefined !== event.wheelDelta) {
533
- delta = event.wheelDelta;
534
- } else if (undefined !== event.detail) {
535
- delta = -event.detail;
536
- }
537
-
530
+ var delta = -event.deltaY;
538
531
  pointUnderCursor.copy(this.getWorldPointAtScreenXY(mousePosition));
539
532
  var newPos = new THREE.Vector3();
540
533
 
@@ -863,7 +856,7 @@ var PlanarControls = /*#__PURE__*/function (_THREE$EventDispatche) {
863
856
  this.view.domElement.addEventListener('mouseup', this._handlerOnMouseUp, false);
864
857
  this.view.domElement.addEventListener('mouseleave', this._handlerOnMouseUp, false);
865
858
  this.view.domElement.addEventListener('mousemove', this._handlerOnMouseMove, false);
866
- this.view.domElement.addEventListener('mousewheel', this._handlerOnMouseWheel, false); // focus policy
859
+ this.view.domElement.addEventListener('wheel', this._handlerOnMouseWheel, false); // focus policy
867
860
 
868
861
  if (this.focusOnMouseOver) {
869
862
  this.view.domElement.addEventListener('mouseover', this._handlerFocusOnMouseOver, false);
@@ -875,9 +868,7 @@ var PlanarControls = /*#__PURE__*/function (_THREE$EventDispatche) {
875
868
  // this allows to use right-click for input without the menu appearing
876
869
 
877
870
 
878
- this.view.domElement.addEventListener('contextmenu', this._handlerContextMenu, false); // for firefox
879
-
880
- this.view.domElement.addEventListener('MozMousePixelScroll', this._handlerOnMouseWheel, false);
871
+ this.view.domElement.addEventListener('contextmenu', this._handlerContextMenu, false);
881
872
  }
882
873
  /**
883
874
  * Removes all the input listeners (deactivate the controls).
@@ -893,12 +884,10 @@ var PlanarControls = /*#__PURE__*/function (_THREE$EventDispatche) {
893
884
  this.view.domElement.removeEventListener('mouseup', this._handlerOnMouseUp, false);
894
885
  this.view.domElement.removeEventListener('mouseleave', this._handlerOnMouseUp, false);
895
886
  this.view.domElement.removeEventListener('mousemove', this._handlerOnMouseMove, false);
896
- this.view.domElement.removeEventListener('mousewheel', this._handlerOnMouseWheel, false);
887
+ this.view.domElement.removeEventListener('wheel', this._handlerOnMouseWheel, false);
897
888
  this.view.domElement.removeEventListener('mouseover', this._handlerFocusOnMouseOver, false);
898
889
  this.view.domElement.removeEventListener('click', this._handlerFocusOnMouseClick, false);
899
- this.view.domElement.removeEventListener('contextmenu', this._handlerContextMenu, false); // for firefox
900
-
901
- this.view.domElement.removeEventListener('MozMousePixelScroll', this._handlerOnMouseWheel, false);
890
+ this.view.domElement.removeEventListener('contextmenu', this._handlerContextMenu, false);
902
891
  }
903
892
  /**
904
893
  * Update the cursor image according to the control state.
@@ -13,6 +13,8 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
13
13
 
14
14
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
15
 
16
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
+
16
18
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
19
 
18
20
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
@@ -38,19 +40,99 @@ var CONTROL_KEYS = {
38
40
  SHIFT: 16,
39
41
  CTRL: 17,
40
42
  S: 83
41
- };
42
-
43
- function stateToTrigger(state) {
44
- if (!state) {
45
- return undefined;
46
- } else if (state.mouseButton === THREE.MOUSE.LEFT && state["double"]) {
47
- return 'dblclick';
48
- } else if (state.mouseButton === THREE.MOUSE.RIGHT && state["double"]) {
49
- return 'dblclick-right';
50
- } else if (state.keyboard) {
51
- return 'keydown';
43
+ }; // TODO : a class should be made for `State`, and the properties marked with `_` prefix should be made private
44
+
45
+ var DEFAULT_STATES = {
46
+ ORBIT: {
47
+ enable: true,
48
+ mouseButton: THREE.MOUSE.LEFT,
49
+ "double": false,
50
+ keyboard: CONTROL_KEYS.CTRL,
51
+ finger: 2,
52
+ _event: 'rotate'
53
+ },
54
+ MOVE_GLOBE: {
55
+ enable: true,
56
+ mouseButton: THREE.MOUSE.LEFT,
57
+ "double": false,
58
+ finger: 1,
59
+ _event: 'drag'
60
+ },
61
+ DOLLY: {
62
+ enable: true,
63
+ mouseButton: THREE.MOUSE.MIDDLE,
64
+ "double": false,
65
+ finger: 2,
66
+ _event: 'dolly'
67
+ },
68
+ PAN: {
69
+ enable: true,
70
+ mouseButton: THREE.MOUSE.RIGHT,
71
+ "double": false,
72
+ finger: 3,
73
+ _event: 'pan'
74
+ },
75
+ PANORAMIC: {
76
+ enable: true,
77
+ mouseButton: THREE.MOUSE.LEFT,
78
+ "double": false,
79
+ keyboard: CONTROL_KEYS.SHIFT,
80
+ _event: 'panoramic'
81
+ },
82
+ TRAVEL_IN: {
83
+ enable: true,
84
+ mouseButton: THREE.MOUSE.LEFT,
85
+ "double": true,
86
+ _event: 'travel_in',
87
+ _trigger: true,
88
+ _direction: 'in'
89
+ },
90
+ TRAVEL_OUT: {
91
+ enable: false,
92
+ "double": false,
93
+ _event: 'travel_out',
94
+ _trigger: true,
95
+ _direction: 'out'
96
+ },
97
+ ZOOM: {
98
+ enable: true,
99
+ _event: 'zoom',
100
+ _trigger: true
101
+ },
102
+ PAN_UP: {
103
+ enable: true,
104
+ keyboard: CONTROL_KEYS.UP,
105
+ "double": false,
106
+ _event: 'pan',
107
+ _trigger: true,
108
+ _direction: 'up'
109
+ },
110
+ PAN_BOTTOM: {
111
+ enable: true,
112
+ keyboard: CONTROL_KEYS.BOTTOM,
113
+ "double": false,
114
+ _event: 'pan',
115
+ _trigger: true,
116
+ _direction: 'bottom'
117
+ },
118
+ PAN_LEFT: {
119
+ enable: true,
120
+ keyboard: CONTROL_KEYS.LEFT,
121
+ "double": false,
122
+ _event: 'pan',
123
+ _trigger: true,
124
+ _direction: 'left'
125
+ },
126
+ PAN_RIGHT: {
127
+ enable: true,
128
+ keyboard: CONTROL_KEYS.RIGHT,
129
+ "double": false,
130
+ _event: 'pan',
131
+ _trigger: true,
132
+ _direction: 'right'
52
133
  }
53
- }
134
+ };
135
+ var viewCoords = new THREE.Vector2();
54
136
  /**
55
137
  * @typedef {Object} StateControl~State
56
138
  * @property {boolean} enable=true Indicate whether the state is enabled or not.
@@ -80,18 +162,20 @@ function stateToTrigger(state) {
80
162
  * @property {State} PANORAMIC {@link State} describing camera panoramic movement : the camera is rotated around
81
163
  * its own position.
82
164
  * @property {State} TRAVEL_IN {@link State} describing camera travel in movement : the camera is zoomed in toward
83
- * a given position. The choice of the target position is made in the Controls
84
- * associated to this StateControl.
85
- * This state can only be associated to double click on mouse buttons (left or right)
86
- * or a keyboard key.
165
+ * a given position. The target position depends on the key/mouse binding of this
166
+ * state. If bound to a mouse button, the target position is the mouse position.
167
+ * Otherwise, it is the center of the screen.
87
168
  * @property {State} TRAVEL_OUT {@link State} describing camera travel out movement : the camera is zoomed out from
88
- * a given position. The choice of the target position is made in the Controls
89
- * associated to this StateControl.
90
- * This state can only be associated to double click on mouse buttons (left or right)
91
- * or a keyboard key. It is disabled by default.
169
+ * a given position. The target position depends on the key/mouse binding of this
170
+ * state. If bound to a mouse button, the target position is the mouse position.
171
+ * Otherwise, it is the center of the screen. It is disabled by default.
172
+ * @property {State} ZOOM {@link State} describing camera zoom in and out movement.
173
+ * @property {boolean} enable Defines whether all input will be communicated to the associated `Controls` or not.
174
+ * Default is true.
175
+ * @property {boolean} enableKeys Defines whether keyboard input will be communicated to the associated `Controls` or
176
+ * not. Default is true.
92
177
  */
93
178
 
94
-
95
179
  var StateControl = /*#__PURE__*/function (_THREE$EventDispatche) {
96
180
  (0, _inherits2["default"])(StateControl, _THREE$EventDispatche);
97
181
 
@@ -105,48 +189,120 @@ var StateControl = /*#__PURE__*/function (_THREE$EventDispatche) {
105
189
  _this = _super.call(this);
106
190
  _this._view = view;
107
191
  _this._domElement = view.domElement;
108
- _this.NONE = {};
192
+ var enabled = true;
193
+ Object.defineProperty((0, _assertThisInitialized2["default"])(_this), 'enabled', {
194
+ get: function get() {
195
+ return enabled;
196
+ },
197
+ set: function set(value) {
198
+ if (!value) {
199
+ _this.onKeyUp();
200
+
201
+ _this.onPointerUp();
202
+ }
109
203
 
110
- _this._handleTravelInEvent = function (event) {
111
- if (_this.TRAVEL_IN === _this.inputToState(event.button, event.keyCode, _this.TRAVEL_IN["double"])) {
112
- _this.dispatchEvent({
113
- type: 'travel_in',
114
- viewCoords: _this._view.eventToViewCoords(event)
115
- });
204
+ enabled = value;
116
205
  }
117
- };
206
+ }); // Set to true to disable use of the keys
207
+
208
+ var enableKeys = true;
209
+ Object.defineProperty((0, _assertThisInitialized2["default"])(_this), 'enableKeys', {
210
+ get: function get() {
211
+ return enableKeys;
212
+ },
213
+ set: function set(value) {
214
+ if (!value) {
215
+ _this.onKeyUp();
216
+ }
118
217
 
119
- _this._handleTravelOutEvent = function (event) {
120
- if (_this.TRAVEL_OUT === _this.inputToState(event.button, event.keyCode, _this.TRAVEL_OUT["double"])) {
121
- _this.dispatchEvent({
122
- type: 'travel_out',
123
- viewCoords: _this._view.eventToViewCoords(event)
124
- });
218
+ enableKeys = value;
125
219
  }
220
+ });
221
+ _this.NONE = {};
222
+ var currentState = _this.NONE;
223
+ Object.defineProperty((0, _assertThisInitialized2["default"])(_this), 'currentState', {
224
+ get: function get() {
225
+ return currentState;
226
+ },
227
+ set: function set(newState) {
228
+ if (currentState !== newState) {
229
+ var previous = currentState;
230
+ currentState = newState;
231
+
232
+ _this.dispatchEvent({
233
+ type: 'state-changed',
234
+ viewCoords: viewCoords,
235
+ previous: previous
236
+ });
237
+ }
238
+ }
239
+ }); // TODO : the 4 next properties should be made private when ES6 allows it
240
+
241
+ _this._clickTimeStamp = 0;
242
+ _this._lastMousePressed = {
243
+ viewCoords: new THREE.Vector2()
126
244
  };
245
+ _this._currentMousePressed = undefined;
246
+ _this._currentKeyPressed = undefined;
247
+ _this._onPointerDown = _this.onPointerDown.bind((0, _assertThisInitialized2["default"])(_this));
248
+ _this._onPointerMove = _this.onPointerMove.bind((0, _assertThisInitialized2["default"])(_this));
249
+ _this._onPointerUp = _this.onPointerUp.bind((0, _assertThisInitialized2["default"])(_this));
250
+ _this._onMouseWheel = _this.onMouseWheel.bind((0, _assertThisInitialized2["default"])(_this));
251
+ _this._onKeyDown = _this.onKeyDown.bind((0, _assertThisInitialized2["default"])(_this));
252
+ _this._onKeyUp = _this.onKeyUp.bind((0, _assertThisInitialized2["default"])(_this));
253
+ _this._onBlur = _this.onBlur.bind((0, _assertThisInitialized2["default"])(_this));
254
+ _this._onContextMenu = _this.onContextMenu.bind((0, _assertThisInitialized2["default"])(_this));
255
+
256
+ _this._domElement.addEventListener('pointerdown', _this._onPointerDown, false);
257
+
258
+ _this._domElement.addEventListener('wheel', _this._onMouseWheel, false); // The event listener is added on `window` so that key input can be accounted event if the view does not have
259
+ // the focus. This can occur at page loading, when a mini map is displayed : the minimap initially has the focus
260
+ // and key input would not be considered on the view's domElement.
261
+
262
+
263
+ window.addEventListener('keydown', _this._onKeyDown, false);
264
+ window.addEventListener('keyup', _this._onKeyUp, false); // Reset key/mouse when window loose focus
265
+
266
+ window.addEventListener('blur', _this._onBlur); // disable context menu when right-clicking
267
+
268
+ _this._domElement.addEventListener('contextmenu', _this._onContextMenu, false);
127
269
 
128
270
  _this.setFromOptions(options);
129
271
 
130
272
  return _this;
131
273
  }
132
274
  /**
133
- * get the state corresponding to the mouse button and the keyboard key
275
+ * get the state corresponding to the mouse button and the keyboard key. If the input relates to a trigger - a
276
+ * single event which triggers movement, without the move of the mouse for instance -, dispatch a relevant event.
134
277
  * @param {Number} mouseButton The mouse button
135
278
  * @param {Number} keyboard The keyboard
136
279
  * @param {Boolean} [double] Value of the searched state `double` property
137
- * @return {state} the state corresponding
280
+ * @return {State} the state corresponding
138
281
  */
139
282
 
140
283
 
141
284
  (0, _createClass2["default"])(StateControl, [{
142
285
  key: "inputToState",
143
- value: function inputToState(mouseButton, keyboard, _double) {
144
- for (var _i = 0, _Object$keys = Object.keys(this); _i < _Object$keys.length; _i++) {
286
+ value: function inputToState(mouseButton, keyboard) {
287
+ var _double = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
288
+
289
+ for (var _i = 0, _Object$keys = Object.keys(DEFAULT_STATES); _i < _Object$keys.length; _i++) {
145
290
  var key = _Object$keys[_i];
146
291
  var state = this[key];
147
292
 
148
293
  if (state.enable && state.mouseButton === mouseButton && state.keyboard === keyboard && state["double"] === _double) {
149
- return state;
294
+ // If the input relates to a state, returns it
295
+ if (!state._trigger) {
296
+ return state;
297
+ } // If the input relates to a trigger (TRAVEL_IN, TRAVEL_OUT), dispatch a relevant event.
298
+
299
+
300
+ this.dispatchEvent({
301
+ type: state._event,
302
+ // Dont pass viewCoords if the input is only a keyboard input.
303
+ viewCoords: mouseButton !== undefined && viewCoords,
304
+ direction: state._direction
305
+ });
150
306
  }
151
307
  }
152
308
 
@@ -162,7 +318,7 @@ var StateControl = /*#__PURE__*/function (_THREE$EventDispatche) {
162
318
  }, {
163
319
  key: "touchToState",
164
320
  value: function touchToState(finger) {
165
- for (var _i2 = 0, _Object$keys2 = Object.keys(this); _i2 < _Object$keys2.length; _i2++) {
321
+ for (var _i2 = 0, _Object$keys2 = Object.keys(DEFAULT_STATES); _i2 < _Object$keys2.length; _i2++) {
166
322
  var key = _Object$keys2[_i2];
167
323
  var state = this[key];
168
324
 
@@ -176,73 +332,167 @@ var StateControl = /*#__PURE__*/function (_THREE$EventDispatche) {
176
332
  /**
177
333
  * Set the current StateControl {@link State} properties to given values.
178
334
  * @param {Object} options Object containing the `State` values to set current `StateControl` properties to.
335
+ * The `enable` property do not necessarily need to be specified. In that case, the
336
+ * previous value of this property will be kept for the new {@link State}.
179
337
  *
180
338
  * @example
181
- * // Switch bindings for PAN and MOVE_GLOBE actions :
339
+ * // Switch bindings for PAN and MOVE_GLOBE actions, and disabling PANORAMIC movement :
182
340
  * view.controls.states.setFromOptions({
183
341
  * PAN: {
184
- * enable: true,
185
- * mouseButton: itowns.THREE.MOUSE.LEFT,
342
+ * mouseButton: itowns.THREE.MOUSE.LEFT,
186
343
  * },
187
344
  * MOVE_GLOBE: {
188
- * enable: true,
189
345
  * mouseButton: itowns.THREE.MOUSE.RIGHT,
190
346
  * },
347
+ * PANORAMIC: {
348
+ * enable: false,
349
+ * },
191
350
  * };
192
351
  */
193
352
 
194
353
  }, {
195
354
  key: "setFromOptions",
196
355
  value: function setFromOptions(options) {
197
- this.ORBIT = options.ORBIT || this.ORBIT || {
198
- mouseButton: THREE.MOUSE.LEFT,
199
- keyboard: CONTROL_KEYS.CTRL,
200
- enable: true,
201
- finger: 2
202
- };
203
- this.DOLLY = options.DOLLY || this.DOLLY || {
204
- mouseButton: THREE.MOUSE.MIDDLE,
205
- enable: true
206
- };
207
- this.PAN = options.PAN || this.PAN || {
208
- mouseButton: THREE.MOUSE.RIGHT,
209
- up: CONTROL_KEYS.UP,
210
- bottom: CONTROL_KEYS.BOTTOM,
211
- left: CONTROL_KEYS.LEFT,
212
- right: CONTROL_KEYS.RIGHT,
213
- enable: true,
214
- finger: 3
215
- };
216
- this.MOVE_GLOBE = options.MOVE_GLOBE || this.MOVE_GLOBE || {
217
- mouseButton: THREE.MOUSE.LEFT,
218
- enable: true,
219
- finger: 1
220
- };
221
- this.PANORAMIC = options.PANORAMIC || this.PANORAMIC || {
222
- mouseButton: THREE.MOUSE.LEFT,
223
- keyboard: CONTROL_KEYS.SHIFT,
224
- enable: true
225
- };
226
- var newTravelIn = options.TRAVEL_IN || this.TRAVEL_IN || {
227
- enable: true,
228
- mouseButton: THREE.MOUSE.LEFT,
229
- "double": true
230
- };
231
-
232
- this._domElement.removeEventListener(stateToTrigger(this.TRAVEL_IN), this._handleTravelInEvent, false);
233
-
234
- this._domElement.addEventListener(stateToTrigger(newTravelIn), this._handleTravelInEvent, false);
235
-
236
- this.TRAVEL_IN = newTravelIn;
237
- var newTravelOut = options.TRAVEL_OUT || this.TRAVEL_OUT || {
238
- enable: false
239
- };
240
-
241
- this._domElement.removeEventListener(stateToTrigger(this.TRAVEL_OUT), this._handleTravelOutEvent, false);
242
-
243
- this._domElement.addEventListener(stateToTrigger(newTravelOut), this._handleTravelOutEvent, false);
244
-
245
- this.TRAVEL_OUT = newTravelOut;
356
+ for (var state in DEFAULT_STATES) {
357
+ if ({}.hasOwnProperty.call(DEFAULT_STATES, state)) {
358
+ var newState = {};
359
+ newState = options[state] || this[state] || Object.assign(newState, DEFAULT_STATES[state]); // Copy the previous value of `enable` property if not defined in options
360
+
361
+ if (options[state] && options[state].enable === undefined) {
362
+ newState.enable = this[state].enable;
363
+ } // If no value is provided for the `double` property,
364
+ // defaults it to `false` instead of leaving it undefined
365
+
366
+
367
+ newState["double"] = !!newState["double"]; // Copy the `_event` and `_trigger` properties
368
+
369
+ newState._event = DEFAULT_STATES[state]._event;
370
+ newState._trigger = DEFAULT_STATES[state]._trigger;
371
+ newState._direction = DEFAULT_STATES[state]._direction;
372
+ this[state] = newState;
373
+ }
374
+ }
375
+ } // ---------- POINTER EVENTS : ----------
376
+
377
+ }, {
378
+ key: "onPointerDown",
379
+ value: function onPointerDown(event) {
380
+ if (!this.enabled) {
381
+ return;
382
+ }
383
+
384
+ viewCoords.copy(this._view.eventToViewCoords(event));
385
+
386
+ switch (event.pointerType) {
387
+ case 'mouse':
388
+ this._currentMousePressed = event.button;
389
+ this.currentState = this.inputToState(this._currentMousePressed, this._currentKeyPressed, // Detect if the mouse button was pressed less than 500 ms before, and if the cursor has not moved two much
390
+ // since previous click. If so, set dblclick to true.
391
+ event.timeStamp - this._clickTimeStamp < 500 && this._lastMousePressed.button === this._currentMousePressed && this._lastMousePressed.viewCoords.distanceTo(viewCoords) < 5);
392
+ this._clickTimeStamp = event.timeStamp;
393
+ this._lastMousePressed.button = this._currentMousePressed;
394
+
395
+ this._lastMousePressed.viewCoords.copy(viewCoords);
396
+
397
+ break;
398
+ // TODO : add touch event management
399
+
400
+ default:
401
+ }
402
+
403
+ this._domElement.addEventListener('pointermove', this._onPointerMove, false);
404
+
405
+ this._domElement.addEventListener('pointerup', this._onPointerUp, false);
406
+
407
+ this._domElement.addEventListener('mouseleave', this._onPointerUp, false);
408
+ }
409
+ }, {
410
+ key: "onPointerMove",
411
+ value: function onPointerMove(event) {
412
+ event.preventDefault();
413
+
414
+ if (!this.enabled) {
415
+ return;
416
+ }
417
+
418
+ viewCoords.copy(this._view.eventToViewCoords(event));
419
+
420
+ switch (event.pointerType) {
421
+ case 'mouse':
422
+ this.dispatchEvent({
423
+ type: this.currentState._event,
424
+ viewCoords: viewCoords
425
+ });
426
+ break;
427
+ // TODO : add touch event management
428
+
429
+ default:
430
+ }
431
+ }
432
+ }, {
433
+ key: "onPointerUp",
434
+ value: function onPointerUp() {
435
+ if (!this.enabled) {
436
+ return;
437
+ }
438
+
439
+ this._currentMousePressed = undefined;
440
+
441
+ this._domElement.removeEventListener('pointermove', this._onPointerMove, false);
442
+
443
+ this._domElement.removeEventListener('pointerup', this._onPointerUp, false);
444
+
445
+ this._domElement.removeEventListener('mouseleave', this._onPointerUp, false);
446
+
447
+ this.currentState = this.NONE;
448
+ } // ---------- WHEEL EVENT : ----------
449
+
450
+ }, {
451
+ key: "onMouseWheel",
452
+ value: function onMouseWheel(event) {
453
+ event.preventDefault();
454
+
455
+ if (this.enabled && this.ZOOM.enable) {
456
+ this.dispatchEvent({
457
+ type: this.ZOOM._event,
458
+ delta: event.deltaY
459
+ });
460
+ }
461
+ } // ---------- KEYBOARD EVENTS : ----------
462
+
463
+ }, {
464
+ key: "onKeyDown",
465
+ value: function onKeyDown(event) {
466
+ if (!this.enabled || !this.enableKeys) {
467
+ return;
468
+ }
469
+
470
+ this._currentKeyPressed = event.keyCode;
471
+ this.inputToState(this._currentMousePressed, this._currentKeyPressed);
472
+ }
473
+ }, {
474
+ key: "onKeyUp",
475
+ value: function onKeyUp() {
476
+ if (!this.enabled || !this.enableKeys) {
477
+ return;
478
+ }
479
+
480
+ this._currentKeyPressed = undefined;
481
+
482
+ if (this._currentMousePressed === undefined) {
483
+ this.currentState = this.NONE;
484
+ }
485
+ }
486
+ }, {
487
+ key: "onBlur",
488
+ value: function onBlur() {
489
+ this.onKeyUp();
490
+ this.onPointerUp();
491
+ }
492
+ }, {
493
+ key: "onContextMenu",
494
+ value: function onContextMenu(event) {
495
+ event.preventDefault();
246
496
  }
247
497
  /**
248
498
  * Remove all event listeners created within this instance of `StateControl`
@@ -251,9 +501,25 @@ var StateControl = /*#__PURE__*/function (_THREE$EventDispatche) {
251
501
  }, {
252
502
  key: "dispose",
253
503
  value: function dispose() {
254
- this._domElement.removeEventListener(this.TRAVEL_IN.trigger, this._handleTravelInEvent, false);
504
+ this._clickTimeStamp = 0;
505
+ this._lastMousePressed = undefined;
506
+ this._currentKeyPressed = undefined;
507
+
508
+ this._domElement.removeEventListener('pointerdown', this._onPointerDown, false);
509
+
510
+ this._domElement.removeEventListener('pointermove', this._onPointerMove, false);
511
+
512
+ this._domElement.removeEventListener('pointerup', this._onPointerUp, false);
513
+
514
+ this._domElement.removeEventListener('wheel', this._onMouseWheel, false);
515
+
516
+ this._domElement.removeEventListener('keydown', this._onKeyDown, false);
517
+
518
+ this._domElement.removeEventListener('keyup', this._onKeyUp, false);
519
+
520
+ window.removeEventListener('blur', this._onBlur);
255
521
 
256
- this._domElement.removeEventListener(this.TRAVEL_OUT.trigger, this._handleTravelInEvent, false);
522
+ this._domElement.removeEventListener('contextmenu', this._onContextMenu, false);
257
523
  }
258
524
  }]);
259
525
  return StateControl;
@@ -29,6 +29,10 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
29
29
 
30
30
  var _color = new THREE.Color();
31
31
 
32
+ var maxValueUint8 = Math.pow(2, 8) - 1;
33
+ var maxValueUint16 = Math.pow(2, 16) - 1;
34
+ var maxValueUint32 = Math.pow(2, 32) - 1;
35
+
32
36
  function toColor(color) {
33
37
  if (color) {
34
38
  if (color.type == 'Color') {
@@ -58,6 +62,16 @@ function fillBatchIdArray(batchId, batchIdArray, start, end) {
58
62
  batchIdArray[i] = batchId;
59
63
  }
60
64
  }
65
+
66
+ function getIntArrayFromSize(data, size) {
67
+ if (size <= maxValueUint8) {
68
+ return new Uint8Array(data);
69
+ } else if (size <= maxValueUint16) {
70
+ return new Uint16Array(data);
71
+ } else {
72
+ return new Uint32Array(data);
73
+ }
74
+ }
61
75
  /**
62
76
  * Convert coordinates to vertices positionned at a given altitude
63
77
  *
@@ -230,7 +244,7 @@ function featureToLine(feature, options) {
230
244
 
231
245
  if (feature.geometries.length > 1) {
232
246
  var countIndices = (count - feature.geometries.length) * 2;
233
- var indices = new Uint16Array(countIndices);
247
+ var indices = getIntArrayFromSize(countIndices, count);
234
248
  var i = 0; // Multi line case
235
249
 
236
250
  var _iterator2 = _createForOfIteratorHelper(feature.geometries),
@@ -342,9 +356,9 @@ function featureToPolygon(feature, options) {
342
356
  try {
343
357
  var _loop3 = function () {
344
358
  var geometry = _step3.value;
345
- var start = geometry.indices[0].offset; // To avoid integer overflow with indice value (16 bits)
359
+ var start = geometry.indices[0].offset; // To avoid integer overflow with index value (32 bits)
346
360
 
347
- if (start > 0xffff) {
361
+ if (start > maxValueUint32) {
348
362
  console.warn('Feature to Polygon: integer overflow, too many points in polygons');
349
363
  return "break";
350
364
  }
@@ -396,7 +410,7 @@ function featureToPolygon(feature, options) {
396
410
  geom.setAttribute('batchId', new THREE.BufferAttribute(batchIds, 1));
397
411
  }
398
412
 
399
- geom.setIndex(new THREE.BufferAttribute(new Uint16Array(indices), 1));
413
+ geom.setIndex(new THREE.BufferAttribute(getIntArrayFromSize(indices, vertices.length / 3), 1));
400
414
  return new THREE.Mesh(geom, material);
401
415
  }
402
416
 
@@ -509,7 +523,7 @@ function featureToExtrudedPolygon(feature, options) {
509
523
  geom.setAttribute('batchId', new THREE.BufferAttribute(batchIds, 1));
510
524
  }
511
525
 
512
- geom.setIndex(new THREE.BufferAttribute(new Uint16Array(indices), 1));
526
+ geom.setIndex(new THREE.BufferAttribute(getIntArrayFromSize(indices, vertices.length / 3), 1));
513
527
  var mesh = new THREE.Mesh(geom, material);
514
528
  return mesh;
515
529
  }
@@ -615,6 +629,7 @@ var _default = {
615
629
  });
616
630
  group.quaternion.copy(collection.quaternion);
617
631
  group.position.copy(collection.position);
632
+ group.scale.copy(collection.scale);
618
633
  return group;
619
634
  };
620
635
  }