1 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
2 |
|
3 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
4 |
|
5 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
6 |
|
7 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
8 |
|
9 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
10 |
|
11 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
12 |
|
13 | 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); }; }
|
14 |
|
15 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
16 |
|
17 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
18 |
|
19 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
20 |
|
21 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | import { Control, DOM, PositionType } from '@antv/l7';
|
30 | import "./css/draw.css";
|
31 | import { DrawCircle, DrawDelete, DrawLine, DrawPoint, DrawPolygon, DrawRect } from './modes';
|
32 | var DrawType = {
|
33 | point: DrawPoint,
|
34 | line: DrawLine,
|
35 | polygon: DrawPolygon,
|
36 | circle: DrawCircle,
|
37 | rect: DrawRect
|
38 | };
|
39 | import { isObject } from '@turf/helpers';
|
40 | import { DrawEvent, DrawModes } from './util/constant';
|
41 | export var DrawControl = function (_Control) {
|
42 | _inherits(DrawControl, _Control);
|
43 |
|
44 | var _super = _createSuper(DrawControl);
|
45 |
|
46 | function DrawControl(scene, options) {
|
47 | var _this;
|
48 |
|
49 | _classCallCheck(this, DrawControl);
|
50 |
|
51 | _this = _super.call(this, options);
|
52 | _this.draw = {};
|
53 |
|
54 | _this.onButtonClick = function (type, e) {
|
55 | for (var draw in _this.draw) {
|
56 | if (draw === type) {
|
57 | _this.draw[draw].enable();
|
58 | } else {
|
59 | _this.draw[draw].disable();
|
60 | }
|
61 | }
|
62 | };
|
63 |
|
64 | _this.onDeleteMode = function (type, e) {
|
65 | e.stopPropagation();
|
66 |
|
67 | if (!_this.currentDraw) {
|
68 | return;
|
69 | }
|
70 |
|
71 | _this.currentDraw.deleteMode.enable();
|
72 |
|
73 | return false;
|
74 | };
|
75 |
|
76 | _this.onModeChange = function (type, mode) {
|
77 | if (mode === DrawModes.SIMPLE_SELECT) {
|
78 | _this.currentDraw = _this.draw[type];
|
79 | }
|
80 | };
|
81 |
|
82 | _this.scene = scene;
|
83 | return _this;
|
84 | }
|
85 |
|
86 | _createClass(DrawControl, [{
|
87 | key: "getDefault",
|
88 | value: function getDefault() {
|
89 | return {
|
90 | position: PositionType.TOPLEFT,
|
91 | controls: {
|
92 | point: true,
|
93 | line: true,
|
94 | polygon: true,
|
95 | rect: true,
|
96 | circle: true,
|
97 | delete: true
|
98 | },
|
99 | name: 'draw'
|
100 | };
|
101 | }
|
102 | }, {
|
103 | key: "onAdd",
|
104 | value: function onAdd() {
|
105 | var layout = this.controlOption.layout;
|
106 | var controlClass = 'l7-control-draw' + ' ' + layout;
|
107 | var controls = this.controlOption.controls;
|
108 | var container = DOM.create('div', controlClass);
|
109 | this.addControls(controls, container);
|
110 |
|
111 | this.addControlEvent();
|
112 |
|
113 | return container;
|
114 | }
|
115 | }, {
|
116 | key: "onRemove",
|
117 | value: function onRemove() {
|
118 | for (var draw in this.draw) {
|
119 | if (this.draw[draw]) {
|
120 | this.draw[draw].destroy();
|
121 | }
|
122 | }
|
123 | }
|
124 | }, {
|
125 | key: "getDraw",
|
126 | value: function getDraw(type) {
|
127 | var controls = this.controlOption.controls;
|
128 |
|
129 | if (controls[type]) {
|
130 | return this.draw[type];
|
131 | }
|
132 |
|
133 | return null;
|
134 | }
|
135 | }, {
|
136 | key: "getAllData",
|
137 | value: function getAllData() {
|
138 | var res = {};
|
139 |
|
140 | for (var draw in this.draw) {
|
141 | if (this.draw[draw]) {
|
142 | res[draw] = this.draw[draw].getData();
|
143 | }
|
144 | }
|
145 |
|
146 | return res;
|
147 | }
|
148 | }, {
|
149 | key: "removeAllData",
|
150 | value: function removeAllData() {
|
151 | for (var draw in this.draw) {
|
152 | if (this.draw[draw]) {
|
153 | this.draw[draw].removeAllData();
|
154 | }
|
155 | }
|
156 | }
|
157 | }, {
|
158 | key: "addControls",
|
159 | value: function addControls(controls, container) {
|
160 | var style = this.controlOption.style;
|
161 |
|
162 | for (var type in controls) {
|
163 | if (DrawType[type] && controls[type] !== false) {
|
164 | var drawOption = isObject(controls[type]) ? controls[type] : {};
|
165 |
|
166 | if (style) {
|
167 | drawOption.style = style;
|
168 | }
|
169 |
|
170 | var draw = new DrawType[type](this.scene, drawOption);
|
171 | draw.on(DrawEvent.MODE_CHANGE, this.onModeChange.bind(null, type));
|
172 | this.draw[type] = draw;
|
173 | this.createButton(draw.title, 'draw-' + type, container, 'click', this.onButtonClick.bind(null, type));
|
174 | } else if (type === 'delete' && controls[type] !== false) {
|
175 | var _draw = new DrawDelete(this.scene);
|
176 |
|
177 | _draw.on(DrawEvent.MODE_CHANGE, this.onModeChange.bind(null, type));
|
178 |
|
179 | this.createButton(_draw.title, 'draw-' + type, container, 'mousedown', this.onDeleteMode.bind(null, type));
|
180 | }
|
181 | }
|
182 | }
|
183 | }, {
|
184 | key: "addControlEvent",
|
185 | value: function addControlEvent() {
|
186 | var _this2 = this;
|
187 |
|
188 | var _loop = function _loop(draw) {
|
189 | if (_this2.draw[draw]) {
|
190 | ['draw.create', 'draw.update', 'draw.delete'].forEach(function (type) {
|
191 | _this2.draw[draw].on(type, function (feature) {
|
192 | _this2.emit(type, {
|
193 | drawType: draw,
|
194 | feature: feature
|
195 | });
|
196 | });
|
197 | });
|
198 | }
|
199 | };
|
200 |
|
201 | for (var draw in this.draw) {
|
202 | _loop(draw);
|
203 | }
|
204 | }
|
205 | }, {
|
206 | key: "createButton",
|
207 | value: function createButton(tile, className, container, eventType, fn) {
|
208 | var link = DOM.create('button', className, container);
|
209 | link.title = tile;
|
210 | link.addEventListener(eventType, fn, false);
|
211 | return link;
|
212 | }
|
213 | }]);
|
214 |
|
215 | return DrawControl;
|
216 | }(Control); |
\ | No newline at end of file |