@antv/l7-scene 2.21.1 → 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.
package/es/boxSelect.js CHANGED
@@ -1,120 +1,104 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
4
- import _inherits from "@babel/runtime/helpers/esm/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
7
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
- import { DOM, getBBoxFromPoints } from '@antv/l7-utils';
11
- import { EventEmitter } from 'eventemitter3';
12
- export var BoxSelectEventList = ['selectstart', 'selecting', 'selectend'];
13
- // TODO: 将 BoxSelect 模块放在哪里比较合适
14
- var BoxSelect = /*#__PURE__*/function (_EventEmitter) {
15
- _inherits(BoxSelect, _EventEmitter);
16
- var _super = _createSuper(BoxSelect);
17
- function BoxSelect(scene) {
18
- var _this;
19
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
20
- _classCallCheck(this, BoxSelect);
21
- _this = _super.call(this);
22
- _defineProperty(_assertThisInitialized(_this), "isEnable", false);
23
- _defineProperty(_assertThisInitialized(_this), "onDragStart", function (e) {
24
- _this.box.style.display = 'block';
25
- _this.startEvent = _this.endEvent = e;
26
- _this.syncBoxBound();
27
- _this.emit('selectstart', _this.getLngLatBox(), _this.startEvent, _this.endEvent);
28
- });
29
- _defineProperty(_assertThisInitialized(_this), "onDragging", function (e) {
30
- _this.endEvent = e;
31
- _this.syncBoxBound();
32
- _this.emit('selecting', _this.getLngLatBox(), _this.startEvent, _this.endEvent);
33
- });
34
- _defineProperty(_assertThisInitialized(_this), "onDragEnd", function (e) {
35
- _this.endEvent = e;
36
- _this.box.style.display = 'none';
37
- _this.emit('selectend', _this.getLngLatBox(), _this.startEvent, _this.endEvent);
38
- });
39
- _this.scene = scene;
40
- _this.options = options;
41
- return _this;
1
+ // src/boxSelect.ts
2
+ import { DOM, getBBoxFromPoints } from "@antv/l7-utils";
3
+ import { EventEmitter } from "eventemitter3";
4
+ var BoxSelectEventList = ["selectstart", "selecting", "selectend"];
5
+ var BoxSelect = class extends EventEmitter {
6
+ constructor(scene, options = {}) {
7
+ super();
8
+ this.isEnable = false;
9
+ this.onDragStart = (e) => {
10
+ this.box.style.display = "block";
11
+ this.startEvent = this.endEvent = e;
12
+ this.syncBoxBound();
13
+ this.emit(
14
+ "selectstart",
15
+ this.getLngLatBox(),
16
+ this.startEvent,
17
+ this.endEvent
18
+ );
19
+ };
20
+ this.onDragging = (e) => {
21
+ this.endEvent = e;
22
+ this.syncBoxBound();
23
+ this.emit("selecting", this.getLngLatBox(), this.startEvent, this.endEvent);
24
+ };
25
+ this.onDragEnd = (e) => {
26
+ this.endEvent = e;
27
+ this.box.style.display = "none";
28
+ this.emit("selectend", this.getLngLatBox(), this.startEvent, this.endEvent);
29
+ };
30
+ this.scene = scene;
31
+ this.options = options;
42
32
  }
43
- _createClass(BoxSelect, [{
44
- key: "container",
45
- get: function get() {
46
- return this.scene.getMapService().getMarkerContainer();
47
- }
48
- }, {
49
- key: "enable",
50
- value: function enable() {
51
- if (this.isEnable) {
52
- return;
53
- }
54
- var className = this.options.className;
55
- this.scene.setMapStatus({
56
- dragEnable: false
57
- });
58
- this.container.style.cursor = 'crosshair';
59
- if (!this.box) {
60
- var box = DOM.create('div', undefined, this.container);
61
- box.classList.add('l7-select-box');
62
- if (className) {
63
- box.classList.add(className);
64
- }
65
- box.style.display = 'none';
66
- this.box = box;
67
- }
68
- this.scene.on('dragstart', this.onDragStart);
69
- this.scene.on('dragging', this.onDragging);
70
- this.scene.on('dragend', this.onDragEnd);
71
- this.isEnable = true;
33
+ get container() {
34
+ return this.scene.getMapService().getMarkerContainer();
35
+ }
36
+ enable() {
37
+ if (this.isEnable) {
38
+ return;
72
39
  }
73
- }, {
74
- key: "disable",
75
- value: function disable() {
76
- if (!this.isEnable) {
77
- return;
40
+ const { className } = this.options;
41
+ this.scene.setMapStatus({
42
+ dragEnable: false
43
+ });
44
+ this.container.style.cursor = "crosshair";
45
+ if (!this.box) {
46
+ const box = DOM.create(
47
+ "div",
48
+ void 0,
49
+ this.container
50
+ );
51
+ box.classList.add("l7-select-box");
52
+ if (className) {
53
+ box.classList.add(className);
78
54
  }
79
- this.scene.setMapStatus({
80
- dragEnable: true
81
- });
82
- this.container.style.cursor = 'auto';
83
- this.scene.off('dragstart', this.onDragStart);
84
- this.scene.off('dragging', this.onDragging);
85
- this.scene.off('dragend', this.onDragEnd);
86
- this.isEnable = false;
87
- }
88
- }, {
89
- key: "syncBoxBound",
90
- value: function syncBoxBound() {
91
- var _this$startEvent = this.startEvent,
92
- x1 = _this$startEvent.x,
93
- y1 = _this$startEvent.y;
94
- var _this$endEvent = this.endEvent,
95
- x2 = _this$endEvent.x,
96
- y2 = _this$endEvent.y;
97
- var left = Math.min(x1, x2);
98
- var top = Math.min(y1, y2);
99
- var width = Math.abs(x1 - x2);
100
- var height = Math.abs(y1 - y2);
101
- this.box.style.top = "".concat(top, "px");
102
- this.box.style.left = "".concat(left, "px");
103
- this.box.style.width = "".concat(width, "px");
104
- this.box.style.height = "".concat(height, "px");
55
+ box.style.display = "none";
56
+ this.box = box;
105
57
  }
106
- }, {
107
- key: "getLngLatBox",
108
- value: function getLngLatBox() {
109
- var _this$startEvent$lngL = this.startEvent.lngLat,
110
- lng1 = _this$startEvent$lngL.lng,
111
- lat1 = _this$startEvent$lngL.lat;
112
- var _this$endEvent$lngLat = this.endEvent.lngLat,
113
- lng2 = _this$endEvent$lngLat.lng,
114
- lat2 = _this$endEvent$lngLat.lat;
115
- return getBBoxFromPoints([[lng1, lat1], [lng2, lat2]]);
58
+ this.scene.on("dragstart", this.onDragStart);
59
+ this.scene.on("dragging", this.onDragging);
60
+ this.scene.on("dragend", this.onDragEnd);
61
+ this.isEnable = true;
62
+ }
63
+ disable() {
64
+ if (!this.isEnable) {
65
+ return;
116
66
  }
117
- }]);
118
- return BoxSelect;
119
- }(EventEmitter);
120
- export { BoxSelect as default };
67
+ this.scene.setMapStatus({
68
+ dragEnable: true
69
+ });
70
+ this.container.style.cursor = "auto";
71
+ this.scene.off("dragstart", this.onDragStart);
72
+ this.scene.off("dragging", this.onDragging);
73
+ this.scene.off("dragend", this.onDragEnd);
74
+ this.isEnable = false;
75
+ }
76
+ syncBoxBound() {
77
+ const { x: x1, y: y1 } = this.startEvent;
78
+ const { x: x2, y: y2 } = this.endEvent;
79
+ const left = Math.min(x1, x2);
80
+ const top = Math.min(y1, y2);
81
+ const width = Math.abs(x1 - x2);
82
+ const height = Math.abs(y1 - y2);
83
+ this.box.style.top = `${top}px`;
84
+ this.box.style.left = `${left}px`;
85
+ this.box.style.width = `${width}px`;
86
+ this.box.style.height = `${height}px`;
87
+ }
88
+ getLngLatBox() {
89
+ const {
90
+ lngLat: { lng: lng1, lat: lat1 }
91
+ } = this.startEvent;
92
+ const {
93
+ lngLat: { lng: lng2, lat: lat2 }
94
+ } = this.endEvent;
95
+ return getBBoxFromPoints([
96
+ [lng1, lat1],
97
+ [lng2, lat2]
98
+ ]);
99
+ }
100
+ };
101
+ export {
102
+ BoxSelectEventList,
103
+ BoxSelect as default
104
+ };