@nocobase/plugin-map 0.10.0-alpha.5 → 0.10.1-alpha.1
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/lib/client/block/MapBlock.js +8 -328
- package/lib/client/block/MapBlockInitializer.js +7 -6
- package/lib/client/components/AMap/Block.d.ts +2 -0
- package/lib/client/components/AMap/Block.js +357 -0
- package/lib/client/components/{AMap.d.ts → AMap/Map.d.ts} +3 -3
- package/lib/client/components/{AMap.js → AMap/Map.js} +13 -13
- package/lib/client/components/{Search.d.ts → AMap/Search.d.ts} +2 -2
- package/lib/client/components/{Search.js → AMap/Search.js} +3 -4
- package/lib/client/components/AMap/index.d.ts +2 -0
- package/lib/client/components/AMap/index.js +27 -0
- package/lib/client/components/Configuration.d.ts +1 -2
- package/lib/client/components/Configuration.js +54 -28
- package/lib/client/components/GoogleMaps/Block.d.ts +2 -0
- package/lib/client/components/GoogleMaps/Block.js +377 -0
- package/lib/client/components/GoogleMaps/Map.d.ts +31 -0
- package/lib/client/components/GoogleMaps/Map.js +471 -0
- package/lib/client/components/GoogleMaps/Search.d.ts +8 -0
- package/lib/client/components/GoogleMaps/Search.js +128 -0
- package/lib/client/components/GoogleMaps/index.d.ts +2 -0
- package/lib/client/components/GoogleMaps/index.js +27 -0
- package/lib/client/components/GoogleMaps/utils.d.ts +5 -0
- package/lib/client/components/GoogleMaps/utils.js +44 -0
- package/lib/client/components/Map.d.ts +1 -1
- package/lib/client/components/Map.js +13 -14
- package/lib/client/components/MapBlock.d.ts +2 -0
- package/lib/client/components/MapBlock.js +40 -0
- package/lib/client/components/MapComponent.d.ts +2 -0
- package/lib/client/components/MapComponent.js +42 -0
- package/lib/client/components/ReadPretty.js +5 -13
- package/lib/client/components/index.d.ts +6 -0
- package/lib/client/components/index.js +71 -0
- package/lib/client/constants.d.ts +2 -0
- package/lib/client/constants.js +6 -2
- package/lib/client/index.js +3 -5
- package/lib/client/locale/zh-CN.d.ts +1 -0
- package/lib/client/locale/zh-CN.js +2 -1
- package/lib/client/types.d.ts +1 -0
- package/lib/client/types.js +5 -0
- package/lib/client/utils.d.ts +1 -0
- package/lib/client/utils.js +1 -0
- package/package.json +16 -5
- package/src/client/block/MapBlock.tsx +7 -311
- package/src/client/block/MapBlockInitializer.tsx +3 -2
- package/src/client/components/AMap/Block.tsx +314 -0
- package/src/client/components/{AMap.tsx → AMap/Map.tsx} +10 -11
- package/src/client/components/{Search.tsx → AMap/Search.tsx} +2 -4
- package/src/client/components/AMap/index.ts +2 -0
- package/src/client/components/Configuration.tsx +49 -25
- package/src/client/components/GoogleMaps/Block.tsx +341 -0
- package/src/client/components/GoogleMaps/Map.tsx +470 -0
- package/src/client/components/GoogleMaps/Search.tsx +107 -0
- package/src/client/components/GoogleMaps/index.ts +2 -0
- package/src/client/components/GoogleMaps/utils.ts +33 -0
- package/src/client/components/Map.tsx +6 -5
- package/src/client/components/MapBlock.tsx +24 -0
- package/src/client/components/MapComponent.tsx +23 -0
- package/src/client/components/ReadPretty.tsx +6 -11
- package/src/client/components/index.ts +6 -0
- package/src/client/constants.ts +5 -0
- package/src/client/index.tsx +2 -3
- package/src/client/locale/zh-CN.ts +2 -0
- package/src/client/types.ts +1 -0
- package/src/client/utils.ts +0 -0
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDrawingMode = exports.GoogleMapsComponent = void 0;
|
|
7
|
+
function _icons() {
|
|
8
|
+
const data = require("@ant-design/icons");
|
|
9
|
+
_icons = function _icons() {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _css() {
|
|
15
|
+
const data = require("@emotion/css");
|
|
16
|
+
_css = function _css() {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _react() {
|
|
22
|
+
const data = require("@formily/react");
|
|
23
|
+
_react = function _react() {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _jsApiLoader() {
|
|
29
|
+
const data = require("@googlemaps/js-api-loader");
|
|
30
|
+
_jsApiLoader = function _jsApiLoader() {
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
function _client() {
|
|
36
|
+
const data = require("@nocobase/client");
|
|
37
|
+
_client = function _client() {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
function _ahooks() {
|
|
43
|
+
const data = require("ahooks");
|
|
44
|
+
_ahooks = function _ahooks() {
|
|
45
|
+
return data;
|
|
46
|
+
};
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
function _antd() {
|
|
50
|
+
const data = require("antd");
|
|
51
|
+
_antd = function _antd() {
|
|
52
|
+
return data;
|
|
53
|
+
};
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
function _react2() {
|
|
57
|
+
const data = _interopRequireWildcard(require("react"));
|
|
58
|
+
_react2 = function _react2() {
|
|
59
|
+
return data;
|
|
60
|
+
};
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
function _reactRouter() {
|
|
64
|
+
const data = require("react-router");
|
|
65
|
+
_reactRouter = function _reactRouter() {
|
|
66
|
+
return data;
|
|
67
|
+
};
|
|
68
|
+
return data;
|
|
69
|
+
}
|
|
70
|
+
var _constants = require("../../constants");
|
|
71
|
+
var _hooks = require("../../hooks");
|
|
72
|
+
var _locale = require("../../locale");
|
|
73
|
+
var _Search = require("./Search");
|
|
74
|
+
var _utils = require("./utils");
|
|
75
|
+
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); }
|
|
76
|
+
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; }
|
|
77
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
78
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
79
|
+
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; }
|
|
80
|
+
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; }
|
|
81
|
+
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; }
|
|
82
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
83
|
+
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); }
|
|
84
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
85
|
+
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."); }
|
|
86
|
+
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); }
|
|
87
|
+
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; }
|
|
88
|
+
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; } }
|
|
89
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
90
|
+
const getDrawingMode = type => {
|
|
91
|
+
if (type === 'point') {
|
|
92
|
+
return 'marker';
|
|
93
|
+
} else if (type === 'lineString') {
|
|
94
|
+
return 'polyline';
|
|
95
|
+
}
|
|
96
|
+
return type;
|
|
97
|
+
};
|
|
98
|
+
exports.getDrawingMode = getDrawingMode;
|
|
99
|
+
const methodMapping = {
|
|
100
|
+
point: {
|
|
101
|
+
propertyKey: 'position',
|
|
102
|
+
overlay: 'Marker'
|
|
103
|
+
},
|
|
104
|
+
polygon: {
|
|
105
|
+
propertyKey: 'paths',
|
|
106
|
+
overlay: 'Polygon'
|
|
107
|
+
},
|
|
108
|
+
lineString: {
|
|
109
|
+
propertyKey: 'path',
|
|
110
|
+
overlay: 'Polyline'
|
|
111
|
+
},
|
|
112
|
+
circle: {
|
|
113
|
+
transformOptions(value) {
|
|
114
|
+
return {
|
|
115
|
+
center: new google.maps.LatLng(value[1], value[0]),
|
|
116
|
+
radius: value[2]
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
overlay: 'Circle'
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const GoogleMapsComponent = _react2().default.forwardRef((props, ref) => {
|
|
123
|
+
const value = props.value,
|
|
124
|
+
onChange = props.onChange,
|
|
125
|
+
_props$block = props.block,
|
|
126
|
+
block = _props$block === void 0 ? false : _props$block,
|
|
127
|
+
readonly = props.readonly,
|
|
128
|
+
_props$disabled = props.disabled,
|
|
129
|
+
disabled = _props$disabled === void 0 ? block : _props$disabled,
|
|
130
|
+
_props$zoom = props.zoom,
|
|
131
|
+
zoom = _props$zoom === void 0 ? 13 : _props$zoom,
|
|
132
|
+
overlayCommonOptions = props.overlayCommonOptions;
|
|
133
|
+
const _ref = (0, _hooks.useMapConfiguration)(props.mapType) || {},
|
|
134
|
+
accessKey = _ref.accessKey;
|
|
135
|
+
const _useMapTranslation = (0, _locale.useMapTranslation)(),
|
|
136
|
+
t = _useMapTranslation.t;
|
|
137
|
+
const _useCollection = (0, _client().useCollection)(),
|
|
138
|
+
getField = _useCollection.getField;
|
|
139
|
+
const fieldSchema = (0, _react().useFieldSchema)();
|
|
140
|
+
const drawingManagerRef = (0, _react2().useRef)();
|
|
141
|
+
const map = (0, _react2().useRef)();
|
|
142
|
+
const overlayRef = (0, _react2().useRef)();
|
|
143
|
+
const _useState = (0, _react2().useState)([]),
|
|
144
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
145
|
+
needUpdateFlag = _useState2[0],
|
|
146
|
+
forceUpdate = _useState2[1];
|
|
147
|
+
const _useState3 = (0, _react2().useState)(''),
|
|
148
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
149
|
+
errMessage = _useState4[0],
|
|
150
|
+
setErrMessage = _useState4[1];
|
|
151
|
+
const api = (0, _client().useAPIClient)();
|
|
152
|
+
const type = (0, _react2().useMemo)(() => {
|
|
153
|
+
if (props.type) return props.type;
|
|
154
|
+
const collectionField = getField(fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.name);
|
|
155
|
+
return collectionField === null || collectionField === void 0 ? void 0 : collectionField.interface;
|
|
156
|
+
}, [props === null || props === void 0 ? void 0 : props.type, fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.name]);
|
|
157
|
+
const drawingMode = (0, _react2().useRef)(getDrawingMode(type));
|
|
158
|
+
const _useState5 = (0, _react2().useState)(_objectSpread({
|
|
159
|
+
strokeWeight: 5,
|
|
160
|
+
strokeColor: '#4e9bff',
|
|
161
|
+
fillColor: '#4e9bff',
|
|
162
|
+
strokeOpacity: 1,
|
|
163
|
+
editable: !disabled,
|
|
164
|
+
draggable: !disabled
|
|
165
|
+
}, overlayCommonOptions)),
|
|
166
|
+
_useState6 = _slicedToArray(_useState5, 1),
|
|
167
|
+
commonOptions = _useState6[0];
|
|
168
|
+
const navigate = (0, _reactRouter().useNavigate)();
|
|
169
|
+
const mapContainerRef = (0, _react2().useRef)();
|
|
170
|
+
const cleanupOverlayListenersRef = (0, _react2().useRef)(new Set());
|
|
171
|
+
const onAndOffListenOverlay = (0, _ahooks().useMemoizedFn)(target => {
|
|
172
|
+
cleanupOverlayListenersRef.current.forEach(cb => {
|
|
173
|
+
cleanupOverlayListenersRef.current.delete(cb);
|
|
174
|
+
});
|
|
175
|
+
if ('getPath' in target) {
|
|
176
|
+
const mvcArray = target.getPath();
|
|
177
|
+
['insert_at', 'remove_at', 'set_at'].forEach(event => {
|
|
178
|
+
cleanupOverlayListenersRef.current.add(mvcArray.addListener(event, () => {
|
|
179
|
+
onMapChange(target, true);
|
|
180
|
+
}).remove);
|
|
181
|
+
});
|
|
182
|
+
} else if (target instanceof google.maps.Circle) {
|
|
183
|
+
['center_changed', 'radius_changed'].forEach(event => {
|
|
184
|
+
cleanupOverlayListenersRef.current.add(target.addListener(event, () => {
|
|
185
|
+
onMapChange(target, true);
|
|
186
|
+
}).remove);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
const toRemoveOverlay = (0, _ahooks().useMemoizedFn)(() => {
|
|
191
|
+
if (overlayRef.current) {
|
|
192
|
+
overlayRef.current.unbindAll();
|
|
193
|
+
overlayRef.current.setMap(null);
|
|
194
|
+
}
|
|
195
|
+
if (type !== 'point') {
|
|
196
|
+
var _drawingManagerRef$cu;
|
|
197
|
+
(_drawingManagerRef$cu = drawingManagerRef.current) === null || _drawingManagerRef$cu === void 0 ? void 0 : _drawingManagerRef$cu.setDrawingMode(null);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
const toCenter = (0, _ahooks().useMemoizedFn)(position => {
|
|
201
|
+
if (map.current) {
|
|
202
|
+
map.current.setCenter(position);
|
|
203
|
+
map.current.setZoom(zoom);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
const setupOverlay = (0, _ahooks().useMemoizedFn)(nextOverlay => {
|
|
207
|
+
toRemoveOverlay();
|
|
208
|
+
onAndOffListenOverlay(nextOverlay);
|
|
209
|
+
overlayRef.current = nextOverlay;
|
|
210
|
+
});
|
|
211
|
+
const setFitView = (0, _ahooks().useMemoizedFn)(overlays => {
|
|
212
|
+
const bounds = new google.maps.LatLngBounds();
|
|
213
|
+
overlays.forEach(overlay => {
|
|
214
|
+
if (overlay instanceof google.maps.Marker) {
|
|
215
|
+
bounds.extend(overlay.getPosition());
|
|
216
|
+
} else if (overlay instanceof google.maps.Polyline || overlay instanceof google.maps.Polygon) {
|
|
217
|
+
const path = overlay.getPath();
|
|
218
|
+
for (let i = 0; i < path.getLength(); i++) {
|
|
219
|
+
bounds.extend(path.getAt(i));
|
|
220
|
+
}
|
|
221
|
+
} else if (overlay instanceof google.maps.Circle) {
|
|
222
|
+
bounds.union(overlay.getBounds());
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
map.current.setCenter(bounds.getCenter());
|
|
226
|
+
});
|
|
227
|
+
const onFocusOverlay = () => {
|
|
228
|
+
if (overlayRef.current) {
|
|
229
|
+
setFitView([overlayRef.current]);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
const onMapChange = (0, _ahooks().useMemoizedFn)((target, onlyChange = false) => {
|
|
233
|
+
let nextValue = null;
|
|
234
|
+
if (type === 'point') {
|
|
235
|
+
const _target$getPosition = target.getPosition(),
|
|
236
|
+
lat = _target$getPosition.lat,
|
|
237
|
+
lng = _target$getPosition.lng;
|
|
238
|
+
nextValue = [lng(), lat()];
|
|
239
|
+
} else if (type === 'polygon' || type === 'lineString') {
|
|
240
|
+
nextValue = target.getPath().getArray().map(item => [item.lng(), item.lat()]);
|
|
241
|
+
if (nextValue.length < 2) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
} else if (type === 'circle') {
|
|
245
|
+
const center = target.getCenter();
|
|
246
|
+
const radius = target.getRadius();
|
|
247
|
+
nextValue = [center.lng(), center.lat(), radius];
|
|
248
|
+
}
|
|
249
|
+
if (!onlyChange) {
|
|
250
|
+
setupOverlay(target);
|
|
251
|
+
}
|
|
252
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(nextValue);
|
|
253
|
+
});
|
|
254
|
+
const createDraw = (0, _ahooks().useMemoizedFn)((onlyCreate = false, additionalOptions) => {
|
|
255
|
+
const currentOptions = _objectSpread(_objectSpread(_objectSpread({}, commonOptions), additionalOptions), {}, {
|
|
256
|
+
map: map.current
|
|
257
|
+
});
|
|
258
|
+
drawingManagerRef.current = new google.maps.drawing.DrawingManager({
|
|
259
|
+
drawingMode: drawingMode.current,
|
|
260
|
+
drawingControl: false,
|
|
261
|
+
markerOptions: _objectSpread(_objectSpread({}, currentOptions), {}, {
|
|
262
|
+
icon: (0, _utils.getIcon)(_constants.defaultImage)
|
|
263
|
+
}),
|
|
264
|
+
polygonOptions: currentOptions,
|
|
265
|
+
polylineOptions: currentOptions,
|
|
266
|
+
circleOptions: currentOptions,
|
|
267
|
+
map: map.current
|
|
268
|
+
});
|
|
269
|
+
if (!onlyCreate) {
|
|
270
|
+
drawingManagerRef.current.addListener('overlaycomplete', event => {
|
|
271
|
+
const overlay = event.overlay;
|
|
272
|
+
onMapChange(overlay);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return drawingManagerRef.current;
|
|
276
|
+
});
|
|
277
|
+
const getOverlay = (0, _ahooks().useMemoizedFn)((t = type, v = value, o) => {
|
|
278
|
+
const mapping = methodMapping[t];
|
|
279
|
+
if (!mapping) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const options = _objectSpread(_objectSpread({}, commonOptions), {}, {
|
|
283
|
+
icon: (0, _utils.getIcon)(_constants.defaultImage)
|
|
284
|
+
}, o);
|
|
285
|
+
if ('transformOptions' in mapping) {
|
|
286
|
+
Object.assign(options, mapping.transformOptions(v));
|
|
287
|
+
} else if ('propertyKey' in mapping) {
|
|
288
|
+
options[mapping.propertyKey] = Array.isArray(v[0]) ? v.map(item => {
|
|
289
|
+
return new google.maps.LatLng(item[1], item[0]);
|
|
290
|
+
}) : new google.maps.LatLng(v[1], v[0]);
|
|
291
|
+
}
|
|
292
|
+
const overlay = new google.maps[mapping.overlay](options);
|
|
293
|
+
return overlay;
|
|
294
|
+
});
|
|
295
|
+
const setOverlay = (0, _ahooks().useMemoizedFn)((t = type, v = value, o) => {
|
|
296
|
+
if (!map.current) return;
|
|
297
|
+
const nextOverlay = getOverlay(t, v, _objectSpread(_objectSpread({}, o), {}, {
|
|
298
|
+
map: map.current
|
|
299
|
+
}));
|
|
300
|
+
return nextOverlay;
|
|
301
|
+
});
|
|
302
|
+
// edit mode
|
|
303
|
+
(0, _react2().useEffect)(() => {
|
|
304
|
+
if (!map.current) return;
|
|
305
|
+
if (!value || !readonly && overlayRef.current) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const nextOverlay = setOverlay();
|
|
309
|
+
setupOverlay(nextOverlay);
|
|
310
|
+
// Focus on the overlay
|
|
311
|
+
setFitView([nextOverlay]);
|
|
312
|
+
}, [value, needUpdateFlag, type, disabled, readonly, setOverlay, setFitView, setupOverlay]);
|
|
313
|
+
(0, _react2().useEffect)(() => {
|
|
314
|
+
if (!accessKey || map.current || !mapContainerRef.current) return;
|
|
315
|
+
let loader;
|
|
316
|
+
try {
|
|
317
|
+
loader = new (_jsApiLoader().Loader)({
|
|
318
|
+
apiKey: accessKey,
|
|
319
|
+
version: 'weekly',
|
|
320
|
+
language: api.auth.getLocale()
|
|
321
|
+
});
|
|
322
|
+
} catch (err) {
|
|
323
|
+
setErrMessage(t('Load google maps failed, Please check the Api key and refresh the page'));
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
// google maps api error
|
|
327
|
+
const error = console.error;
|
|
328
|
+
console.error = (err, ...args) => {
|
|
329
|
+
if (err === null || err === void 0 ? void 0 : err.includes('InvalidKeyMapError')) {
|
|
330
|
+
setErrMessage(t('Load google maps failed, Please check the Api key and refresh the page'));
|
|
331
|
+
}
|
|
332
|
+
error(err, ...args);
|
|
333
|
+
};
|
|
334
|
+
Promise.all([loader.importLibrary('drawing'), loader.importLibrary('core'), loader.importLibrary('geometry')]).then( /*#__PURE__*/function () {
|
|
335
|
+
var _ref2 = _asyncToGenerator(function* (res) {
|
|
336
|
+
const center = yield (0, _utils.getCurrentPosition)();
|
|
337
|
+
map.current = new google.maps.Map(mapContainerRef.current, {
|
|
338
|
+
zoom,
|
|
339
|
+
center,
|
|
340
|
+
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
|
341
|
+
zoomControl: false,
|
|
342
|
+
streetViewControl: false,
|
|
343
|
+
panControl: false,
|
|
344
|
+
mapTypeControl: false,
|
|
345
|
+
fullscreenControl: false
|
|
346
|
+
});
|
|
347
|
+
setErrMessage('');
|
|
348
|
+
forceUpdate([]);
|
|
349
|
+
});
|
|
350
|
+
return function (_x2) {
|
|
351
|
+
return _ref2.apply(this, arguments);
|
|
352
|
+
};
|
|
353
|
+
}()).catch(err => {
|
|
354
|
+
if (err instanceof Error) {
|
|
355
|
+
setErrMessage(err.message);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
return () => {
|
|
360
|
+
var _map$current, _drawingManagerRef$cu2;
|
|
361
|
+
(_map$current = map.current) === null || _map$current === void 0 ? void 0 : _map$current.unbindAll();
|
|
362
|
+
map.current = null;
|
|
363
|
+
(_drawingManagerRef$cu2 = drawingManagerRef.current) === null || _drawingManagerRef$cu2 === void 0 ? void 0 : _drawingManagerRef$cu2.unbindAll();
|
|
364
|
+
};
|
|
365
|
+
}, [accessKey, api.auth, type, zoom]);
|
|
366
|
+
(0, _react2().useEffect)(() => {
|
|
367
|
+
if (!map.current || !type || disabled || drawingManagerRef.current) return;
|
|
368
|
+
createDraw();
|
|
369
|
+
}, [createDraw, disabled, needUpdateFlag, type]);
|
|
370
|
+
(0, _react2().useImperativeHandle)(ref, () => ({
|
|
371
|
+
setOverlay,
|
|
372
|
+
getOverlay,
|
|
373
|
+
setFitView,
|
|
374
|
+
createDraw,
|
|
375
|
+
map: map.current,
|
|
376
|
+
overlay: overlayRef.current,
|
|
377
|
+
drawingManager: drawingManagerRef.current,
|
|
378
|
+
errMessage
|
|
379
|
+
}));
|
|
380
|
+
const onReset = (0, _ahooks().useMemoizedFn)(() => {
|
|
381
|
+
const ok = () => {
|
|
382
|
+
toRemoveOverlay();
|
|
383
|
+
drawingManagerRef.current.setDrawingMode(drawingMode.current);
|
|
384
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(null);
|
|
385
|
+
};
|
|
386
|
+
_antd().Modal.confirm({
|
|
387
|
+
title: t('Clear the canvas'),
|
|
388
|
+
content: t('Are you sure to clear the canvas?'),
|
|
389
|
+
okText: t('Confirm'),
|
|
390
|
+
cancelText: t('Cancel'),
|
|
391
|
+
onOk() {
|
|
392
|
+
ok();
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
if (!accessKey || errMessage) {
|
|
397
|
+
return _react2().default.createElement(_antd().Alert, {
|
|
398
|
+
action: _react2().default.createElement(_antd().Button, {
|
|
399
|
+
type: "primary",
|
|
400
|
+
onClick: () => navigate('/admin/settings/map/configuration?tab=google')
|
|
401
|
+
}, t('Go to the configuration page')),
|
|
402
|
+
message: errMessage || t('Please configure the Api key first'),
|
|
403
|
+
type: "error"
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
return _react2().default.createElement("div", {
|
|
407
|
+
className: (0, _css().css)`
|
|
408
|
+
position: relative;
|
|
409
|
+
height: 500px;
|
|
410
|
+
`
|
|
411
|
+
}, !map.current && _react2().default.createElement("div", {
|
|
412
|
+
className: (0, _css().css)`
|
|
413
|
+
position: absolute;
|
|
414
|
+
inset: 0;
|
|
415
|
+
display: flex;
|
|
416
|
+
align-items: center;
|
|
417
|
+
justify-content: center;
|
|
418
|
+
`
|
|
419
|
+
}, _react2().default.createElement(_antd().Spin, null)), !disabled ? _react2().default.createElement(_react2().default.Fragment, null, map.current && _react2().default.createElement(_Search.Search, {
|
|
420
|
+
toCenter: toCenter,
|
|
421
|
+
mapRef: map
|
|
422
|
+
}), _react2().default.createElement("div", {
|
|
423
|
+
className: (0, _css().css)`
|
|
424
|
+
position: absolute;
|
|
425
|
+
bottom: 80px;
|
|
426
|
+
right: 20px;
|
|
427
|
+
z-index: 10;
|
|
428
|
+
`
|
|
429
|
+
}, _react2().default.createElement(_antd().Button, {
|
|
430
|
+
onClick: onFocusOverlay,
|
|
431
|
+
disabled: !overlayRef.current,
|
|
432
|
+
type: "primary",
|
|
433
|
+
shape: "round",
|
|
434
|
+
size: "large",
|
|
435
|
+
icon: _react2().default.createElement(_icons().SyncOutlined, null)
|
|
436
|
+
})), type === 'lineString' || type === 'polygon' ? _react2().default.createElement("div", {
|
|
437
|
+
className: (0, _css().css)`
|
|
438
|
+
position: absolute;
|
|
439
|
+
bottom: 20px;
|
|
440
|
+
left: 10px;
|
|
441
|
+
z-index: 2;
|
|
442
|
+
pointer-events: none;
|
|
443
|
+
`
|
|
444
|
+
}, _react2().default.createElement(_antd().Alert, {
|
|
445
|
+
message: t('Click to select the starting point and double-click to end the drawing'),
|
|
446
|
+
type: "info"
|
|
447
|
+
})) : null, _react2().default.createElement("div", {
|
|
448
|
+
className: (0, _css().css)`
|
|
449
|
+
position: absolute;
|
|
450
|
+
bottom: 20px;
|
|
451
|
+
right: 20px;
|
|
452
|
+
z-index: 2;
|
|
453
|
+
`
|
|
454
|
+
}, _react2().default.createElement(_antd().Button, {
|
|
455
|
+
disabled: !value,
|
|
456
|
+
style: {
|
|
457
|
+
height: '40px'
|
|
458
|
+
},
|
|
459
|
+
onClick: onReset,
|
|
460
|
+
type: "primary",
|
|
461
|
+
danger: true
|
|
462
|
+
}, t('Clear')))) : null, _react2().default.createElement("div", {
|
|
463
|
+
ref: mapContainerRef,
|
|
464
|
+
className: (0, _css().css)`
|
|
465
|
+
width: 100%;
|
|
466
|
+
height: 100%;
|
|
467
|
+
`,
|
|
468
|
+
style: props === null || props === void 0 ? void 0 : props.style
|
|
469
|
+
}));
|
|
470
|
+
});
|
|
471
|
+
exports.GoogleMapsComponent = GoogleMapsComponent;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="google.maps" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
interface SearchProps {
|
|
4
|
+
toCenter: (p: any) => void;
|
|
5
|
+
mapRef: React.RefObject<google.maps.Map>;
|
|
6
|
+
}
|
|
7
|
+
export declare const Search: (props: SearchProps) => React.JSX.Element;
|
|
8
|
+
export default Search;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.Search = void 0;
|
|
7
|
+
function _css() {
|
|
8
|
+
const data = require("@emotion/css");
|
|
9
|
+
_css = function _css() {
|
|
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 toCenter = props.toCenter,
|
|
51
|
+
mapRef = props.mapRef;
|
|
52
|
+
const _useMapTranslation = (0, _locale.useMapTranslation)(),
|
|
53
|
+
t = _useMapTranslation.t;
|
|
54
|
+
const placeSearchRef = (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
|
+
google.maps.importLibrary('places').then(places => {
|
|
61
|
+
placeSearchRef.current = new places.AutocompleteService();
|
|
62
|
+
}).catch(() => {
|
|
63
|
+
_antd().message.error('Please configure the Google API Key correctly');
|
|
64
|
+
});
|
|
65
|
+
}, [mapRef]);
|
|
66
|
+
const _useDebounceFn = (0, _ahooks().useDebounceFn)(keyword => {
|
|
67
|
+
if (!placeSearchRef.current) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
placeSearchRef.current.getPlacePredictions({
|
|
71
|
+
input: keyword || ' '
|
|
72
|
+
}, (result, status) => {
|
|
73
|
+
if (status === google.maps.places.PlacesServiceStatus.OK) {
|
|
74
|
+
setOptions(result.map(item => {
|
|
75
|
+
const structured = item.structured_formatting;
|
|
76
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
77
|
+
label: `${structured.main_text}${structured.secondary_text ? ' ' + structured.secondary_text : ''}`,
|
|
78
|
+
value: item.place_id
|
|
79
|
+
});
|
|
80
|
+
}));
|
|
81
|
+
} else {
|
|
82
|
+
setOptions([]);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}, {
|
|
87
|
+
wait: 300
|
|
88
|
+
}),
|
|
89
|
+
onSearch = _useDebounceFn.run;
|
|
90
|
+
const onSelect = value => {
|
|
91
|
+
const place = options.find(o => {
|
|
92
|
+
return o.value === value;
|
|
93
|
+
});
|
|
94
|
+
const service = new google.maps.places.PlacesService(mapRef.current);
|
|
95
|
+
service.getDetails({
|
|
96
|
+
placeId: place.place_id,
|
|
97
|
+
fields: ['geometry']
|
|
98
|
+
}, (result, status) => {
|
|
99
|
+
if (status === google.maps.places.PlacesServiceStatus.OK) {
|
|
100
|
+
toCenter(result.geometry.location);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
return _react().default.createElement("div", {
|
|
105
|
+
className: (0, _css().css)`
|
|
106
|
+
position: absolute;
|
|
107
|
+
top: 10px;
|
|
108
|
+
left: 10px;
|
|
109
|
+
z-index: 10;
|
|
110
|
+
width: calc(100% - 20px);
|
|
111
|
+
`
|
|
112
|
+
}, _react().default.createElement(_antd().Select, {
|
|
113
|
+
id: "google-map-search",
|
|
114
|
+
showSearch: true,
|
|
115
|
+
allowClear: true,
|
|
116
|
+
style: {
|
|
117
|
+
background: 'rgba(255, 255, 255, 0.8)'
|
|
118
|
+
},
|
|
119
|
+
placeholder: t('Enter keywords to search'),
|
|
120
|
+
filterOption: false,
|
|
121
|
+
onSearch: onSearch,
|
|
122
|
+
onSelect: onSelect,
|
|
123
|
+
options: options
|
|
124
|
+
}));
|
|
125
|
+
};
|
|
126
|
+
exports.Search = Search;
|
|
127
|
+
var _default = Search;
|
|
128
|
+
exports.default = _default;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
});
|