@nocobase/plugin-map 0.11.1-alpha.5 → 0.12.0-alpha.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 (197) hide show
  1. package/client.d.ts +2 -3
  2. package/client.js +1 -1
  3. package/dist/client/index.js +3092 -0
  4. package/{lib → dist}/index.d.ts +1 -0
  5. package/dist/index.js +18 -0
  6. package/dist/locale/en-US.js +6 -0
  7. package/dist/locale/fr-FR.js +6 -0
  8. package/dist/locale/pt-BR.js +51 -0
  9. package/dist/locale/zh-CN.js +54 -0
  10. package/dist/server/actions/index.js +43 -0
  11. package/dist/server/collections/mapConfiguration.js +32 -0
  12. package/dist/server/constants.js +5 -0
  13. package/dist/server/fields/circle.js +47 -0
  14. package/dist/server/fields/index.js +33 -0
  15. package/dist/server/fields/lineString.js +54 -0
  16. package/dist/server/fields/point.js +57 -0
  17. package/dist/server/fields/polygon.js +53 -0
  18. package/dist/server/helpers/index.js +31 -0
  19. package/dist/server/index.js +11 -0
  20. package/dist/server/plugin.js +59 -0
  21. package/dist/server/value-parsers/index.js +53 -0
  22. package/docs/en-US/changelog.md +1 -0
  23. package/docs/en-US/index.md +1 -0
  24. package/docs/en-US/installation.md +1 -0
  25. package/docs/en-US/tabs.json +18 -0
  26. package/docs/en-US/usage.md +1 -0
  27. package/docs/zh-CN/changelog.md +1 -0
  28. package/docs/zh-CN/index.md +1 -0
  29. package/docs/zh-CN/installation.md +1 -0
  30. package/docs/zh-CN/tabs.json +18 -0
  31. package/docs/zh-CN/usage.md +1 -0
  32. package/package.json +19 -30
  33. package/server.d.ts +2 -3
  34. package/server.js +1 -1
  35. package/lib/client/block/MapActionInitializers.js +0 -93
  36. package/lib/client/block/MapBlock.js +0 -38
  37. package/lib/client/block/MapBlockDesigner.js +0 -196
  38. package/lib/client/block/MapBlockInitializer.js +0 -124
  39. package/lib/client/block/MapBlockProvider.js +0 -91
  40. package/lib/client/block/index.js +0 -58
  41. package/lib/client/block/utils.js +0 -102
  42. package/lib/client/components/AMap/Block.js +0 -350
  43. package/lib/client/components/AMap/Map.js +0 -458
  44. package/lib/client/components/AMap/Search.js +0 -121
  45. package/lib/client/components/AMap/index.js +0 -27
  46. package/lib/client/components/Configuration.js +0 -160
  47. package/lib/client/components/Designer.js +0 -167
  48. package/lib/client/components/GoogleMaps/Block.js +0 -370
  49. package/lib/client/components/GoogleMaps/Map.js +0 -466
  50. package/lib/client/components/GoogleMaps/Search.js +0 -128
  51. package/lib/client/components/GoogleMaps/index.js +0 -27
  52. package/lib/client/components/GoogleMaps/utils.js +0 -44
  53. package/lib/client/components/Map.js +0 -50
  54. package/lib/client/components/MapBlock.js +0 -40
  55. package/lib/client/components/MapComponent.js +0 -42
  56. package/lib/client/components/ReadPretty.js +0 -56
  57. package/lib/client/components/index.js +0 -71
  58. package/lib/client/constants.js +0 -19
  59. package/lib/client/fields/circle.js +0 -32
  60. package/lib/client/fields/index.js +0 -17
  61. package/lib/client/fields/lineString.js +0 -32
  62. package/lib/client/fields/point.js +0 -32
  63. package/lib/client/fields/polygon.js +0 -32
  64. package/lib/client/fields/schema.js +0 -64
  65. package/lib/client/hooks/index.js +0 -16
  66. package/lib/client/hooks/useMapConfiguration.js +0 -54
  67. package/lib/client/index.js +0 -73
  68. package/lib/client/initialize.js +0 -50
  69. package/lib/client/locale/index.js +0 -38
  70. package/lib/client/types.js +0 -5
  71. package/lib/client/utils.js +0 -1
  72. package/lib/index.js +0 -13
  73. package/lib/locale/en-US.js +0 -9
  74. package/lib/locale/fr-FR.js +0 -9
  75. package/lib/locale/pt-BR.js +0 -54
  76. package/lib/locale/zh-CN.js +0 -57
  77. package/lib/server/actions/index.js +0 -55
  78. package/lib/server/collections/mapConfiguration.js +0 -30
  79. package/lib/server/constants.js +0 -8
  80. package/lib/server/fields/circle.js +0 -58
  81. package/lib/server/fields/index.js +0 -49
  82. package/lib/server/fields/lineString.js +0 -65
  83. package/lib/server/fields/point.js +0 -68
  84. package/lib/server/fields/polygon.js +0 -64
  85. package/lib/server/helpers/index.js +0 -32
  86. package/lib/server/index.js +0 -13
  87. package/lib/server/plugin.js +0 -79
  88. package/lib/server/value-parsers/index.js +0 -75
  89. package/src/client/block/MapActionInitializers.tsx +0 -97
  90. package/src/client/block/MapBlock.tsx +0 -11
  91. package/src/client/block/MapBlockDesigner.tsx +0 -161
  92. package/src/client/block/MapBlockInitializer.tsx +0 -91
  93. package/src/client/block/MapBlockProvider.tsx +0 -55
  94. package/src/client/block/index.tsx +0 -35
  95. package/src/client/block/utils.ts +0 -81
  96. package/src/client/components/AMap/Block.tsx +0 -314
  97. package/src/client/components/AMap/Map.tsx +0 -461
  98. package/src/client/components/AMap/Search.tsx +0 -92
  99. package/src/client/components/AMap/index.ts +0 -2
  100. package/src/client/components/Configuration.tsx +0 -117
  101. package/src/client/components/Designer.tsx +0 -147
  102. package/src/client/components/GoogleMaps/Block.tsx +0 -341
  103. package/src/client/components/GoogleMaps/Map.tsx +0 -470
  104. package/src/client/components/GoogleMaps/Search.tsx +0 -107
  105. package/src/client/components/GoogleMaps/index.ts +0 -2
  106. package/src/client/components/GoogleMaps/utils.ts +0 -33
  107. package/src/client/components/Map.tsx +0 -33
  108. package/src/client/components/MapBlock.tsx +0 -24
  109. package/src/client/components/MapComponent.tsx +0 -23
  110. package/src/client/components/ReadPretty.tsx +0 -28
  111. package/src/client/components/index.ts +0 -6
  112. package/src/client/constants.ts +0 -11
  113. package/src/client/fields/circle.ts +0 -23
  114. package/src/client/fields/index.ts +0 -11
  115. package/src/client/fields/lineString.ts +0 -23
  116. package/src/client/fields/point.ts +0 -23
  117. package/src/client/fields/polygon.ts +0 -23
  118. package/src/client/fields/schema.ts +0 -54
  119. package/src/client/hooks/index.ts +0 -1
  120. package/src/client/hooks/useMapConfiguration.ts +0 -42
  121. package/src/client/index.tsx +0 -55
  122. package/src/client/initialize.tsx +0 -32
  123. package/src/client/locale/index.ts +0 -19
  124. package/src/client/types.ts +0 -1
  125. package/src/client/utils.ts +0 -0
  126. package/src/index.ts +0 -1
  127. package/src/locale/en-US.ts +0 -3
  128. package/src/locale/fr-FR.ts +0 -3
  129. package/src/locale/pt-BR.ts +0 -51
  130. package/src/locale/zh-CN.ts +0 -52
  131. package/src/server/__tests__/fields.test.ts +0 -157
  132. package/src/server/actions/index.ts +0 -44
  133. package/src/server/collections/mapConfiguration.ts +0 -29
  134. package/src/server/constants.ts +0 -1
  135. package/src/server/fields/.gitkeep +0 -0
  136. package/src/server/fields/circle.ts +0 -48
  137. package/src/server/fields/index.ts +0 -4
  138. package/src/server/fields/lineString.ts +0 -55
  139. package/src/server/fields/point.ts +0 -58
  140. package/src/server/fields/polygon.ts +0 -54
  141. package/src/server/helpers/index.ts +0 -25
  142. package/src/server/index.ts +0 -1
  143. package/src/server/plugin.ts +0 -57
  144. package/src/server/value-parsers/index.ts +0 -55
  145. /package/{lib → dist}/client/block/MapActionInitializers.d.ts +0 -0
  146. /package/{lib → dist}/client/block/MapBlock.d.ts +0 -0
  147. /package/{lib → dist}/client/block/MapBlockDesigner.d.ts +0 -0
  148. /package/{lib → dist}/client/block/MapBlockInitializer.d.ts +0 -0
  149. /package/{lib → dist}/client/block/MapBlockProvider.d.ts +0 -0
  150. /package/{lib → dist}/client/block/index.d.ts +0 -0
  151. /package/{lib → dist}/client/block/utils.d.ts +0 -0
  152. /package/{lib → dist}/client/components/AMap/Block.d.ts +0 -0
  153. /package/{lib → dist}/client/components/AMap/Map.d.ts +0 -0
  154. /package/{lib → dist}/client/components/AMap/Search.d.ts +0 -0
  155. /package/{lib → dist}/client/components/AMap/index.d.ts +0 -0
  156. /package/{lib → dist}/client/components/Configuration.d.ts +0 -0
  157. /package/{lib → dist}/client/components/Designer.d.ts +0 -0
  158. /package/{lib → dist}/client/components/GoogleMaps/Block.d.ts +0 -0
  159. /package/{lib → dist}/client/components/GoogleMaps/Map.d.ts +0 -0
  160. /package/{lib → dist}/client/components/GoogleMaps/Search.d.ts +0 -0
  161. /package/{lib → dist}/client/components/GoogleMaps/index.d.ts +0 -0
  162. /package/{lib → dist}/client/components/GoogleMaps/utils.d.ts +0 -0
  163. /package/{lib → dist}/client/components/Map.d.ts +0 -0
  164. /package/{lib → dist}/client/components/MapBlock.d.ts +0 -0
  165. /package/{lib → dist}/client/components/MapComponent.d.ts +0 -0
  166. /package/{lib → dist}/client/components/ReadPretty.d.ts +0 -0
  167. /package/{lib → dist}/client/components/index.d.ts +0 -0
  168. /package/{lib → dist}/client/constants.d.ts +0 -0
  169. /package/{lib → dist}/client/fields/circle.d.ts +0 -0
  170. /package/{lib → dist}/client/fields/index.d.ts +0 -0
  171. /package/{lib → dist}/client/fields/lineString.d.ts +0 -0
  172. /package/{lib → dist}/client/fields/point.d.ts +0 -0
  173. /package/{lib → dist}/client/fields/polygon.d.ts +0 -0
  174. /package/{lib → dist}/client/fields/schema.d.ts +0 -0
  175. /package/{lib → dist}/client/hooks/index.d.ts +0 -0
  176. /package/{lib → dist}/client/hooks/useMapConfiguration.d.ts +0 -0
  177. /package/{lib → dist}/client/index.d.ts +0 -0
  178. /package/{lib → dist}/client/initialize.d.ts +0 -0
  179. /package/{lib → dist}/client/locale/index.d.ts +0 -0
  180. /package/{lib → dist}/client/types.d.ts +0 -0
  181. /package/{lib → dist}/client/utils.d.ts +0 -0
  182. /package/{lib → dist}/locale/en-US.d.ts +0 -0
  183. /package/{lib → dist}/locale/fr-FR.d.ts +0 -0
  184. /package/{lib → dist}/locale/pt-BR.d.ts +0 -0
  185. /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
  186. /package/{lib → dist}/server/actions/index.d.ts +0 -0
  187. /package/{lib → dist}/server/collections/mapConfiguration.d.ts +0 -0
  188. /package/{lib → dist}/server/constants.d.ts +0 -0
  189. /package/{lib → dist}/server/fields/circle.d.ts +0 -0
  190. /package/{lib → dist}/server/fields/index.d.ts +0 -0
  191. /package/{lib → dist}/server/fields/lineString.d.ts +0 -0
  192. /package/{lib → dist}/server/fields/point.d.ts +0 -0
  193. /package/{lib → dist}/server/fields/polygon.d.ts +0 -0
  194. /package/{lib → dist}/server/helpers/index.d.ts +0 -0
  195. /package/{lib → dist}/server/index.d.ts +0 -0
  196. /package/{lib → dist}/server/plugin.d.ts +0 -0
  197. /package/{lib → dist}/server/value-parsers/index.d.ts +0 -0
@@ -1,458 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.AMapComponent = void 0;
7
- function _amapJsapiLoader() {
8
- const data = _interopRequireDefault(require("@amap/amap-jsapi-loader"));
9
- _amapJsapiLoader = function _amapJsapiLoader() {
10
- return data;
11
- };
12
- return data;
13
- }
14
- require("@amap/amap-jsapi-types");
15
- function _icons() {
16
- const data = require("@ant-design/icons");
17
- _icons = function _icons() {
18
- return data;
19
- };
20
- return data;
21
- }
22
- function _react() {
23
- const data = require("@formily/react");
24
- _react = function _react() {
25
- return data;
26
- };
27
- return data;
28
- }
29
- function _client() {
30
- const data = require("@nocobase/client");
31
- _client = function _client() {
32
- return data;
33
- };
34
- return data;
35
- }
36
- function _ahooks() {
37
- const data = require("ahooks");
38
- _ahooks = function _ahooks() {
39
- return data;
40
- };
41
- return data;
42
- }
43
- function _antd() {
44
- const data = require("antd");
45
- _antd = function _antd() {
46
- return data;
47
- };
48
- return data;
49
- }
50
- function _react2() {
51
- const data = _interopRequireWildcard(require("react"));
52
- _react2 = function _react2() {
53
- return data;
54
- };
55
- return data;
56
- }
57
- function _reactRouterDom() {
58
- const data = require("react-router-dom");
59
- _reactRouterDom = function _reactRouterDom() {
60
- return data;
61
- };
62
- return data;
63
- }
64
- var _hooks = require("../../hooks");
65
- var _locale = require("../../locale");
66
- var _Search = require("./Search");
67
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
68
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
69
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
70
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
71
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
72
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
73
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
74
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
75
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
76
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
77
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
78
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
79
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
80
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
81
- const methodMapping = {
82
- point: {
83
- mouseTool: 'marker',
84
- propertyKey: 'position',
85
- overlay: 'Marker'
86
- },
87
- polygon: {
88
- mouseTool: 'polygon',
89
- editor: 'PolygonEditor',
90
- propertyKey: 'path',
91
- overlay: 'Polygon'
92
- },
93
- lineString: {
94
- mouseTool: 'polyline',
95
- editor: 'PolylineEditor',
96
- propertyKey: 'path',
97
- overlay: 'Polyline'
98
- },
99
- circle: {
100
- mouseTool: 'circle',
101
- editor: 'CircleEditor',
102
- transformOptions(value) {
103
- return {
104
- center: value.slice(0, 2),
105
- radius: value[2]
106
- };
107
- },
108
- overlay: 'Circle'
109
- }
110
- };
111
- const AMapComponent = _react2().default.forwardRef((props, ref) => {
112
- const _ref = (0, _hooks.useMapConfiguration)(props.mapType) || {},
113
- accessKey = _ref.accessKey,
114
- securityJsCode = _ref.securityJsCode;
115
- const value = props.value,
116
- onChange = props.onChange,
117
- _props$block = props.block,
118
- block = _props$block === void 0 ? false : _props$block,
119
- readonly = props.readonly,
120
- _props$disabled = props.disabled,
121
- disabled = _props$disabled === void 0 ? block : _props$disabled,
122
- _props$zoom = props.zoom,
123
- zoom = _props$zoom === void 0 ? 13 : _props$zoom,
124
- overlayCommonOptions = props.overlayCommonOptions;
125
- const _useMapTranslation = (0, _locale.useMapTranslation)(),
126
- t = _useMapTranslation.t;
127
- const fieldSchema = (0, _react().useFieldSchema)();
128
- const aMap = (0, _react2().useRef)();
129
- const map = (0, _react2().useRef)();
130
- const _mouseTool = (0, _react2().useRef)();
131
- const _useState = (0, _react2().useState)([]),
132
- _useState2 = _slicedToArray(_useState, 2),
133
- needUpdateFlag = _useState2[0],
134
- forceUpdate = _useState2[1];
135
- const _useState3 = (0, _react2().useState)(''),
136
- _useState4 = _slicedToArray(_useState3, 2),
137
- errMessage = _useState4[0],
138
- setErrMessage = _useState4[1];
139
- const _useCollection = (0, _client().useCollection)(),
140
- getField = _useCollection.getField;
141
- const type = (0, _react2().useMemo)(() => {
142
- if (props.type) return props.type;
143
- const collectionField = getField(fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.name);
144
- return collectionField === null || collectionField === void 0 ? void 0 : collectionField.interface;
145
- }, [props === null || props === void 0 ? void 0 : props.type, fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.name]);
146
- const overlay = (0, _react2().useRef)();
147
- const _editor = (0, _react2().useRef)(null);
148
- const navigate = (0, _reactRouterDom().useNavigate)();
149
- const id = (0, _react2().useRef)(`nocobase-map-${type || ''}-${Date.now().toString(32)}`);
150
- const _App$useApp = _antd().App.useApp(),
151
- modal = _App$useApp.modal;
152
- const _useState5 = (0, _react2().useState)(_objectSpread({
153
- strokeWeight: 5,
154
- strokeColor: '#4e9bff',
155
- fillColor: '#4e9bff',
156
- strokeOpacity: 1
157
- }, overlayCommonOptions)),
158
- _useState6 = _slicedToArray(_useState5, 1),
159
- commonOptions = _useState6[0];
160
- const toRemoveOverlay = (0, _ahooks().useMemoizedFn)(() => {
161
- if (overlay.current) {
162
- overlay.current.remove();
163
- }
164
- });
165
- const setTarget = (0, _ahooks().useMemoizedFn)(() => {
166
- if ((!disabled || block) && type !== 'point' && _editor.current) {
167
- _editor.current.setTarget(overlay.current);
168
- _editor.current.open();
169
- }
170
- });
171
- const onMapChange = (0, _ahooks().useMemoizedFn)((target, onlyChange = false) => {
172
- let nextValue = null;
173
- if (type === 'point') {
174
- const _target$getPosition = target.getPosition(),
175
- lat = _target$getPosition.lat,
176
- lng = _target$getPosition.lng;
177
- nextValue = [lng, lat];
178
- } else if (type === 'polygon' || type === 'lineString') {
179
- nextValue = target.getPath().map(item => [item.lng, item.lat]);
180
- if (nextValue.length < 2) {
181
- return;
182
- }
183
- } else if (type === 'circle') {
184
- const center = target.getCenter();
185
- const radius = target.getRadius();
186
- nextValue = [center.lng, center.lat, radius];
187
- }
188
- if (!onlyChange) {
189
- toRemoveOverlay();
190
- overlay.current = target;
191
- setTarget();
192
- }
193
- onChange === null || onChange === void 0 ? void 0 : onChange(nextValue);
194
- });
195
- const createEditor = (0, _ahooks().useMemoizedFn)((curType = type) => {
196
- const mapping = methodMapping[curType];
197
- if (mapping && 'editor' in mapping && !_editor.current) {
198
- _editor.current = new aMap.current[mapping.editor](map.current, null, {
199
- createOptions: commonOptions,
200
- editOptions: commonOptions,
201
- controlPoint: _objectSpread(_objectSpread({}, commonOptions), {}, {
202
- strokeWeight: 3
203
- }),
204
- midControlPoint: _objectSpread(_objectSpread({}, commonOptions), {}, {
205
- strokeWeight: 2,
206
- fillColor: '#fff'
207
- })
208
- });
209
- _editor.current.on('adjust', function ({
210
- target
211
- }) {
212
- onMapChange(target, true);
213
- });
214
- _editor.current.on('move', function ({
215
- target
216
- }) {
217
- onMapChange(target, true);
218
- });
219
- return _editor.current;
220
- }
221
- });
222
- const executeMouseTool = (0, _ahooks().useMemoizedFn)((curType = type) => {
223
- var _editor$current;
224
- if (!_mouseTool.current || (_editor$current = _editor.current) !== null && _editor$current !== void 0 && _editor$current.getTarget()) return;
225
- const mapping = methodMapping[curType];
226
- if (!mapping) {
227
- return;
228
- }
229
- _mouseTool.current[mapping.mouseTool](_objectSpread({}, commonOptions));
230
- });
231
- const createMouseTool = (0, _ahooks().useMemoizedFn)((curType = type) => {
232
- if (_mouseTool.current) return;
233
- _mouseTool.current = new aMap.current.MouseTool(map.current);
234
- _mouseTool.current.on('draw', function ({
235
- obj
236
- }) {
237
- onMapChange(obj);
238
- });
239
- executeMouseTool(curType);
240
- });
241
- const toCenter = (position, imm) => {
242
- if (map.current) {
243
- map.current.setZoomAndCenter(18, position, imm);
244
- }
245
- };
246
- const onReset = () => {
247
- const ok = () => {
248
- toRemoveOverlay();
249
- if (_editor.current) {
250
- _editor.current.setTarget();
251
- _editor.current.close();
252
- }
253
- onChange === null || onChange === void 0 ? void 0 : onChange(null);
254
- };
255
- modal.confirm({
256
- title: t('Clear the canvas'),
257
- content: t('Are you sure to clear the canvas?'),
258
- okText: t('Confirm'),
259
- cancelText: t('Cancel'),
260
- onOk() {
261
- ok();
262
- }
263
- });
264
- };
265
- const onFocusOverlay = () => {
266
- if (overlay.current) {
267
- map.current.setFitView([overlay.current]);
268
- }
269
- };
270
- const getOverlay = (0, _react2().useCallback)((t = type, v = value, o) => {
271
- const mapping = methodMapping[t];
272
- if (!mapping) {
273
- return;
274
- }
275
- const options = _objectSpread(_objectSpread({}, commonOptions), o);
276
- if ('transformOptions' in mapping) {
277
- Object.assign(options, mapping.transformOptions(v));
278
- } else if ('propertyKey' in mapping) {
279
- options[mapping.propertyKey] = v;
280
- }
281
- return new aMap.current[mapping.overlay](options);
282
- }, [commonOptions]);
283
- const setOverlay = (t = type, v = value, o) => {
284
- if (!aMap.current) return;
285
- const nextOverlay = getOverlay(t, v, o);
286
- nextOverlay.setMap(map.current);
287
- return nextOverlay;
288
- };
289
- // 编辑时
290
- (0, _react2().useEffect)(() => {
291
- if (!aMap.current) return;
292
- if (!value || !readonly && overlay.current) {
293
- return;
294
- }
295
- const nextOverlay = setOverlay();
296
- // 聚焦在编辑的位置
297
- map.current.setFitView([nextOverlay]);
298
- overlay.current = nextOverlay;
299
- if (!disabled) {
300
- createEditor();
301
- setTarget();
302
- }
303
- }, [value, needUpdateFlag, type, commonOptions, disabled, readonly]);
304
- // 当在编辑时,关闭 mouseTool
305
- (0, _react2().useEffect)(() => {
306
- if (!_mouseTool.current) return;
307
- if (disabled) {
308
- var _mouseTool$current, _editor$current2;
309
- (_mouseTool$current = _mouseTool.current) === null || _mouseTool$current === void 0 ? void 0 : _mouseTool$current.close();
310
- (_editor$current2 = _editor.current) === null || _editor$current2 === void 0 ? void 0 : _editor$current2.close();
311
- } else {
312
- var _editor$current3;
313
- executeMouseTool();
314
- (_editor$current3 = _editor.current) === null || _editor$current3 === void 0 ? void 0 : _editor$current3.open();
315
- }
316
- }, [disabled]);
317
- // AMap.MouseTool & AMap.XXXEditor
318
- (0, _react2().useEffect)(() => {
319
- if (!aMap.current || !type || disabled) return;
320
- createMouseTool();
321
- createEditor();
322
- }, [disabled, needUpdateFlag, type]);
323
- // 当值变更时,toggle mouseTool
324
- (0, _react2().useEffect)(() => {
325
- if (!_mouseTool.current || !_editor.current) return;
326
- const target = _editor.current.getTarget();
327
- if (target) {
328
- var _mouseTool$current$cl, _mouseTool$current2;
329
- (_mouseTool$current$cl = (_mouseTool$current2 = _mouseTool.current).close) === null || _mouseTool$current$cl === void 0 ? void 0 : _mouseTool$current$cl.call(_mouseTool$current2);
330
- } else {
331
- executeMouseTool();
332
- }
333
- }, [type, value]);
334
- (0, _react2().useEffect)(() => {
335
- if (!accessKey || map.current) return;
336
- if (securityJsCode) {
337
- window._AMapSecurityConfig = {
338
- [securityJsCode.endsWith('_AMapService') ? 'serviceHOST' : 'securityJsCode']: securityJsCode
339
- };
340
- }
341
- _amapJsapiLoader().default.load({
342
- key: accessKey,
343
- version: '2.0',
344
- plugins: ['AMap.MouseTool', 'AMap.PolygonEditor', 'AMap.PolylineEditor', 'AMap.CircleEditor']
345
- }).then(amap => {
346
- return requestIdleCallback(() => {
347
- map.current = new amap.Map(id.current, {
348
- resizeEnable: true,
349
- zoom
350
- });
351
- aMap.current = amap;
352
- setErrMessage('');
353
- forceUpdate([]);
354
- });
355
- }).catch(err => {
356
- if (typeof err === 'string') {
357
- if (err.includes('多个不一致的 key')) {
358
- setErrMessage(t('The AccessKey is incorrect, please check it'));
359
- } else {
360
- setErrMessage(err);
361
- }
362
- } else if ((err === null || err === void 0 ? void 0 : err.type) === 'error') {
363
- setErrMessage('Something went wrong, please refresh the page and try again');
364
- }
365
- });
366
- return () => {
367
- var _map$current;
368
- (_map$current = map.current) === null || _map$current === void 0 ? void 0 : _map$current.destroy();
369
- aMap.current = null;
370
- map.current = null;
371
- _mouseTool.current = null;
372
- _editor.current = null;
373
- };
374
- }, [accessKey, type, securityJsCode]);
375
- (0, _react2().useImperativeHandle)(ref, () => ({
376
- setOverlay,
377
- getOverlay,
378
- createMouseTool,
379
- createEditor,
380
- executeMouseTool,
381
- aMap: aMap.current,
382
- map: map.current,
383
- overlay: overlay.current,
384
- mouseTool: () => _mouseTool.current,
385
- editor: () => _editor.current,
386
- errMessage
387
- }));
388
- if (!accessKey || errMessage) {
389
- return _react2().default.createElement(_antd().Alert, {
390
- action: _react2().default.createElement(_antd().Button, {
391
- type: "primary",
392
- onClick: () => navigate('/admin/settings/map/configuration')
393
- }, t('Go to the configuration page')),
394
- message: errMessage || t('Please configure the AccessKey and SecurityJsCode first'),
395
- type: "error"
396
- });
397
- }
398
- return _react2().default.createElement("div", {
399
- className: (0, _client().css)`
400
- position: relative;
401
- height: 500px;
402
- `,
403
- id: id.current,
404
- style: props === null || props === void 0 ? void 0 : props.style
405
- }, !aMap.current && _react2().default.createElement("div", {
406
- className: (0, _client().css)`
407
- position: absolute;
408
- inset: 0;
409
- display: flex;
410
- align-items: center;
411
- justify-content: center;
412
- `
413
- }, _react2().default.createElement(_antd().Spin, null)), !disabled ? _react2().default.createElement(_react2().default.Fragment, null, _react2().default.createElement(_Search.Search, {
414
- toCenter: toCenter,
415
- aMap: aMap.current
416
- }), _react2().default.createElement("div", {
417
- className: (0, _client().css)`
418
- position: absolute;
419
- bottom: 80px;
420
- right: 20px;
421
- z-index: 10;
422
- `
423
- }, _react2().default.createElement(_antd().Button, {
424
- onClick: onFocusOverlay,
425
- disabled: !overlay.current,
426
- type: "primary",
427
- shape: "round",
428
- size: "large",
429
- icon: _react2().default.createElement(_icons().SyncOutlined, null)
430
- })), type !== 'point' ? _react2().default.createElement("div", {
431
- className: (0, _client().css)`
432
- position: absolute;
433
- bottom: 20px;
434
- left: 10px;
435
- z-index: 2;
436
- pointer-events: none;
437
- `
438
- }, _react2().default.createElement(_antd().Alert, {
439
- message: t('Click to select the starting point and double-click to end the drawing'),
440
- type: "info"
441
- })) : null, _react2().default.createElement("div", {
442
- className: (0, _client().css)`
443
- position: absolute;
444
- bottom: 20px;
445
- right: 20px;
446
- z-index: 2;
447
- `
448
- }, _react2().default.createElement(_antd().Button, {
449
- disabled: !value,
450
- style: {
451
- height: '40px'
452
- },
453
- onClick: onReset,
454
- type: "primary",
455
- danger: true
456
- }, t('Clear')))) : null);
457
- });
458
- exports.AMapComponent = AMapComponent;
@@ -1,121 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Search = void 0;
7
- function _client() {
8
- const data = require("@nocobase/client");
9
- _client = function _client() {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _ahooks() {
15
- const data = require("ahooks");
16
- _ahooks = function _ahooks() {
17
- return data;
18
- };
19
- return data;
20
- }
21
- function _antd() {
22
- const data = require("antd");
23
- _antd = function _antd() {
24
- return data;
25
- };
26
- return data;
27
- }
28
- function _react() {
29
- const data = _interopRequireWildcard(require("react"));
30
- _react = function _react() {
31
- return data;
32
- };
33
- return data;
34
- }
35
- var _locale = require("../../locale");
36
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
37
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
38
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
39
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
40
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
41
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
42
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
43
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
44
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
45
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
46
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
47
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
48
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
49
- const Search = props => {
50
- const aMap = props.aMap,
51
- toCenter = props.toCenter;
52
- const _useMapTranslation = (0, _locale.useMapTranslation)(),
53
- t = _useMapTranslation.t;
54
- const placeSearch = (0, _react().useRef)();
55
- const _useState = (0, _react().useState)([]),
56
- _useState2 = _slicedToArray(_useState, 2),
57
- options = _useState2[0],
58
- setOptions = _useState2[1];
59
- (0, _react().useEffect)(() => {
60
- aMap === null || aMap === void 0 ? void 0 : aMap.plugin('AMap.PlaceSearch', () => {
61
- placeSearch.current = new aMap.PlaceSearch({
62
- city: '全国',
63
- pageSize: 30
64
- });
65
- });
66
- }, [aMap]);
67
- const _useDebounceFn = (0, _ahooks().useDebounceFn)(keyword => {
68
- if (!placeSearch.current) {
69
- return;
70
- }
71
- placeSearch.current.search(keyword || ' ', (status, result) => {
72
- if (status === 'complete') {
73
- setOptions(result.poiList.pois.map(item => {
74
- return _objectSpread(_objectSpread({}, item), {}, {
75
- label: `${item.name}-${item.address}`,
76
- value: item.id
77
- });
78
- }));
79
- } else {
80
- if (status === 'no_data') {
81
- setOptions([]);
82
- return;
83
- }
84
- _antd().message.error(t('Please configure the AMap securityCode or securityHost correctly'));
85
- }
86
- });
87
- }, {
88
- wait: 300
89
- }),
90
- onSearch = _useDebounceFn.run;
91
- const onSelect = value => {
92
- const place = options.find(o => {
93
- return o.value === value;
94
- });
95
- if (place !== null && place !== void 0 && place.location) {
96
- toCenter(place.location);
97
- }
98
- };
99
- return _react().default.createElement("div", {
100
- className: (0, _client().css)`
101
- position: absolute;
102
- top: 10px;
103
- left: 10px;
104
- z-index: 10;
105
- width: calc(100% - 20px);
106
- `
107
- }, _react().default.createElement(_antd().Select, {
108
- showSearch: true,
109
- allowClear: true,
110
- style: {
111
- background: 'rgba(255, 255, 255, 0.8)'
112
- },
113
- placeholder: t('Enter keywords to search'),
114
- filterOption: false,
115
- onSearch: onSearch,
116
- onSelect: onSelect,
117
- options: options,
118
- popupMatchSelectWidth: false
119
- }));
120
- };
121
- exports.Search = Search;
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _Block = require("./Block");
7
- Object.keys(_Block).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _Block[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return _Block[key];
14
- }
15
- });
16
- });
17
- var _Map = require("./Map");
18
- Object.keys(_Map).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _Map[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function get() {
24
- return _Map[key];
25
- }
26
- });
27
- });