@antv/l7-map 2.21.0 → 2.21.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 (158) hide show
  1. package/es/camera.js +595 -674
  2. package/es/earthmap.js +313 -276
  3. package/es/geo/edge_insets.js +57 -72
  4. package/es/geo/lng_lat.js +50 -64
  5. package/es/geo/lng_lat_bounds.js +101 -137
  6. package/es/geo/mercator.js +23 -35
  7. package/es/geo/point.js +150 -221
  8. package/es/geo/simple.js +22 -34
  9. package/es/geo/transform.js +839 -905
  10. package/es/handler/blockable_map_event.js +46 -66
  11. package/es/handler/box_zoom.js +125 -143
  12. package/es/handler/click_zoom.js +37 -51
  13. package/es/handler/events/event.js +11 -9
  14. package/es/handler/events/map_mouse_event.js +39 -54
  15. package/es/handler/events/map_touch_event.js +54 -73
  16. package/es/handler/events/map_wheel_event.js +22 -38
  17. package/es/handler/events/render_event.js +6 -23
  18. package/es/handler/handler_inertia.js +98 -113
  19. package/es/handler/handler_manager.js +349 -437
  20. package/es/handler/handler_util.js +2 -2
  21. package/es/handler/keyboard.js +98 -110
  22. package/es/handler/map_event.js +81 -117
  23. package/es/handler/mouse/mouse_handler.js +81 -100
  24. package/es/handler/mouse/mousepan_handler.js +16 -39
  25. package/es/handler/mouse/mousepitch_hander.js +18 -40
  26. package/es/handler/mouse/mouserotate_hander.js +18 -40
  27. package/es/handler/mouse/util.js +7 -6
  28. package/es/handler/scroll_zoom.js +221 -231
  29. package/es/handler/shim/dblclick_zoom.js +36 -47
  30. package/es/handler/shim/drag_pan.js +41 -50
  31. package/es/handler/shim/drag_rotate.js +38 -48
  32. package/es/handler/shim/touch_zoom_rotate.js +68 -79
  33. package/es/handler/tap/single_tap_recognizer.js +60 -80
  34. package/es/handler/tap/tap_drag_zoom.js +72 -89
  35. package/es/handler/tap/tap_recognizer.js +37 -45
  36. package/es/handler/tap/tap_zoom.js +67 -95
  37. package/es/handler/touch/touch_pan.js +77 -96
  38. package/es/handler/touch/touch_pitch.js +61 -79
  39. package/es/handler/touch/touch_rotate.js +47 -67
  40. package/es/handler/touch/touch_zoom.js +29 -46
  41. package/es/handler/touch/two_touch.js +79 -104
  42. package/es/hash.js +75 -88
  43. package/es/map.js +318 -284
  44. package/es/util.js +18 -37
  45. package/es/utils/Aabb.js +60 -100
  46. package/es/utils/dom.js +32 -55
  47. package/es/utils/performance.js +25 -29
  48. package/es/utils/primitives.js +33 -43
  49. package/es/utils/task_queue.js +47 -76
  50. package/lib/camera.d.ts +86 -0
  51. package/lib/camera.js +597 -672
  52. package/lib/earthmap.d.ts +69 -0
  53. package/lib/earthmap.js +314 -276
  54. package/lib/geo/edge_insets.d.ts +54 -0
  55. package/lib/geo/edge_insets.js +58 -70
  56. package/lib/geo/lng_lat.d.ts +18 -0
  57. package/lib/geo/lng_lat.js +50 -62
  58. package/lib/geo/lng_lat_bounds.d.ts +25 -0
  59. package/lib/geo/lng_lat_bounds.js +102 -136
  60. package/lib/geo/mercator.d.ts +30 -0
  61. package/lib/geo/mercator.js +26 -37
  62. package/lib/geo/point.d.ts +40 -0
  63. package/lib/geo/point.js +151 -220
  64. package/lib/geo/simple.d.ts +30 -0
  65. package/lib/geo/simple.js +25 -36
  66. package/lib/geo/transform.d.ts +198 -0
  67. package/lib/geo/transform.js +844 -907
  68. package/lib/handler/IHandler.d.ts +34 -0
  69. package/lib/handler/blockable_map_event.d.ts +17 -0
  70. package/lib/handler/blockable_map_event.js +48 -65
  71. package/lib/handler/box_zoom.d.ts +59 -0
  72. package/lib/handler/box_zoom.js +126 -143
  73. package/lib/handler/click_zoom.d.ts +16 -0
  74. package/lib/handler/click_zoom.js +38 -50
  75. package/lib/handler/events/event.d.ts +4 -0
  76. package/lib/handler/events/event.js +12 -9
  77. package/lib/handler/events/index.d.ts +4 -0
  78. package/lib/handler/events/index.js +3 -3
  79. package/lib/handler/events/map_mouse_event.d.ts +34 -0
  80. package/lib/handler/events/map_mouse_event.js +41 -52
  81. package/lib/handler/events/map_touch_event.d.ts +57 -0
  82. package/lib/handler/events/map_touch_event.js +56 -71
  83. package/lib/handler/events/map_wheel_event.d.ts +33 -0
  84. package/lib/handler/events/map_wheel_event.js +23 -37
  85. package/lib/handler/events/render_event.d.ts +5 -0
  86. package/lib/handler/events/render_event.js +7 -22
  87. package/lib/handler/handler_inertia.d.ts +23 -0
  88. package/lib/handler/handler_inertia.js +102 -112
  89. package/lib/handler/handler_manager.d.ts +61 -0
  90. package/lib/handler/handler_manager.js +351 -437
  91. package/lib/handler/handler_util.d.ts +4 -0
  92. package/lib/handler/handler_util.js +2 -2
  93. package/lib/handler/keyboard.d.ts +36 -0
  94. package/lib/handler/keyboard.js +98 -110
  95. package/lib/handler/map_event.d.ts +29 -0
  96. package/lib/handler/map_event.js +83 -116
  97. package/lib/handler/mouse/index.d.ts +4 -0
  98. package/lib/handler/mouse/index.js +3 -3
  99. package/lib/handler/mouse/mouse_handler.d.ts +22 -0
  100. package/lib/handler/mouse/mouse_handler.js +83 -99
  101. package/lib/handler/mouse/mousepan_handler.d.ts +10 -0
  102. package/lib/handler/mouse/mousepan_handler.js +19 -38
  103. package/lib/handler/mouse/mousepitch_hander.d.ts +9 -0
  104. package/lib/handler/mouse/mousepitch_hander.js +21 -39
  105. package/lib/handler/mouse/mouserotate_hander.d.ts +9 -0
  106. package/lib/handler/mouse/mouserotate_hander.js +21 -39
  107. package/lib/handler/mouse/util.d.ts +6 -0
  108. package/lib/handler/mouse/util.js +7 -7
  109. package/lib/handler/scroll_zoom.d.ts +93 -0
  110. package/lib/handler/scroll_zoom.js +221 -231
  111. package/lib/handler/shim/dblclick_zoom.d.ts +40 -0
  112. package/lib/handler/shim/dblclick_zoom.js +37 -46
  113. package/lib/handler/shim/drag_pan.d.ts +61 -0
  114. package/lib/handler/shim/drag_pan.js +42 -49
  115. package/lib/handler/shim/drag_rotate.d.ts +46 -0
  116. package/lib/handler/shim/drag_rotate.js +39 -47
  117. package/lib/handler/shim/touch_zoom_rotate.d.ts +70 -0
  118. package/lib/handler/shim/touch_zoom_rotate.js +69 -78
  119. package/lib/handler/tap/single_tap_recognizer.d.ts +20 -0
  120. package/lib/handler/tap/single_tap_recognizer.js +63 -79
  121. package/lib/handler/tap/tap_drag_zoom.d.ts +22 -0
  122. package/lib/handler/tap/tap_drag_zoom.js +74 -88
  123. package/lib/handler/tap/tap_recognizer.d.ts +17 -0
  124. package/lib/handler/tap/tap_recognizer.js +41 -47
  125. package/lib/handler/tap/tap_zoom.d.ts +22 -0
  126. package/lib/handler/tap/tap_zoom.js +69 -94
  127. package/lib/handler/touch/index.d.ts +5 -0
  128. package/lib/handler/touch/index.js +4 -4
  129. package/lib/handler/touch/touch_pan.d.ts +30 -0
  130. package/lib/handler/touch/touch_pan.js +79 -95
  131. package/lib/handler/touch/touch_pitch.d.ts +13 -0
  132. package/lib/handler/touch/touch_pitch.js +64 -78
  133. package/lib/handler/touch/touch_rotate.d.ts +12 -0
  134. package/lib/handler/touch/touch_rotate.js +50 -66
  135. package/lib/handler/touch/touch_zoom.d.ts +12 -0
  136. package/lib/handler/touch/touch_zoom.js +32 -45
  137. package/lib/handler/touch/two_touch.d.ts +23 -0
  138. package/lib/handler/touch/two_touch.js +81 -103
  139. package/lib/hash.d.ts +14 -0
  140. package/lib/hash.js +75 -88
  141. package/lib/index.d.ts +4 -0
  142. package/lib/index.js +4 -4
  143. package/lib/interface.d.ts +34 -0
  144. package/lib/map.d.ts +70 -0
  145. package/lib/map.js +319 -284
  146. package/lib/util.d.ts +25 -0
  147. package/lib/util.js +20 -36
  148. package/lib/utils/Aabb.d.ts +12 -0
  149. package/lib/utils/Aabb.js +61 -99
  150. package/lib/utils/dom.d.ts +4 -0
  151. package/lib/utils/dom.js +34 -55
  152. package/lib/utils/performance.d.ts +17 -0
  153. package/lib/utils/performance.js +25 -29
  154. package/lib/utils/primitives.d.ts +6 -0
  155. package/lib/utils/primitives.js +34 -42
  156. package/lib/utils/task_queue.d.ts +13 -0
  157. package/lib/utils/task_queue.js +47 -76
  158. package/package.json +25 -32
@@ -0,0 +1,34 @@
1
+ import type { EarthMap } from '../earthmap';
2
+ import type Point from '../geo/point';
3
+ import type { Map } from '../map';
4
+ export interface IHandlerResult {
5
+ panDelta?: Point;
6
+ zoomDelta?: number;
7
+ bearingDelta?: number;
8
+ pitchDelta?: number;
9
+ around?: Point | null;
10
+ pinchAround?: Point | null;
11
+ cameraAnimation?: (map: Map | EarthMap) => any;
12
+ originalEvent?: any;
13
+ needsRenderFrame?: boolean;
14
+ noInertia?: boolean;
15
+ }
16
+ export interface IHandler {
17
+ touchstart?: (e: TouchEvent, points: Point[], mapTouches: Touch[]) => IHandlerResult | void;
18
+ touchmove?: (e: TouchEvent, points: Point[], mapTouches: Touch[]) => IHandlerResult | void;
19
+ touchend?: (e: TouchEvent, points: Point[], mapTouches: Touch[]) => IHandlerResult | void;
20
+ touchcancel?: (e: TouchEvent, points: Point[], mapTouches: Touch[]) => IHandlerResult | void;
21
+ mousedown?: (e: MouseEvent, point: Point) => IHandlerResult | void;
22
+ mousemove?: (e: MouseEvent, point: Point) => IHandlerResult | void;
23
+ mouseup?: (e: MouseEvent, point: Point) => IHandlerResult | void;
24
+ dblclick?: (e: MouseEvent, point: Point) => IHandlerResult | void;
25
+ wheel?: (e: WheelEvent, point: Point) => IHandlerResult | void;
26
+ keydown?: (e: KeyboardEvent) => IHandlerResult | void;
27
+ keyup?: (e: KeyboardEvent) => IHandlerResult | void;
28
+ renderFrame?: () => IHandlerResult | void;
29
+ enable(options?: any): void;
30
+ disable(): void;
31
+ isEnabled(): boolean;
32
+ isActive(): boolean;
33
+ reset(): void;
34
+ }
@@ -0,0 +1,17 @@
1
+ import type { EarthMap } from '../earthmap';
2
+ import type { Map } from '../map';
3
+ export default class BlockableMapEventHandler {
4
+ private map;
5
+ private delayContextMenu;
6
+ private contextMenuEvent;
7
+ constructor(map: Map | EarthMap);
8
+ reset(): void;
9
+ mousemove(e: MouseEvent): void;
10
+ mousedown(): void;
11
+ mouseup(): void;
12
+ contextmenu(e: MouseEvent): void;
13
+ isEnabled(): boolean;
14
+ isActive(): boolean;
15
+ enable(): boolean;
16
+ disable(): boolean;
17
+ }
@@ -5,79 +5,62 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
9
  var _events = require("./events");
11
10
  // @ts-ignore
12
- var BlockableMapEventHandler = exports.default = /*#__PURE__*/function () {
13
- function BlockableMapEventHandler(map) {
14
- (0, _classCallCheck2.default)(this, BlockableMapEventHandler);
11
+
12
+ class BlockableMapEventHandler {
13
+ constructor(map) {
14
+ (0, _defineProperty2.default)(this, "map", void 0);
15
+ (0, _defineProperty2.default)(this, "delayContextMenu", void 0);
16
+ (0, _defineProperty2.default)(this, "contextMenuEvent", void 0);
15
17
  this.map = map;
16
18
  }
17
- (0, _createClass2.default)(BlockableMapEventHandler, [{
18
- key: "reset",
19
- value: function reset() {
20
- this.delayContextMenu = false;
19
+ reset() {
20
+ this.delayContextMenu = false;
21
+ // @ts-ignore
22
+ delete this.contextMenuEvent;
23
+ }
24
+ mousemove(e) {
25
+ // mousemove map events should not be fired when interaction handlers (pan, rotate, etc) are active
26
+ this.map.emit(e.type, new _events.MapMouseEvent(e.type, this.map, e));
27
+ }
28
+ mousedown() {
29
+ this.delayContextMenu = true;
30
+ }
31
+ mouseup() {
32
+ this.delayContextMenu = false;
33
+ if (this.contextMenuEvent) {
34
+ this.map.emit('contextmenu', new _events.MapMouseEvent('contextmenu', this.map, this.contextMenuEvent));
21
35
  // @ts-ignore
22
36
  delete this.contextMenuEvent;
23
37
  }
24
- }, {
25
- key: "mousemove",
26
- value: function mousemove(e) {
27
- // mousemove map events should not be fired when interaction handlers (pan, rotate, etc) are active
38
+ }
39
+ contextmenu(e) {
40
+ if (this.delayContextMenu) {
41
+ // Mac: contextmenu fired on mousedown; we save it until mouseup for consistency's sake
42
+ this.contextMenuEvent = e;
43
+ } else {
44
+ // Windows: contextmenu fired on mouseup, so fire event now
28
45
  this.map.emit(e.type, new _events.MapMouseEvent(e.type, this.map, e));
29
46
  }
30
- }, {
31
- key: "mousedown",
32
- value: function mousedown() {
33
- this.delayContextMenu = true;
34
- }
35
- }, {
36
- key: "mouseup",
37
- value: function mouseup() {
38
- this.delayContextMenu = false;
39
- if (this.contextMenuEvent) {
40
- this.map.emit('contextmenu', new _events.MapMouseEvent('contextmenu', this.map, this.contextMenuEvent));
41
- // @ts-ignore
42
- delete this.contextMenuEvent;
43
- }
44
- }
45
- }, {
46
- key: "contextmenu",
47
- value: function contextmenu(e) {
48
- if (this.delayContextMenu) {
49
- // Mac: contextmenu fired on mousedown; we save it until mouseup for consistency's sake
50
- this.contextMenuEvent = e;
51
- } else {
52
- // Windows: contextmenu fired on mouseup, so fire event now
53
- this.map.emit(e.type, new _events.MapMouseEvent(e.type, this.map, e));
54
- }
55
47
 
56
- // prevent browser context menu when necessary
57
- if (this.map.listeners('contextmenu')) {
58
- e.preventDefault();
59
- }
60
- }
61
- }, {
62
- key: "isEnabled",
63
- value: function isEnabled() {
64
- return true;
48
+ // prevent browser context menu when necessary
49
+ if (this.map.listeners('contextmenu')) {
50
+ e.preventDefault();
65
51
  }
66
- }, {
67
- key: "isActive",
68
- value: function isActive() {
69
- return false;
70
- }
71
- }, {
72
- key: "enable",
73
- value: function enable() {
74
- return true;
75
- }
76
- }, {
77
- key: "disable",
78
- value: function disable() {
79
- return false;
80
- }
81
- }]);
82
- return BlockableMapEventHandler;
83
- }();
52
+ }
53
+ isEnabled() {
54
+ return true;
55
+ }
56
+ isActive() {
57
+ return false;
58
+ }
59
+ enable() {
60
+ return true;
61
+ }
62
+ disable() {
63
+ return false;
64
+ }
65
+ }
66
+ exports.default = BlockableMapEventHandler;
@@ -0,0 +1,59 @@
1
+ import type { EarthMap } from '../earthmap';
2
+ import type Point from '../geo/point';
3
+ import type { Map } from '../map';
4
+ /**
5
+ * The `BoxZoomHandler` allows the user to zoom the map to fit within a bounding box.
6
+ * The bounding box is defined by clicking and holding `shift` while dragging the cursor.
7
+ */
8
+ declare class BoxZoomHandler {
9
+ private map;
10
+ private el;
11
+ private container;
12
+ private enabled;
13
+ private active;
14
+ private startPos;
15
+ private lastPos;
16
+ private box;
17
+ private clickTolerance;
18
+ /**
19
+ * @private
20
+ */
21
+ constructor(map: Map | EarthMap, options: {
22
+ clickTolerance: number;
23
+ });
24
+ /**
25
+ * Returns a Boolean indicating whether the "box zoom" interaction is enabled.
26
+ *
27
+ * @returns {boolean} `true` if the "box zoom" interaction is enabled.
28
+ */
29
+ isEnabled(): boolean;
30
+ /**
31
+ * Returns a Boolean indicating whether the "box zoom" interaction is active, i.e. currently being used.
32
+ *
33
+ * @returns {boolean} `true` if the "box zoom" interaction is active.
34
+ */
35
+ isActive(): boolean;
36
+ /**
37
+ * Enables the "box zoom" interaction.
38
+ *
39
+ * @example
40
+ * map.boxZoom.enable();
41
+ */
42
+ enable(): void;
43
+ /**
44
+ * Disables the "box zoom" interaction.
45
+ *
46
+ * @example
47
+ * map.boxZoom.disable();
48
+ */
49
+ disable(): void;
50
+ mousedown(e: MouseEvent, point: Point): void;
51
+ mousemoveWindow(e: MouseEvent, point: Point): void;
52
+ mouseupWindow(e: MouseEvent, point: Point): {
53
+ cameraAnimation: (map: Map) => boolean | Map;
54
+ } | undefined;
55
+ keydown(e: KeyboardEvent): void;
56
+ reset(): void;
57
+ fireEvent(type: string, e: any): boolean;
58
+ }
59
+ export default BoxZoomHandler;
@@ -5,21 +5,29 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
9
  var _dom = _interopRequireDefault(require("../utils/dom"));
11
10
  var _event = require("./events/event");
12
11
  // @ts-ignore
12
+
13
13
  /**
14
14
  * The `BoxZoomHandler` allows the user to zoom the map to fit within a bounding box.
15
15
  * The bounding box is defined by clicking and holding `shift` while dragging the cursor.
16
16
  */
17
- var BoxZoomHandler = /*#__PURE__*/function () {
17
+ class BoxZoomHandler {
18
18
  /**
19
19
  * @private
20
20
  */
21
- function BoxZoomHandler(map, options) {
22
- (0, _classCallCheck2.default)(this, BoxZoomHandler);
21
+ constructor(map, options) {
22
+ (0, _defineProperty2.default)(this, "map", void 0);
23
+ (0, _defineProperty2.default)(this, "el", void 0);
24
+ (0, _defineProperty2.default)(this, "container", void 0);
25
+ (0, _defineProperty2.default)(this, "enabled", void 0);
26
+ (0, _defineProperty2.default)(this, "active", void 0);
27
+ (0, _defineProperty2.default)(this, "startPos", void 0);
28
+ (0, _defineProperty2.default)(this, "lastPos", void 0);
29
+ (0, _defineProperty2.default)(this, "box", void 0);
30
+ (0, _defineProperty2.default)(this, "clickTolerance", void 0);
23
31
  this.map = map;
24
32
  this.el = map.getCanvasContainer();
25
33
  this.container = map.getContainer();
@@ -31,155 +39,130 @@ var BoxZoomHandler = /*#__PURE__*/function () {
31
39
  *
32
40
  * @returns {boolean} `true` if the "box zoom" interaction is enabled.
33
41
  */
34
- (0, _createClass2.default)(BoxZoomHandler, [{
35
- key: "isEnabled",
36
- value: function isEnabled() {
37
- return !!this.enabled;
38
- }
42
+ isEnabled() {
43
+ return !!this.enabled;
44
+ }
39
45
 
40
- /**
41
- * Returns a Boolean indicating whether the "box zoom" interaction is active, i.e. currently being used.
42
- *
43
- * @returns {boolean} `true` if the "box zoom" interaction is active.
44
- */
45
- }, {
46
- key: "isActive",
47
- value: function isActive() {
48
- return !!this.active;
49
- }
46
+ /**
47
+ * Returns a Boolean indicating whether the "box zoom" interaction is active, i.e. currently being used.
48
+ *
49
+ * @returns {boolean} `true` if the "box zoom" interaction is active.
50
+ */
51
+ isActive() {
52
+ return !!this.active;
53
+ }
50
54
 
51
- /**
52
- * Enables the "box zoom" interaction.
53
- *
54
- * @example
55
- * map.boxZoom.enable();
56
- */
57
- }, {
58
- key: "enable",
59
- value: function enable() {
60
- if (this.isEnabled()) {
61
- return;
62
- }
63
- this.enabled = true;
55
+ /**
56
+ * Enables the "box zoom" interaction.
57
+ *
58
+ * @example
59
+ * map.boxZoom.enable();
60
+ */
61
+ enable() {
62
+ if (this.isEnabled()) {
63
+ return;
64
64
  }
65
+ this.enabled = true;
66
+ }
65
67
 
66
- /**
67
- * Disables the "box zoom" interaction.
68
- *
69
- * @example
70
- * map.boxZoom.disable();
71
- */
72
- }, {
73
- key: "disable",
74
- value: function disable() {
75
- if (!this.isEnabled()) {
76
- return;
77
- }
78
- this.enabled = false;
68
+ /**
69
+ * Disables the "box zoom" interaction.
70
+ *
71
+ * @example
72
+ * map.boxZoom.disable();
73
+ */
74
+ disable() {
75
+ if (!this.isEnabled()) {
76
+ return;
79
77
  }
80
- }, {
81
- key: "mousedown",
82
- value: function mousedown(e, point) {
83
- if (!this.isEnabled()) {
84
- return;
85
- }
86
- if (!(e.shiftKey && e.button === 0)) {
87
- return;
88
- }
89
- _dom.default.disableDrag();
90
- this.startPos = this.lastPos = point;
91
- this.active = true;
78
+ this.enabled = false;
79
+ }
80
+ mousedown(e, point) {
81
+ if (!this.isEnabled()) {
82
+ return;
92
83
  }
93
- }, {
94
- key: "mousemoveWindow",
95
- value: function mousemoveWindow(e, point) {
96
- if (!this.active) {
97
- return;
98
- }
99
- var pos = point;
100
- if (this.lastPos.equals(pos) || !this.box && pos.dist(this.startPos) < this.clickTolerance) {
101
- return;
102
- }
103
- var p0 = this.startPos;
104
- this.lastPos = pos;
105
- if (!this.box) {
106
- this.box = _dom.default.create('div', 'l7-boxzoom', this.container);
107
- this.container.classList.add('l7-crosshair');
108
- this.fireEvent('boxzoomstart', e);
109
- }
110
- var minX = Math.min(p0.x, pos.x);
111
- var maxX = Math.max(p0.x, pos.x);
112
- var minY = Math.min(p0.y, pos.y);
113
- var maxY = Math.max(p0.y, pos.y);
114
- _dom.default.setTransform(this.box, "translate(".concat(minX, "px,").concat(minY, "px)"));
115
- if (this.box) {
116
- this.box.style.width = "".concat(maxX - minX, "px");
117
- this.box.style.height = "".concat(maxY - minY, "px");
118
- }
84
+ if (!(e.shiftKey && e.button === 0)) {
85
+ return;
119
86
  }
120
- }, {
121
- key: "mouseupWindow",
122
- value: function mouseupWindow(e, point) {
123
- var _this = this;
124
- if (!this.active) {
125
- return;
126
- }
127
- if (e.button !== 0) {
128
- return;
129
- }
130
- var p0 = this.startPos;
131
- var p1 = point;
132
- this.reset();
133
- _dom.default.suppressClick();
134
- if (p0.x === p1.x && p0.y === p1.y) {
135
- this.fireEvent('boxzoomcancel', e);
136
- } else {
137
- this.map.emit('boxzoomend', new _event.Event('boxzoomend', {
138
- originalEvent: e
139
- }));
140
- return {
141
- cameraAnimation: function cameraAnimation(map) {
142
- return map.fitScreenCoordinates(p0, p1, _this.map.getBearing(), {
143
- linear: true
144
- });
145
- }
146
- };
147
- }
87
+ _dom.default.disableDrag();
88
+ this.startPos = this.lastPos = point;
89
+ this.active = true;
90
+ }
91
+ mousemoveWindow(e, point) {
92
+ if (!this.active) {
93
+ return;
94
+ }
95
+ const pos = point;
96
+ if (this.lastPos.equals(pos) || !this.box && pos.dist(this.startPos) < this.clickTolerance) {
97
+ return;
148
98
  }
149
- }, {
150
- key: "keydown",
151
- value: function keydown(e) {
152
- if (!this.active) {
153
- return;
154
- }
155
- if (e.keyCode === 27) {
156
- this.reset();
157
- this.fireEvent('boxzoomcancel', e);
158
- }
99
+ const p0 = this.startPos;
100
+ this.lastPos = pos;
101
+ if (!this.box) {
102
+ this.box = _dom.default.create('div', 'l7-boxzoom', this.container);
103
+ this.container.classList.add('l7-crosshair');
104
+ this.fireEvent('boxzoomstart', e);
159
105
  }
160
- }, {
161
- key: "reset",
162
- value: function reset() {
163
- this.active = false;
164
- this.container.classList.remove('l7-crosshair');
165
- if (this.box) {
166
- _dom.default.remove(this.box);
167
- this.box = null;
168
- }
169
- _dom.default.enableDrag();
170
- // @ts-ignore
171
- delete this.startPos;
172
- // @ts-ignore
173
- delete this.lastPos;
106
+ const minX = Math.min(p0.x, pos.x);
107
+ const maxX = Math.max(p0.x, pos.x);
108
+ const minY = Math.min(p0.y, pos.y);
109
+ const maxY = Math.max(p0.y, pos.y);
110
+ _dom.default.setTransform(this.box, `translate(${minX}px,${minY}px)`);
111
+ if (this.box) {
112
+ this.box.style.width = `${maxX - minX}px`;
113
+ this.box.style.height = `${maxY - minY}px`;
174
114
  }
175
- }, {
176
- key: "fireEvent",
177
- value: function fireEvent(type, e) {
178
- return this.map.emit(type, new _event.Event(type, {
115
+ }
116
+ mouseupWindow(e, point) {
117
+ if (!this.active) {
118
+ return;
119
+ }
120
+ if (e.button !== 0) {
121
+ return;
122
+ }
123
+ const p0 = this.startPos;
124
+ const p1 = point;
125
+ this.reset();
126
+ _dom.default.suppressClick();
127
+ if (p0.x === p1.x && p0.y === p1.y) {
128
+ this.fireEvent('boxzoomcancel', e);
129
+ } else {
130
+ this.map.emit('boxzoomend', new _event.Event('boxzoomend', {
179
131
  originalEvent: e
180
132
  }));
133
+ return {
134
+ cameraAnimation: map => map.fitScreenCoordinates(p0, p1, this.map.getBearing(), {
135
+ linear: true
136
+ })
137
+ };
181
138
  }
182
- }]);
183
- return BoxZoomHandler;
184
- }();
139
+ }
140
+ keydown(e) {
141
+ if (!this.active) {
142
+ return;
143
+ }
144
+ if (e.keyCode === 27) {
145
+ this.reset();
146
+ this.fireEvent('boxzoomcancel', e);
147
+ }
148
+ }
149
+ reset() {
150
+ this.active = false;
151
+ this.container.classList.remove('l7-crosshair');
152
+ if (this.box) {
153
+ _dom.default.remove(this.box);
154
+ this.box = null;
155
+ }
156
+ _dom.default.enableDrag();
157
+ // @ts-ignore
158
+ delete this.startPos;
159
+ // @ts-ignore
160
+ delete this.lastPos;
161
+ }
162
+ fireEvent(type, e) {
163
+ return this.map.emit(type, new _event.Event(type, {
164
+ originalEvent: e
165
+ }));
166
+ }
167
+ }
185
168
  var _default = exports.default = BoxZoomHandler;
@@ -0,0 +1,16 @@
1
+ import type { EarthMap } from '../earthmap';
2
+ import type Point from '../geo/point';
3
+ import type { Map } from '../map';
4
+ export default class ClickZoomHandler {
5
+ private enabled;
6
+ private active;
7
+ constructor();
8
+ reset(): void;
9
+ dblclick(e: MouseEvent, point: Point): {
10
+ cameraAnimation: (map: Map | EarthMap) => void;
11
+ };
12
+ enable(): void;
13
+ disable(): void;
14
+ isEnabled(): boolean;
15
+ isActive(): boolean;
16
+ }
@@ -5,56 +5,44 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
9
  // @ts-ignore
11
- var ClickZoomHandler = exports.default = /*#__PURE__*/function () {
12
- function ClickZoomHandler() {
13
- (0, _classCallCheck2.default)(this, ClickZoomHandler);
10
+
11
+ class ClickZoomHandler {
12
+ constructor() {
13
+ (0, _defineProperty2.default)(this, "enabled", void 0);
14
+ (0, _defineProperty2.default)(this, "active", void 0);
15
+ this.reset();
16
+ }
17
+ reset() {
18
+ this.active = false;
19
+ }
20
+ dblclick(e, point) {
21
+ e.preventDefault();
22
+ return {
23
+ cameraAnimation: map => {
24
+ map.easeTo({
25
+ duration: 300,
26
+ zoom: map.getZoom() + (e.shiftKey ? -1 : 1),
27
+ around: map.unproject(point)
28
+ }, {
29
+ originalEvent: e
30
+ });
31
+ }
32
+ };
33
+ }
34
+ enable() {
35
+ this.enabled = true;
36
+ }
37
+ disable() {
38
+ this.enabled = false;
14
39
  this.reset();
15
40
  }
16
- (0, _createClass2.default)(ClickZoomHandler, [{
17
- key: "reset",
18
- value: function reset() {
19
- this.active = false;
20
- }
21
- }, {
22
- key: "dblclick",
23
- value: function dblclick(e, point) {
24
- e.preventDefault();
25
- return {
26
- cameraAnimation: function cameraAnimation(map) {
27
- map.easeTo({
28
- duration: 300,
29
- zoom: map.getZoom() + (e.shiftKey ? -1 : 1),
30
- around: map.unproject(point)
31
- }, {
32
- originalEvent: e
33
- });
34
- }
35
- };
36
- }
37
- }, {
38
- key: "enable",
39
- value: function enable() {
40
- this.enabled = true;
41
- }
42
- }, {
43
- key: "disable",
44
- value: function disable() {
45
- this.enabled = false;
46
- this.reset();
47
- }
48
- }, {
49
- key: "isEnabled",
50
- value: function isEnabled() {
51
- return this.enabled;
52
- }
53
- }, {
54
- key: "isActive",
55
- value: function isActive() {
56
- return this.active;
57
- }
58
- }]);
59
- return ClickZoomHandler;
60
- }();
41
+ isEnabled() {
42
+ return this.enabled;
43
+ }
44
+ isActive() {
45
+ return this.active;
46
+ }
47
+ }
48
+ exports.default = ClickZoomHandler;
@@ -0,0 +1,4 @@
1
+ export declare class Event {
2
+ type: string;
3
+ constructor(type: string, data?: any);
4
+ }