MapControls.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { MOUSE, TOUCH } from 'three';
  2. import { OrbitControls } from './OrbitControls.js';
  3. /**
  4. * This class is intended for transforming a camera over a map from bird's eye perspective.
  5. * The class shares its implementation with {@link OrbitControls} but uses a specific preset
  6. * for mouse/touch interaction and disables screen space panning by default.
  7. *
  8. * - Orbit: Right mouse, or left mouse + ctrl/meta/shiftKey / touch: two-finger rotate.
  9. * - Zoom: Middle mouse, or mousewheel / touch: two-finger spread or squish.
  10. * - Pan: Left mouse, or arrow keys / touch: one-finger move.
  11. *
  12. * @augments OrbitControls
  13. * @three_import import { MapControls } from 'three/addons/controls/MapControls.js';
  14. */
  15. class MapControls extends OrbitControls {
  16. constructor( object, domElement ) {
  17. super( object, domElement );
  18. /**
  19. * Overwritten and set to `false` to pan orthogonal to world-space direction `camera.up`.
  20. *
  21. * @type {boolean}
  22. * @default false
  23. */
  24. this.screenSpacePanning = false;
  25. /**
  26. * This object contains references to the mouse actions used by the controls.
  27. *
  28. * ```js
  29. * controls.mouseButtons = {
  30. * LEFT: THREE.MOUSE.PAN,
  31. * MIDDLE: THREE.MOUSE.DOLLY,
  32. * RIGHT: THREE.MOUSE.ROTATE
  33. * }
  34. * ```
  35. * @type {Object}
  36. */
  37. this.mouseButtons = { LEFT: MOUSE.PAN, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.ROTATE };
  38. /**
  39. * This object contains references to the touch actions used by the controls.
  40. *
  41. * ```js
  42. * controls.mouseButtons = {
  43. * ONE: THREE.TOUCH.PAN,
  44. * TWO: THREE.TOUCH.DOLLY_ROTATE
  45. * }
  46. * ```
  47. * @type {Object}
  48. */
  49. this.touches = { ONE: TOUCH.PAN, TWO: TOUCH.DOLLY_ROTATE };
  50. }
  51. }
  52. export { MapControls };