itowns 2.44.3-next.40 → 2.44.3-next.42

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 (199) hide show
  1. package/README.md +3 -129
  2. package/package.json +16 -72
  3. package/CODING.md +0 -120
  4. package/CONTRIBUTING.md +0 -150
  5. package/CONTRIBUTORS.md +0 -56
  6. package/LICENSE.md +0 -44
  7. package/changelog.md +0 -1361
  8. package/dist/455.js +0 -2
  9. package/dist/455.js.map +0 -1
  10. package/dist/debug.js +0 -3
  11. package/dist/debug.js.LICENSE.txt +0 -13
  12. package/dist/debug.js.map +0 -1
  13. package/dist/itowns.js +0 -3
  14. package/dist/itowns.js.LICENSE.txt +0 -5
  15. package/dist/itowns.js.map +0 -1
  16. package/dist/itowns_lasparser.js +0 -2
  17. package/dist/itowns_lasparser.js.map +0 -1
  18. package/dist/itowns_lasworker.js +0 -2
  19. package/dist/itowns_lasworker.js.map +0 -1
  20. package/dist/itowns_potree2worker.js +0 -2
  21. package/dist/itowns_potree2worker.js.map +0 -1
  22. package/dist/itowns_widgets.js +0 -2
  23. package/dist/itowns_widgets.js.map +0 -1
  24. package/examples/.eslintrc.cjs +0 -35
  25. package/examples/jsm/.eslintrc.cjs +0 -38
  26. package/lib/Controls/FirstPersonControls.js +0 -308
  27. package/lib/Controls/FlyControls.js +0 -175
  28. package/lib/Controls/GlobeControls.js +0 -1179
  29. package/lib/Controls/PlanarControls.js +0 -1025
  30. package/lib/Controls/StateControl.js +0 -432
  31. package/lib/Controls/StreetControls.js +0 -392
  32. package/lib/Converter/Feature2Mesh.js +0 -614
  33. package/lib/Converter/Feature2Texture.js +0 -175
  34. package/lib/Converter/convertToTile.js +0 -70
  35. package/lib/Converter/textureConverter.js +0 -43
  36. package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
  37. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
  38. package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
  39. package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
  40. package/lib/Core/3DTiles/C3DTFeature.js +0 -110
  41. package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
  42. package/lib/Core/3DTiles/C3DTileset.js +0 -99
  43. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
  44. package/lib/Core/AnimationPlayer.js +0 -142
  45. package/lib/Core/CopcNode.js +0 -174
  46. package/lib/Core/Deprecated/Undeprecator.js +0 -74
  47. package/lib/Core/EntwinePointTileNode.js +0 -126
  48. package/lib/Core/Feature.js +0 -489
  49. package/lib/Core/Geographic/CoordStars.js +0 -80
  50. package/lib/Core/Geographic/Coordinates.js +0 -331
  51. package/lib/Core/Geographic/Crs.js +0 -170
  52. package/lib/Core/Geographic/Extent.js +0 -550
  53. package/lib/Core/Geographic/GeoidGrid.js +0 -109
  54. package/lib/Core/Label.js +0 -222
  55. package/lib/Core/MainLoop.js +0 -209
  56. package/lib/Core/Math/Ellipsoid.js +0 -185
  57. package/lib/Core/Picking.js +0 -255
  58. package/lib/Core/PointCloudNode.js +0 -42
  59. package/lib/Core/Potree2Node.js +0 -206
  60. package/lib/Core/Potree2PointAttributes.js +0 -139
  61. package/lib/Core/PotreeNode.js +0 -101
  62. package/lib/Core/Prefab/Globe/Atmosphere.js +0 -295
  63. package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -152
  64. package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +0 -111
  65. package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
  66. package/lib/Core/Prefab/GlobeView.js +0 -156
  67. package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -59
  68. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
  69. package/lib/Core/Prefab/PlanarView.js +0 -62
  70. package/lib/Core/Prefab/TileBuilder.js +0 -82
  71. package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -248
  72. package/lib/Core/Scheduler/Cache.js +0 -17
  73. package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
  74. package/lib/Core/Scheduler/Scheduler.js +0 -294
  75. package/lib/Core/Style.js +0 -660
  76. package/lib/Core/StyleOptions.js +0 -486
  77. package/lib/Core/System/Capabilities.js +0 -63
  78. package/lib/Core/Tile/Tile.js +0 -207
  79. package/lib/Core/Tile/TileGrid.js +0 -49
  80. package/lib/Core/TileGeometry.js +0 -124
  81. package/lib/Core/TileMesh.js +0 -108
  82. package/lib/Core/View.js +0 -1116
  83. package/lib/Layer/C3DTilesLayer.js +0 -459
  84. package/lib/Layer/ColorLayer.js +0 -154
  85. package/lib/Layer/CopcLayer.js +0 -63
  86. package/lib/Layer/ElevationLayer.js +0 -139
  87. package/lib/Layer/EntwinePointTileLayer.js +0 -71
  88. package/lib/Layer/FeatureGeometryLayer.js +0 -77
  89. package/lib/Layer/GeoidLayer.js +0 -80
  90. package/lib/Layer/GeometryLayer.js +0 -233
  91. package/lib/Layer/InfoLayer.js +0 -64
  92. package/lib/Layer/LabelLayer.js +0 -470
  93. package/lib/Layer/Layer.js +0 -335
  94. package/lib/Layer/LayerUpdateState.js +0 -89
  95. package/lib/Layer/LayerUpdateStrategy.js +0 -80
  96. package/lib/Layer/OGC3DTilesLayer.js +0 -543
  97. package/lib/Layer/OrientedImageLayer.js +0 -228
  98. package/lib/Layer/PointCloudLayer.js +0 -405
  99. package/lib/Layer/Potree2Layer.js +0 -171
  100. package/lib/Layer/PotreeLayer.js +0 -72
  101. package/lib/Layer/RasterLayer.js +0 -37
  102. package/lib/Layer/ReferencingLayerProperties.js +0 -62
  103. package/lib/Layer/TiledGeometryLayer.js +0 -459
  104. package/lib/Loader/LASLoader.js +0 -193
  105. package/lib/Loader/Potree2BrotliLoader.js +0 -261
  106. package/lib/Loader/Potree2Loader.js +0 -207
  107. package/lib/Main.js +0 -115
  108. package/lib/MainBundle.js +0 -4
  109. package/lib/Parser/B3dmParser.js +0 -174
  110. package/lib/Parser/CameraCalibrationParser.js +0 -94
  111. package/lib/Parser/GDFParser.js +0 -72
  112. package/lib/Parser/GTXParser.js +0 -75
  113. package/lib/Parser/GeoJsonParser.js +0 -212
  114. package/lib/Parser/GpxParser.js +0 -25
  115. package/lib/Parser/ISGParser.js +0 -71
  116. package/lib/Parser/KMLParser.js +0 -25
  117. package/lib/Parser/LASParser.js +0 -137
  118. package/lib/Parser/MapBoxUrlParser.js +0 -83
  119. package/lib/Parser/PntsParser.js +0 -131
  120. package/lib/Parser/Potree2BinParser.js +0 -92
  121. package/lib/Parser/PotreeBinParser.js +0 -106
  122. package/lib/Parser/PotreeCinParser.js +0 -29
  123. package/lib/Parser/ShapefileParser.js +0 -78
  124. package/lib/Parser/VectorTileParser.js +0 -215
  125. package/lib/Parser/XbilParser.js +0 -120
  126. package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
  127. package/lib/Parser/iGLTFLoader.js +0 -168
  128. package/lib/Process/3dTilesProcessing.js +0 -304
  129. package/lib/Process/FeatureProcessing.js +0 -76
  130. package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
  131. package/lib/Process/ObjectRemovalHelper.js +0 -97
  132. package/lib/Process/handlerNodeError.js +0 -23
  133. package/lib/Provider/3dTilesProvider.js +0 -149
  134. package/lib/Provider/DataSourceProvider.js +0 -8
  135. package/lib/Provider/Fetcher.js +0 -233
  136. package/lib/Provider/PointCloudProvider.js +0 -45
  137. package/lib/Provider/TileProvider.js +0 -16
  138. package/lib/Provider/URLBuilder.js +0 -116
  139. package/lib/Renderer/Camera.js +0 -281
  140. package/lib/Renderer/Color.js +0 -56
  141. package/lib/Renderer/ColorLayersOrdering.js +0 -115
  142. package/lib/Renderer/CommonMaterial.js +0 -31
  143. package/lib/Renderer/Label2DRenderer.js +0 -192
  144. package/lib/Renderer/LayeredMaterial.js +0 -243
  145. package/lib/Renderer/OBB.js +0 -151
  146. package/lib/Renderer/OrientedImageCamera.js +0 -118
  147. package/lib/Renderer/OrientedImageMaterial.js +0 -167
  148. package/lib/Renderer/PointsMaterial.js +0 -485
  149. package/lib/Renderer/RasterTile.js +0 -208
  150. package/lib/Renderer/RenderMode.js +0 -31
  151. package/lib/Renderer/Shader/ShaderChunk.js +0 -160
  152. package/lib/Renderer/Shader/ShaderUtils.js +0 -47
  153. package/lib/Renderer/SphereHelper.js +0 -17
  154. package/lib/Renderer/WebXR.js +0 -51
  155. package/lib/Renderer/c3DEngine.js +0 -214
  156. package/lib/Source/C3DTilesGoogleSource.js +0 -74
  157. package/lib/Source/C3DTilesIonSource.js +0 -54
  158. package/lib/Source/C3DTilesSource.js +0 -30
  159. package/lib/Source/CopcSource.js +0 -126
  160. package/lib/Source/EntwinePointTileSource.js +0 -72
  161. package/lib/Source/FileSource.js +0 -188
  162. package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
  163. package/lib/Source/OGC3DTilesIonSource.js +0 -34
  164. package/lib/Source/OGC3DTilesSource.js +0 -21
  165. package/lib/Source/OrientedImageSource.js +0 -59
  166. package/lib/Source/Potree2Source.js +0 -167
  167. package/lib/Source/PotreeSource.js +0 -82
  168. package/lib/Source/Source.js +0 -203
  169. package/lib/Source/TMSSource.js +0 -144
  170. package/lib/Source/VectorTilesSource.js +0 -182
  171. package/lib/Source/WFSSource.js +0 -170
  172. package/lib/Source/WMSSource.js +0 -168
  173. package/lib/Source/WMTSSource.js +0 -92
  174. package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
  175. package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -506
  176. package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
  177. package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
  178. package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -400
  179. package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2879
  180. package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -709
  181. package/lib/ThreeExtended/math/ColorSpaces.js +0 -59
  182. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
  183. package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
  184. package/lib/Utils/CameraUtils.js +0 -555
  185. package/lib/Utils/DEMUtils.js +0 -350
  186. package/lib/Utils/FeaturesUtils.js +0 -156
  187. package/lib/Utils/Gradients.js +0 -16
  188. package/lib/Utils/OrientationUtils.js +0 -457
  189. package/lib/Utils/ThreeUtils.js +0 -115
  190. package/lib/Utils/gui/C3DTilesStyle.js +0 -215
  191. package/lib/Utils/gui/Main.js +0 -7
  192. package/lib/Utils/gui/Minimap.js +0 -154
  193. package/lib/Utils/gui/Navigation.js +0 -245
  194. package/lib/Utils/gui/Scale.js +0 -107
  195. package/lib/Utils/gui/Searchbar.js +0 -234
  196. package/lib/Utils/gui/Widget.js +0 -80
  197. package/lib/Utils/placeObjectOnGround.js +0 -136
  198. package/lib/Worker/LASLoaderWorker.js +0 -19
  199. package/lib/Worker/Potree2Worker.js +0 -21
@@ -1,432 +0,0 @@
1
- import * as THREE from 'three';
2
- const CONTROL_KEYS = {
3
- LEFT: 37,
4
- UP: 38,
5
- RIGHT: 39,
6
- BOTTOM: 40,
7
- SPACE: 32,
8
- SHIFT: 16,
9
- CTRL: 17,
10
- META: 91,
11
- S: 83
12
- };
13
-
14
- // TODO : a class should be made for `State`, and the properties marked with `_` prefix should be made private
15
- const DEFAULT_STATES = {
16
- ORBIT: {
17
- enable: true,
18
- mouseButton: THREE.MOUSE.LEFT,
19
- double: false,
20
- keyboard: CONTROL_KEYS.CTRL,
21
- finger: 2,
22
- _event: 'rotate'
23
- },
24
- MOVE_GLOBE: {
25
- enable: true,
26
- mouseButton: THREE.MOUSE.LEFT,
27
- double: false,
28
- finger: 1,
29
- _event: 'drag'
30
- },
31
- DOLLY: {
32
- enable: true,
33
- mouseButton: THREE.MOUSE.MIDDLE,
34
- double: false,
35
- finger: 2,
36
- _event: 'dolly'
37
- },
38
- PAN: {
39
- enable: true,
40
- mouseButton: THREE.MOUSE.RIGHT,
41
- double: false,
42
- finger: 3,
43
- _event: 'pan'
44
- },
45
- PANORAMIC: {
46
- enable: true,
47
- mouseButton: THREE.MOUSE.LEFT,
48
- double: false,
49
- keyboard: CONTROL_KEYS.SHIFT,
50
- _event: 'panoramic'
51
- },
52
- TRAVEL_IN: {
53
- enable: true,
54
- mouseButton: THREE.MOUSE.LEFT,
55
- double: true,
56
- _event: 'travel_in',
57
- _trigger: true,
58
- _direction: 'in'
59
- },
60
- TRAVEL_OUT: {
61
- enable: false,
62
- double: false,
63
- _event: 'travel_out',
64
- _trigger: true,
65
- _direction: 'out'
66
- },
67
- ZOOM: {
68
- enable: true,
69
- _event: 'zoom',
70
- _trigger: true
71
- },
72
- PAN_UP: {
73
- enable: true,
74
- keyboard: CONTROL_KEYS.UP,
75
- double: false,
76
- _event: 'pan',
77
- _trigger: true,
78
- _direction: 'up'
79
- },
80
- PAN_BOTTOM: {
81
- enable: true,
82
- keyboard: CONTROL_KEYS.BOTTOM,
83
- double: false,
84
- _event: 'pan',
85
- _trigger: true,
86
- _direction: 'bottom'
87
- },
88
- PAN_LEFT: {
89
- enable: true,
90
- keyboard: CONTROL_KEYS.LEFT,
91
- double: false,
92
- _event: 'pan',
93
- _trigger: true,
94
- _direction: 'left'
95
- },
96
- PAN_RIGHT: {
97
- enable: true,
98
- keyboard: CONTROL_KEYS.RIGHT,
99
- double: false,
100
- _event: 'pan',
101
- _trigger: true,
102
- _direction: 'right'
103
- }
104
- };
105
- const viewCoords = new THREE.Vector2();
106
-
107
- /**
108
- * @typedef {Object} StateControl~State
109
- * @property {boolean} enable=true Indicate whether the state is enabled or not.
110
- * @property {Number} [mouseButton] The mouse button bound to this state.
111
- * @property {Number} [keyboard] The keyCode of the keyboard input bound to this state.
112
- * @property {Number} [finger] The number of fingers on the pad bound to this state.
113
- * @property {boolean} [double] True if the mouse button bound to this state must be pressed twice. For
114
- * example, if `double` is set to true with a `mouseButton` set to left click,
115
- * the State will be bound to a double click mouse button.
116
- */
117
-
118
- /**
119
- * It represents the control's states.
120
- * Each {@link State} is a control mode of the camera and how to interact with
121
- * the interface to activate this mode.
122
- * @class StateControl
123
- *
124
- * @property {State} NONE {@link State} when camera is idle.
125
- * @property {State} ORBIT {@link State} describing camera orbiting movement : the camera moves around its
126
- * target at a constant distance from it.
127
- * @property {State} DOLLY {@link State} describing camera dolly movement : the camera moves forward or
128
- * backward from its target.
129
- * @property {State} PAN {@link State} describing camera pan movement : the camera moves parallel to the
130
- * current view plane.
131
- * @property {State} MOVE_GLOBE {@link State} describing camera drag movement : the camera is moved around the view
132
- * to give the feeling that the view is dragged under a static camera.
133
- * @property {State} PANORAMIC {@link State} describing camera panoramic movement : the camera is rotated around
134
- * its own position.
135
- * @property {State} TRAVEL_IN {@link State} describing camera travel in movement : the camera is zoomed in toward
136
- * a given position. The target position depends on the key/mouse binding of this
137
- * state. If bound to a mouse button, the target position is the mouse position.
138
- * Otherwise, it is the center of the screen.
139
- * @property {State} TRAVEL_OUT {@link State} describing camera travel out movement : the camera is zoomed out from
140
- * a given position. The target position depends on the key/mouse binding of this
141
- * state. If bound to a mouse button, the target position is the mouse position.
142
- * Otherwise, it is the center of the screen. It is disabled by default.
143
- * @property {State} ZOOM {@link State} describing camera zoom in and out movement.
144
- * @property {boolean} enable Defines whether all input will be communicated to the associated `Controls` or not.
145
- * Default is true.
146
- * @property {boolean} enableKeys Defines whether keyboard input will be communicated to the associated `Controls` or
147
- * not. Default is true.
148
- */
149
- class StateControl extends THREE.EventDispatcher {
150
- constructor(view) {
151
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
152
- super();
153
- this._view = view;
154
- this._domElement = view.domElement;
155
- let enabled = true;
156
- Object.defineProperty(this, 'enabled', {
157
- get: () => enabled,
158
- set: value => {
159
- if (!value) {
160
- this.onKeyUp();
161
- this.onPointerUp();
162
- }
163
- enabled = value;
164
- }
165
- });
166
-
167
- // Set to true to disable use of the keys
168
- let enableKeys = true;
169
- Object.defineProperty(this, 'enableKeys', {
170
- get: () => enableKeys,
171
- set: value => {
172
- if (!value) {
173
- this.onKeyUp();
174
- }
175
- enableKeys = value;
176
- }
177
- });
178
- this.NONE = {};
179
- let currentState = this.NONE;
180
- Object.defineProperty(this, 'currentState', {
181
- get: () => currentState,
182
- set: newState => {
183
- if (currentState !== newState) {
184
- const previous = currentState;
185
- currentState = newState;
186
- this.dispatchEvent({
187
- type: 'state-changed',
188
- viewCoords,
189
- previous
190
- });
191
- }
192
- }
193
- });
194
-
195
- // TODO : the 4 next properties should be made private when ES6 allows it
196
- this._clickTimeStamp = 0;
197
- this._lastMousePressed = {
198
- viewCoords: new THREE.Vector2()
199
- };
200
- this._currentMousePressed = undefined;
201
- this._currentKeyPressed = undefined;
202
- this._onPointerDown = this.onPointerDown.bind(this);
203
- this._onPointerMove = this.onPointerMove.bind(this);
204
- this._onPointerUp = this.onPointerUp.bind(this);
205
- this._onMouseWheel = this.onMouseWheel.bind(this);
206
- this._onKeyDown = this.onKeyDown.bind(this);
207
- this._onKeyUp = this.onKeyUp.bind(this);
208
- this._onBlur = this.onBlur.bind(this);
209
- this._onContextMenu = this.onContextMenu.bind(this);
210
- this._domElement.addEventListener('pointerdown', this._onPointerDown, false);
211
- this._domElement.addEventListener('wheel', this._onMouseWheel, false);
212
- this._domElement.addEventListener('keydown', this._onKeyDown, false);
213
- this._domElement.addEventListener('keyup', this._onKeyUp, false);
214
-
215
- // Reset key/mouse when window loose focus
216
- this._domElement.addEventListener('blur', this._onBlur);
217
- // disable context menu when right-clicking
218
- this._domElement.addEventListener('contextmenu', this._onContextMenu, false);
219
- this.setFromOptions(options);
220
- }
221
-
222
- /**
223
- * get the state corresponding to the mouse button and the keyboard key. If the input relates to a trigger - a
224
- * single event which triggers movement, without the move of the mouse for instance -, dispatch a relevant event.
225
- * @param {Number} mouseButton The mouse button
226
- * @param {Number} keyboard The keyboard
227
- * @param {Boolean} [double] Value of the searched state `double` property
228
- * @return {State} the state corresponding
229
- */
230
- inputToState(mouseButton, keyboard) {
231
- let double = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
232
- for (const key of Object.keys(DEFAULT_STATES)) {
233
- const state = this[key];
234
- if (state.enable && state.mouseButton === mouseButton && state.keyboard === keyboard && state.double === double) {
235
- // If the input relates to a state, returns it
236
- if (!state._trigger) {
237
- return state;
238
- }
239
- // If the input relates to a trigger (TRAVEL_IN, TRAVEL_OUT), dispatch a relevant event.
240
- this.dispatchEvent({
241
- type: state._event,
242
- // Dont pass viewCoords if the input is only a keyboard input.
243
- viewCoords: mouseButton !== undefined && viewCoords,
244
- direction: state._direction
245
- });
246
- }
247
- }
248
- return this.NONE;
249
- }
250
-
251
- /**
252
- * get the state corresponding to the number of finger on the pad
253
- *
254
- * @param {Number} finger The number of finger
255
- * @return {state} the state corresponding
256
- */
257
- touchToState(finger) {
258
- for (const key of Object.keys(DEFAULT_STATES)) {
259
- const state = this[key];
260
- if (state.enable && finger === state.finger) {
261
- return state;
262
- }
263
- }
264
- return this.NONE;
265
- }
266
-
267
- /**
268
- * Set the current StateControl {@link State} properties to given values.
269
- * @param {Object} options Object containing the `State` values to set current `StateControl` properties to.
270
- * The `enable` property do not necessarily need to be specified. In that case, the
271
- * previous value of this property will be kept for the new {@link State}.
272
- *
273
- * @example
274
- * // Switch bindings for PAN and MOVE_GLOBE actions, and disabling PANORAMIC movement :
275
- * view.controls.states.setFromOptions({
276
- * PAN: {
277
- * mouseButton: itowns.THREE.MOUSE.LEFT,
278
- * },
279
- * MOVE_GLOBE: {
280
- * mouseButton: itowns.THREE.MOUSE.RIGHT,
281
- * },
282
- * PANORAMIC: {
283
- * enable: false,
284
- * },
285
- * };
286
- */
287
- setFromOptions(options) {
288
- for (const state in DEFAULT_STATES) {
289
- if ({}.hasOwnProperty.call(DEFAULT_STATES, state)) {
290
- let newState = {};
291
- newState = options[state] || this[state] || Object.assign(newState, DEFAULT_STATES[state]);
292
-
293
- // Copy the previous value of `enable` property if not defined in options
294
- if (options[state] && options[state].enable === undefined) {
295
- newState.enable = this[state].enable;
296
- }
297
- // If no value is provided for the `double` property,
298
- // defaults it to `false` instead of leaving it undefined
299
- newState.double = !!newState.double;
300
-
301
- // Copy the `_event` and `_trigger` properties
302
- newState._event = DEFAULT_STATES[state]._event;
303
- newState._trigger = DEFAULT_STATES[state]._trigger;
304
- newState._direction = DEFAULT_STATES[state]._direction;
305
- this[state] = newState;
306
- }
307
- }
308
- }
309
-
310
- // ---------- POINTER EVENTS : ----------
311
-
312
- onPointerDown(event) {
313
- if (!this.enabled) {
314
- return;
315
- }
316
- viewCoords.copy(this._view.eventToViewCoords(event));
317
- switch (event.pointerType) {
318
- case 'mouse':
319
- {
320
- this._currentMousePressed = event.button;
321
- if (this._currentKeyPressed === undefined) {
322
- if (event.ctrlKey) {
323
- this._currentKeyPressed = CONTROL_KEYS.CTRL;
324
- } else if (event.shiftKey) {
325
- this._currentKeyPressed = CONTROL_KEYS.SHIFT;
326
- } else if (event.metaKey) {
327
- this._currentKeyPressed = CONTROL_KEYS.META;
328
- }
329
- }
330
- this.currentState = this.inputToState(this._currentMousePressed, this._currentKeyPressed,
331
- // Detect if the mouse button was pressed less than 500 ms before, and if the cursor has not moved two much
332
- // since previous click. If so, set dblclick to true.
333
- event.timeStamp - this._clickTimeStamp < 500 && this._lastMousePressed.button === this._currentMousePressed && this._lastMousePressed.viewCoords.distanceTo(viewCoords) < 5);
334
- this._clickTimeStamp = event.timeStamp;
335
- this._lastMousePressed.button = this._currentMousePressed;
336
- this._lastMousePressed.viewCoords.copy(viewCoords);
337
- break;
338
- }
339
- // TODO : add touch event management
340
- default:
341
- }
342
- this._domElement.addEventListener('pointermove', this._onPointerMove, false);
343
- this._domElement.addEventListener('pointerup', this._onPointerUp, false);
344
- this._domElement.addEventListener('mouseleave', this._onPointerUp, false);
345
- }
346
- onPointerMove(event) {
347
- event.preventDefault();
348
- if (!this.enabled) {
349
- return;
350
- }
351
- viewCoords.copy(this._view.eventToViewCoords(event));
352
- switch (event.pointerType) {
353
- case 'mouse':
354
- this.dispatchEvent({
355
- type: this.currentState._event,
356
- viewCoords
357
- });
358
- break;
359
- // TODO : add touch event management
360
- default:
361
- }
362
- }
363
- onPointerUp() {
364
- if (!this.enabled) {
365
- return;
366
- }
367
- this._currentMousePressed = undefined;
368
- this._domElement.removeEventListener('pointermove', this._onPointerMove, false);
369
- this._domElement.removeEventListener('pointerup', this._onPointerUp, false);
370
- this._domElement.removeEventListener('mouseleave', this._onPointerUp, false);
371
- this.currentState = this.NONE;
372
- }
373
-
374
- // ---------- WHEEL EVENT : ----------
375
-
376
- onMouseWheel(event) {
377
- event.preventDefault();
378
- if (this.enabled && this.ZOOM.enable) {
379
- viewCoords.copy(this._view.eventToViewCoords(event));
380
- this.currentState = this.ZOOM;
381
- this.dispatchEvent({
382
- type: this.ZOOM._event,
383
- delta: event.deltaY,
384
- viewCoords
385
- });
386
- }
387
- }
388
-
389
- // ---------- KEYBOARD EVENTS : ----------
390
-
391
- onKeyDown(event) {
392
- if (!this.enabled || !this.enableKeys) {
393
- return;
394
- }
395
- this._currentKeyPressed = event.keyCode;
396
- this.inputToState(this._currentMousePressed, this._currentKeyPressed);
397
- }
398
- onKeyUp() {
399
- if (!this.enabled || !this.enableKeys) {
400
- return;
401
- }
402
- this._currentKeyPressed = undefined;
403
- if (this._currentMousePressed === undefined) {
404
- this.currentState = this.NONE;
405
- }
406
- }
407
- onBlur() {
408
- this.onKeyUp();
409
- this.onPointerUp();
410
- }
411
- onContextMenu(event) {
412
- event.preventDefault();
413
- }
414
-
415
- /**
416
- * Remove all event listeners created within this instance of `StateControl`
417
- */
418
- dispose() {
419
- this._clickTimeStamp = 0;
420
- this._lastMousePressed = undefined;
421
- this._currentKeyPressed = undefined;
422
- this._domElement.removeEventListener('pointerdown', this._onPointerDown, false);
423
- this._domElement.removeEventListener('pointermove', this._onPointerMove, false);
424
- this._domElement.removeEventListener('pointerup', this._onPointerUp, false);
425
- this._domElement.removeEventListener('wheel', this._onMouseWheel, false);
426
- this._domElement.removeEventListener('keydown', this._onKeyDown, false);
427
- this._domElement.removeEventListener('keyup', this._onKeyUp, false);
428
- this._domElement.removeEventListener('blur', this._onBlur);
429
- this._domElement.removeEventListener('contextmenu', this._onContextMenu, false);
430
- }
431
- }
432
- export default StateControl;