1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
9 |
|
10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11 |
|
12 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
13 |
|
14 | 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); } }
|
15 |
|
16 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
17 |
|
18 | var DrawSource = function () {
|
19 | function DrawSource(data) {
|
20 | _classCallCheck(this, DrawSource);
|
21 |
|
22 | this.data = data || this.getDefaultData();
|
23 | }
|
24 |
|
25 | _createClass(DrawSource, [{
|
26 | key: "addFeature",
|
27 | value: function addFeature(feature) {
|
28 | this.data.features.push(feature);
|
29 | }
|
30 | }, {
|
31 | key: "getData",
|
32 | value: function getData() {
|
33 | var features = (0, _cloneDeep.default)(this.data.features).map(function (feature) {
|
34 | var _feature$properties, _feature$properties2;
|
35 |
|
36 | feature.properties = {
|
37 | id: feature === null || feature === void 0 ? void 0 : (_feature$properties = feature.properties) === null || _feature$properties === void 0 ? void 0 : _feature$properties.id,
|
38 | type: feature === null || feature === void 0 ? void 0 : (_feature$properties2 = feature.properties) === null || _feature$properties2 === void 0 ? void 0 : _feature$properties2.type
|
39 | };
|
40 | return feature;
|
41 | });
|
42 | return {
|
43 | type: 'FeatureCollection',
|
44 | features: features
|
45 | };
|
46 | }
|
47 | }, {
|
48 | key: "getFeature",
|
49 | value: function getFeature(id) {
|
50 | var result = this.data.features.find(function (fe) {
|
51 | var _fe$properties;
|
52 |
|
53 | return (fe === null || fe === void 0 ? void 0 : (_fe$properties = fe.properties) === null || _fe$properties === void 0 ? void 0 : _fe$properties.id) === id;
|
54 | });
|
55 | return result;
|
56 | }
|
57 | }, {
|
58 | key: "removeAllFeatures",
|
59 | value: function removeAllFeatures() {
|
60 | this.data = this.getDefaultData();
|
61 | }
|
62 | }, {
|
63 | key: "removeFeature",
|
64 | value: function removeFeature(feature) {
|
65 | var index = this.getFeatureIndex(feature);
|
66 |
|
67 | if (index !== undefined) {
|
68 | this.data.features.splice(index, 1);
|
69 | }
|
70 | }
|
71 | }, {
|
72 | key: "setFeatureActive",
|
73 | value: function setFeatureActive(feature) {
|
74 | var _feature$properties3;
|
75 |
|
76 | var fe = this.getFeature(feature === null || feature === void 0 ? void 0 : (_feature$properties3 = feature.properties) === null || _feature$properties3 === void 0 ? void 0 : _feature$properties3.id);
|
77 |
|
78 | if (fe && fe.properties) {
|
79 | fe.properties.active = true;
|
80 | }
|
81 | }
|
82 | }, {
|
83 | key: "setFeatureUnActive",
|
84 | value: function setFeatureUnActive(feature) {
|
85 | var _feature$properties4;
|
86 |
|
87 | var fe = this.getFeature(feature === null || feature === void 0 ? void 0 : (_feature$properties4 = feature.properties) === null || _feature$properties4 === void 0 ? void 0 : _feature$properties4.id);
|
88 |
|
89 | if (fe && fe.properties) {
|
90 | fe.properties.active = false;
|
91 | }
|
92 | }
|
93 | }, {
|
94 | key: "clearFeatureActive",
|
95 | value: function clearFeatureActive() {
|
96 | this.data.features.forEach(function (fe) {
|
97 | if (fe && fe.properties) {
|
98 | fe.properties.active = false;
|
99 | }
|
100 | });
|
101 | }
|
102 | }, {
|
103 | key: "updateFeature",
|
104 | value: function updateFeature(feature) {
|
105 | this.removeFeature(feature);
|
106 | this.addFeature(feature);
|
107 | }
|
108 | }, {
|
109 | key: "destroy",
|
110 | value: function destroy() {
|
111 | this.data = this.getDefaultData();
|
112 | }
|
113 | }, {
|
114 | key: "getDefaultData",
|
115 | value: function getDefaultData() {
|
116 | return {
|
117 | type: 'FeatureCollection',
|
118 | features: []
|
119 | };
|
120 | }
|
121 | }, {
|
122 | key: "getFeatureIndex",
|
123 | value: function getFeatureIndex(feature) {
|
124 | return this.data.features.findIndex(function (fe) {
|
125 | var _fe$properties2, _feature$properties5;
|
126 |
|
127 | return (fe === null || fe === void 0 ? void 0 : (_fe$properties2 = fe.properties) === null || _fe$properties2 === void 0 ? void 0 : _fe$properties2.id) === (feature === null || feature === void 0 ? void 0 : (_feature$properties5 = feature.properties) === null || _feature$properties5 === void 0 ? void 0 : _feature$properties5.id);
|
128 | });
|
129 | }
|
130 | }]);
|
131 |
|
132 | return DrawSource;
|
133 | }();
|
134 |
|
135 | exports.default = DrawSource; |
\ | No newline at end of file |