@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.
- package/client.d.ts +2 -3
- package/client.js +1 -1
- package/dist/client/index.js +3092 -0
- package/{lib → dist}/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/locale/en-US.js +6 -0
- package/dist/locale/fr-FR.js +6 -0
- package/dist/locale/pt-BR.js +51 -0
- package/dist/locale/zh-CN.js +54 -0
- package/dist/server/actions/index.js +43 -0
- package/dist/server/collections/mapConfiguration.js +32 -0
- package/dist/server/constants.js +5 -0
- package/dist/server/fields/circle.js +47 -0
- package/dist/server/fields/index.js +33 -0
- package/dist/server/fields/lineString.js +54 -0
- package/dist/server/fields/point.js +57 -0
- package/dist/server/fields/polygon.js +53 -0
- package/dist/server/helpers/index.js +31 -0
- package/dist/server/index.js +11 -0
- package/dist/server/plugin.js +59 -0
- package/dist/server/value-parsers/index.js +53 -0
- package/docs/en-US/changelog.md +1 -0
- package/docs/en-US/index.md +1 -0
- package/docs/en-US/installation.md +1 -0
- package/docs/en-US/tabs.json +18 -0
- package/docs/en-US/usage.md +1 -0
- package/docs/zh-CN/changelog.md +1 -0
- package/docs/zh-CN/index.md +1 -0
- package/docs/zh-CN/installation.md +1 -0
- package/docs/zh-CN/tabs.json +18 -0
- package/docs/zh-CN/usage.md +1 -0
- package/package.json +19 -30
- package/server.d.ts +2 -3
- package/server.js +1 -1
- package/lib/client/block/MapActionInitializers.js +0 -93
- package/lib/client/block/MapBlock.js +0 -38
- package/lib/client/block/MapBlockDesigner.js +0 -196
- package/lib/client/block/MapBlockInitializer.js +0 -124
- package/lib/client/block/MapBlockProvider.js +0 -91
- package/lib/client/block/index.js +0 -58
- package/lib/client/block/utils.js +0 -102
- package/lib/client/components/AMap/Block.js +0 -350
- package/lib/client/components/AMap/Map.js +0 -458
- package/lib/client/components/AMap/Search.js +0 -121
- package/lib/client/components/AMap/index.js +0 -27
- package/lib/client/components/Configuration.js +0 -160
- package/lib/client/components/Designer.js +0 -167
- package/lib/client/components/GoogleMaps/Block.js +0 -370
- package/lib/client/components/GoogleMaps/Map.js +0 -466
- package/lib/client/components/GoogleMaps/Search.js +0 -128
- package/lib/client/components/GoogleMaps/index.js +0 -27
- package/lib/client/components/GoogleMaps/utils.js +0 -44
- package/lib/client/components/Map.js +0 -50
- package/lib/client/components/MapBlock.js +0 -40
- package/lib/client/components/MapComponent.js +0 -42
- package/lib/client/components/ReadPretty.js +0 -56
- package/lib/client/components/index.js +0 -71
- package/lib/client/constants.js +0 -19
- package/lib/client/fields/circle.js +0 -32
- package/lib/client/fields/index.js +0 -17
- package/lib/client/fields/lineString.js +0 -32
- package/lib/client/fields/point.js +0 -32
- package/lib/client/fields/polygon.js +0 -32
- package/lib/client/fields/schema.js +0 -64
- package/lib/client/hooks/index.js +0 -16
- package/lib/client/hooks/useMapConfiguration.js +0 -54
- package/lib/client/index.js +0 -73
- package/lib/client/initialize.js +0 -50
- package/lib/client/locale/index.js +0 -38
- package/lib/client/types.js +0 -5
- package/lib/client/utils.js +0 -1
- package/lib/index.js +0 -13
- package/lib/locale/en-US.js +0 -9
- package/lib/locale/fr-FR.js +0 -9
- package/lib/locale/pt-BR.js +0 -54
- package/lib/locale/zh-CN.js +0 -57
- package/lib/server/actions/index.js +0 -55
- package/lib/server/collections/mapConfiguration.js +0 -30
- package/lib/server/constants.js +0 -8
- package/lib/server/fields/circle.js +0 -58
- package/lib/server/fields/index.js +0 -49
- package/lib/server/fields/lineString.js +0 -65
- package/lib/server/fields/point.js +0 -68
- package/lib/server/fields/polygon.js +0 -64
- package/lib/server/helpers/index.js +0 -32
- package/lib/server/index.js +0 -13
- package/lib/server/plugin.js +0 -79
- package/lib/server/value-parsers/index.js +0 -75
- package/src/client/block/MapActionInitializers.tsx +0 -97
- package/src/client/block/MapBlock.tsx +0 -11
- package/src/client/block/MapBlockDesigner.tsx +0 -161
- package/src/client/block/MapBlockInitializer.tsx +0 -91
- package/src/client/block/MapBlockProvider.tsx +0 -55
- package/src/client/block/index.tsx +0 -35
- package/src/client/block/utils.ts +0 -81
- package/src/client/components/AMap/Block.tsx +0 -314
- package/src/client/components/AMap/Map.tsx +0 -461
- package/src/client/components/AMap/Search.tsx +0 -92
- package/src/client/components/AMap/index.ts +0 -2
- package/src/client/components/Configuration.tsx +0 -117
- package/src/client/components/Designer.tsx +0 -147
- package/src/client/components/GoogleMaps/Block.tsx +0 -341
- package/src/client/components/GoogleMaps/Map.tsx +0 -470
- package/src/client/components/GoogleMaps/Search.tsx +0 -107
- package/src/client/components/GoogleMaps/index.ts +0 -2
- package/src/client/components/GoogleMaps/utils.ts +0 -33
- package/src/client/components/Map.tsx +0 -33
- package/src/client/components/MapBlock.tsx +0 -24
- package/src/client/components/MapComponent.tsx +0 -23
- package/src/client/components/ReadPretty.tsx +0 -28
- package/src/client/components/index.ts +0 -6
- package/src/client/constants.ts +0 -11
- package/src/client/fields/circle.ts +0 -23
- package/src/client/fields/index.ts +0 -11
- package/src/client/fields/lineString.ts +0 -23
- package/src/client/fields/point.ts +0 -23
- package/src/client/fields/polygon.ts +0 -23
- package/src/client/fields/schema.ts +0 -54
- package/src/client/hooks/index.ts +0 -1
- package/src/client/hooks/useMapConfiguration.ts +0 -42
- package/src/client/index.tsx +0 -55
- package/src/client/initialize.tsx +0 -32
- package/src/client/locale/index.ts +0 -19
- package/src/client/types.ts +0 -1
- package/src/client/utils.ts +0 -0
- package/src/index.ts +0 -1
- package/src/locale/en-US.ts +0 -3
- package/src/locale/fr-FR.ts +0 -3
- package/src/locale/pt-BR.ts +0 -51
- package/src/locale/zh-CN.ts +0 -52
- package/src/server/__tests__/fields.test.ts +0 -157
- package/src/server/actions/index.ts +0 -44
- package/src/server/collections/mapConfiguration.ts +0 -29
- package/src/server/constants.ts +0 -1
- package/src/server/fields/.gitkeep +0 -0
- package/src/server/fields/circle.ts +0 -48
- package/src/server/fields/index.ts +0 -4
- package/src/server/fields/lineString.ts +0 -55
- package/src/server/fields/point.ts +0 -58
- package/src/server/fields/polygon.ts +0 -54
- package/src/server/helpers/index.ts +0 -25
- package/src/server/index.ts +0 -1
- package/src/server/plugin.ts +0 -57
- package/src/server/value-parsers/index.ts +0 -55
- /package/{lib → dist}/client/block/MapActionInitializers.d.ts +0 -0
- /package/{lib → dist}/client/block/MapBlock.d.ts +0 -0
- /package/{lib → dist}/client/block/MapBlockDesigner.d.ts +0 -0
- /package/{lib → dist}/client/block/MapBlockInitializer.d.ts +0 -0
- /package/{lib → dist}/client/block/MapBlockProvider.d.ts +0 -0
- /package/{lib → dist}/client/block/index.d.ts +0 -0
- /package/{lib → dist}/client/block/utils.d.ts +0 -0
- /package/{lib → dist}/client/components/AMap/Block.d.ts +0 -0
- /package/{lib → dist}/client/components/AMap/Map.d.ts +0 -0
- /package/{lib → dist}/client/components/AMap/Search.d.ts +0 -0
- /package/{lib → dist}/client/components/AMap/index.d.ts +0 -0
- /package/{lib → dist}/client/components/Configuration.d.ts +0 -0
- /package/{lib → dist}/client/components/Designer.d.ts +0 -0
- /package/{lib → dist}/client/components/GoogleMaps/Block.d.ts +0 -0
- /package/{lib → dist}/client/components/GoogleMaps/Map.d.ts +0 -0
- /package/{lib → dist}/client/components/GoogleMaps/Search.d.ts +0 -0
- /package/{lib → dist}/client/components/GoogleMaps/index.d.ts +0 -0
- /package/{lib → dist}/client/components/GoogleMaps/utils.d.ts +0 -0
- /package/{lib → dist}/client/components/Map.d.ts +0 -0
- /package/{lib → dist}/client/components/MapBlock.d.ts +0 -0
- /package/{lib → dist}/client/components/MapComponent.d.ts +0 -0
- /package/{lib → dist}/client/components/ReadPretty.d.ts +0 -0
- /package/{lib → dist}/client/components/index.d.ts +0 -0
- /package/{lib → dist}/client/constants.d.ts +0 -0
- /package/{lib → dist}/client/fields/circle.d.ts +0 -0
- /package/{lib → dist}/client/fields/index.d.ts +0 -0
- /package/{lib → dist}/client/fields/lineString.d.ts +0 -0
- /package/{lib → dist}/client/fields/point.d.ts +0 -0
- /package/{lib → dist}/client/fields/polygon.d.ts +0 -0
- /package/{lib → dist}/client/fields/schema.d.ts +0 -0
- /package/{lib → dist}/client/hooks/index.d.ts +0 -0
- /package/{lib → dist}/client/hooks/useMapConfiguration.d.ts +0 -0
- /package/{lib → dist}/client/index.d.ts +0 -0
- /package/{lib → dist}/client/initialize.d.ts +0 -0
- /package/{lib → dist}/client/locale/index.d.ts +0 -0
- /package/{lib → dist}/client/types.d.ts +0 -0
- /package/{lib → dist}/client/utils.d.ts +0 -0
- /package/{lib → dist}/locale/en-US.d.ts +0 -0
- /package/{lib → dist}/locale/fr-FR.d.ts +0 -0
- /package/{lib → dist}/locale/pt-BR.d.ts +0 -0
- /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
- /package/{lib → dist}/server/actions/index.d.ts +0 -0
- /package/{lib → dist}/server/collections/mapConfiguration.d.ts +0 -0
- /package/{lib → dist}/server/constants.d.ts +0 -0
- /package/{lib → dist}/server/fields/circle.d.ts +0 -0
- /package/{lib → dist}/server/fields/index.d.ts +0 -0
- /package/{lib → dist}/server/fields/lineString.d.ts +0 -0
- /package/{lib → dist}/server/fields/point.d.ts +0 -0
- /package/{lib → dist}/server/fields/polygon.d.ts +0 -0
- /package/{lib → dist}/server/helpers/index.d.ts +0 -0
- /package/{lib → dist}/server/index.d.ts +0 -0
- /package/{lib → dist}/server/plugin.d.ts +0 -0
- /package/{lib → dist}/server/value-parsers/index.d.ts +0 -0
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { SchemaComponentOptions, SchemaInitializerContext, SchemaInitializerProvider } from '@nocobase/client';
|
|
2
|
-
import React, { useContext, useEffect } from 'react';
|
|
3
|
-
import { generateNTemplate } from '../locale';
|
|
4
|
-
import { MapActionInitializers } from './MapActionInitializers';
|
|
5
|
-
import { MapBlock } from './MapBlock';
|
|
6
|
-
import { MapBlockDesigner } from './MapBlockDesigner';
|
|
7
|
-
import { MapBlockInitializer } from './MapBlockInitializer';
|
|
8
|
-
import { MapBlockProvider, useMapBlockProps } from './MapBlockProvider';
|
|
9
|
-
|
|
10
|
-
export const MapBlockOptions: React.FC = (props) => {
|
|
11
|
-
const items = useContext<any>(SchemaInitializerContext);
|
|
12
|
-
const children = items.BlockInitializers.items[0].children;
|
|
13
|
-
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (!children.find((item) => item.component === 'MapBlockInitializer')) {
|
|
16
|
-
children.push({
|
|
17
|
-
key: 'mapBlock',
|
|
18
|
-
type: 'item',
|
|
19
|
-
title: generateNTemplate('Map'),
|
|
20
|
-
component: 'MapBlockInitializer',
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}, []);
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<SchemaInitializerProvider initializers={{ MapActionInitializers }}>
|
|
27
|
-
<SchemaComponentOptions
|
|
28
|
-
scope={{ useMapBlockProps }}
|
|
29
|
-
components={{ MapBlockInitializer, MapBlockDesigner, MapBlockProvider, MapBlock }}
|
|
30
|
-
>
|
|
31
|
-
{props.children}
|
|
32
|
-
</SchemaComponentOptions>
|
|
33
|
-
</SchemaInitializerProvider>
|
|
34
|
-
);
|
|
35
|
-
};
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { ISchema } from '@formily/react';
|
|
2
|
-
import { uid } from '@formily/shared';
|
|
3
|
-
|
|
4
|
-
export const createMapBlockSchema = (options) => {
|
|
5
|
-
const { collection, resource, fieldNames, ...others } = options;
|
|
6
|
-
const schema: ISchema = {
|
|
7
|
-
type: 'void',
|
|
8
|
-
'x-acl-action': `${resource || collection}:list`,
|
|
9
|
-
'x-decorator': 'MapBlockProvider',
|
|
10
|
-
'x-decorator-props': {
|
|
11
|
-
collection: collection,
|
|
12
|
-
resource: resource || collection,
|
|
13
|
-
action: 'list',
|
|
14
|
-
fieldNames,
|
|
15
|
-
params: {
|
|
16
|
-
paginate: false,
|
|
17
|
-
},
|
|
18
|
-
...others,
|
|
19
|
-
},
|
|
20
|
-
'x-designer': 'MapBlockDesigner',
|
|
21
|
-
'x-component': 'CardItem',
|
|
22
|
-
// 保存当前筛选区块所能过滤的数据区块
|
|
23
|
-
'x-filter-targets': [],
|
|
24
|
-
properties: {
|
|
25
|
-
actions: {
|
|
26
|
-
type: 'void',
|
|
27
|
-
'x-initializer': 'MapActionInitializers',
|
|
28
|
-
'x-component': 'ActionBar',
|
|
29
|
-
'x-component-props': {
|
|
30
|
-
style: {
|
|
31
|
-
marginBottom: 16,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
properties: {},
|
|
35
|
-
},
|
|
36
|
-
[uid()]: {
|
|
37
|
-
type: 'void',
|
|
38
|
-
'x-component': 'MapBlock',
|
|
39
|
-
'x-component-props': {
|
|
40
|
-
useProps: '{{ useMapBlockProps }}',
|
|
41
|
-
},
|
|
42
|
-
properties: {
|
|
43
|
-
drawer: {
|
|
44
|
-
type: 'void',
|
|
45
|
-
'x-component': 'Action.Drawer',
|
|
46
|
-
'x-component-props': {
|
|
47
|
-
className: 'nb-action-popup',
|
|
48
|
-
},
|
|
49
|
-
title: '{{ t("View record") }}',
|
|
50
|
-
properties: {
|
|
51
|
-
tabs: {
|
|
52
|
-
type: 'void',
|
|
53
|
-
'x-component': 'Tabs',
|
|
54
|
-
'x-component-props': {},
|
|
55
|
-
'x-initializer': 'TabPaneInitializers',
|
|
56
|
-
properties: {
|
|
57
|
-
tab1: {
|
|
58
|
-
type: 'void',
|
|
59
|
-
title: '{{t("Details")}}',
|
|
60
|
-
'x-component': 'Tabs.TabPane',
|
|
61
|
-
'x-designer': 'Tabs.Designer',
|
|
62
|
-
'x-component-props': {},
|
|
63
|
-
properties: {
|
|
64
|
-
grid: {
|
|
65
|
-
type: 'void',
|
|
66
|
-
'x-component': 'Grid',
|
|
67
|
-
'x-initializer': 'RecordBlockInitializers',
|
|
68
|
-
properties: {},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
return schema;
|
|
81
|
-
};
|
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
import { CheckOutlined, EnvironmentOutlined, ExpandOutlined } from '@ant-design/icons';
|
|
2
|
-
import { RecursionField, Schema, useFieldSchema } from '@formily/react';
|
|
3
|
-
import {
|
|
4
|
-
ActionContextProvider,
|
|
5
|
-
css,
|
|
6
|
-
RecordProvider,
|
|
7
|
-
useCollection,
|
|
8
|
-
useCompile,
|
|
9
|
-
useFilterAPI,
|
|
10
|
-
useProps,
|
|
11
|
-
} from '@nocobase/client';
|
|
12
|
-
import { useMemoizedFn } from 'ahooks';
|
|
13
|
-
import { Button, Space } from 'antd';
|
|
14
|
-
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
15
|
-
import { defaultImage, selectedImage } from '../../constants';
|
|
16
|
-
import { useMapTranslation } from '../../locale';
|
|
17
|
-
import { AMapComponent, AMapForwardedRefProps } from './Map';
|
|
18
|
-
|
|
19
|
-
export const AMapBlock = (props) => {
|
|
20
|
-
const { fieldNames, dataSource = [], fixedBlock, zoom, setSelectedRecordKeys } = useProps(props);
|
|
21
|
-
const { getField, getPrimaryKey } = useCollection();
|
|
22
|
-
const field = getField(fieldNames?.field);
|
|
23
|
-
const [isMapInitialization, setIsMapInitialization] = useState(false);
|
|
24
|
-
const mapRef = useRef<AMapForwardedRefProps>();
|
|
25
|
-
const geometryUtils: AMap.IGeometryUtil = mapRef.current?.aMap?.GeometryUtil;
|
|
26
|
-
const [record, setRecord] = useState();
|
|
27
|
-
const [selectingMode, setSelecting] = useState('');
|
|
28
|
-
const { t } = useMapTranslation();
|
|
29
|
-
const compile = useCompile();
|
|
30
|
-
const { isConnected, doFilter } = useFilterAPI();
|
|
31
|
-
const [, setPrevSelected] = useState(null);
|
|
32
|
-
const selectingModeRef = useRef(selectingMode);
|
|
33
|
-
selectingModeRef.current = selectingMode;
|
|
34
|
-
|
|
35
|
-
const setOverlayOptions = (overlay: AMap.Polygon | AMap.Marker, state?: boolean) => {
|
|
36
|
-
const extData = overlay.getExtData();
|
|
37
|
-
const selected = typeof state === 'undefined' ? extData.selected : !state;
|
|
38
|
-
extData.selected = !selected;
|
|
39
|
-
if ('setIcon' in overlay) {
|
|
40
|
-
overlay.setIcon(
|
|
41
|
-
new mapRef.current.aMap.Icon({
|
|
42
|
-
imageSize: [19, 32],
|
|
43
|
-
image: selected ? defaultImage : selectedImage,
|
|
44
|
-
} as AMap.IconOpts),
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
(overlay as AMap.Polygon).setOptions({
|
|
48
|
-
extData,
|
|
49
|
-
...(selected
|
|
50
|
-
? { strokeColor: '#4e9bff', fillColor: '#4e9bff' }
|
|
51
|
-
: { strokeColor: '#F18b62', fillColor: '#F18b62' }),
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const removeSelection = () => {
|
|
56
|
-
if (!mapRef.current) return;
|
|
57
|
-
mapRef.current.mouseTool().close(true);
|
|
58
|
-
mapRef.current.editor().setTarget(null);
|
|
59
|
-
mapRef.current.editor().close();
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// selection
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
if (selectingMode !== 'selection') {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (!mapRef.current.editor()) {
|
|
68
|
-
mapRef.current.createEditor('polygon');
|
|
69
|
-
mapRef.current.createMouseTool('polygon');
|
|
70
|
-
} else {
|
|
71
|
-
mapRef.current.executeMouseTool('polygon');
|
|
72
|
-
}
|
|
73
|
-
return () => {
|
|
74
|
-
removeSelection();
|
|
75
|
-
};
|
|
76
|
-
}, [selectingMode]);
|
|
77
|
-
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
if (selectingMode) {
|
|
80
|
-
return () => {
|
|
81
|
-
if (!selectingModeRef.current) {
|
|
82
|
-
mapRef.current.map.getAllOverlays().forEach((o) => {
|
|
83
|
-
setOverlayOptions(o, false);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}, [selectingMode]);
|
|
89
|
-
|
|
90
|
-
const onSelectingComplete = useMemoizedFn(() => {
|
|
91
|
-
const selectingOverlay = mapRef.current.editor().getTarget();
|
|
92
|
-
const overlays = mapRef.current.map.getAllOverlays();
|
|
93
|
-
const selectedOverlays = overlays.filter((o) => {
|
|
94
|
-
if (o === selectingOverlay || o.getExtData().id === undefined) return;
|
|
95
|
-
if ('getPosition' in o) {
|
|
96
|
-
return geometryUtils.isPointInRing(o.getPosition(), selectingOverlay.getPath() as any);
|
|
97
|
-
}
|
|
98
|
-
return geometryUtils.doesRingRingIntersect(o.getPath(), selectingOverlay.getPath() as any);
|
|
99
|
-
});
|
|
100
|
-
const ids = selectedOverlays.map((o) => {
|
|
101
|
-
setOverlayOptions(o, true);
|
|
102
|
-
return o.getExtData().id;
|
|
103
|
-
});
|
|
104
|
-
setSelectedRecordKeys((lastIds) => ids.concat(lastIds));
|
|
105
|
-
selectingOverlay.remove();
|
|
106
|
-
mapRef.current.editor().close();
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
useEffect(() => {
|
|
110
|
-
if (!field || !mapRef.current) return;
|
|
111
|
-
const overlays = dataSource
|
|
112
|
-
.map((item) => {
|
|
113
|
-
const data = item[fieldNames?.field];
|
|
114
|
-
if (!data) return;
|
|
115
|
-
const overlay = mapRef.current.setOverlay(field.type, data, {
|
|
116
|
-
strokeColor: '#4e9bff',
|
|
117
|
-
fillColor: '#4e9bff',
|
|
118
|
-
cursor: 'pointer',
|
|
119
|
-
label: {
|
|
120
|
-
direction: 'bottom',
|
|
121
|
-
offset: [0, 5],
|
|
122
|
-
content: fieldNames?.marker ? compile(item[fieldNames.marker]) : undefined,
|
|
123
|
-
},
|
|
124
|
-
extData: {
|
|
125
|
-
id: item[getPrimaryKey()],
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
return overlay;
|
|
129
|
-
})
|
|
130
|
-
.filter(Boolean);
|
|
131
|
-
mapRef.current.map?.setFitView(overlays);
|
|
132
|
-
|
|
133
|
-
const events = overlays.map((o: AMap.Marker) => {
|
|
134
|
-
const onClick = (e) => {
|
|
135
|
-
const overlay: AMap.Polygon | AMap.Marker = e.target;
|
|
136
|
-
const extData = overlay.getExtData();
|
|
137
|
-
if (!extData) return;
|
|
138
|
-
if (selectingModeRef.current) {
|
|
139
|
-
if (selectingModeRef.current === 'click') {
|
|
140
|
-
setSelectedRecordKeys((keys) =>
|
|
141
|
-
extData.selected ? keys.filter((key) => key !== extData.id) : [...keys, extData.id],
|
|
142
|
-
);
|
|
143
|
-
setOverlayOptions(overlay);
|
|
144
|
-
}
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
const data = dataSource?.find((item) => {
|
|
148
|
-
return extData.id === item[getPrimaryKey()];
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
// 筛选区块模式
|
|
152
|
-
if (isConnected) {
|
|
153
|
-
setPrevSelected((prev) => {
|
|
154
|
-
prev && clearSelected(prev);
|
|
155
|
-
if (prev === o) {
|
|
156
|
-
clearSelected(o);
|
|
157
|
-
|
|
158
|
-
// 删除过滤参数
|
|
159
|
-
doFilter(null);
|
|
160
|
-
return null;
|
|
161
|
-
} else {
|
|
162
|
-
selectMarker(o);
|
|
163
|
-
doFilter(data[getPrimaryKey()], (target) => target.field || getPrimaryKey(), '$eq');
|
|
164
|
-
}
|
|
165
|
-
return o;
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (data) {
|
|
172
|
-
setRecord(data);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
o.on('click', onClick);
|
|
176
|
-
return () => o.off('click', onClick);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
return () => {
|
|
180
|
-
overlays.forEach((ov) => {
|
|
181
|
-
ov.remove();
|
|
182
|
-
});
|
|
183
|
-
events.forEach((e) => e());
|
|
184
|
-
};
|
|
185
|
-
}, [dataSource, isMapInitialization, fieldNames, field.type, isConnected]);
|
|
186
|
-
|
|
187
|
-
useEffect(() => {
|
|
188
|
-
setTimeout(() => {
|
|
189
|
-
setSelectedRecordKeys([]);
|
|
190
|
-
});
|
|
191
|
-
}, [dataSource]);
|
|
192
|
-
|
|
193
|
-
const mapRefCallback = (instance: AMapForwardedRefProps) => {
|
|
194
|
-
mapRef.current = instance;
|
|
195
|
-
setIsMapInitialization(!!instance?.map && !instance.errMessage);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
return (
|
|
199
|
-
<div
|
|
200
|
-
className={css`
|
|
201
|
-
position: relative;
|
|
202
|
-
height: 100%;
|
|
203
|
-
`}
|
|
204
|
-
>
|
|
205
|
-
<div
|
|
206
|
-
className={css`
|
|
207
|
-
position: absolute;
|
|
208
|
-
left: 10px;
|
|
209
|
-
top: 10px;
|
|
210
|
-
z-index: 999;
|
|
211
|
-
`}
|
|
212
|
-
>
|
|
213
|
-
{isMapInitialization && !mapRef.current.errMessage ? (
|
|
214
|
-
<Space direction="vertical">
|
|
215
|
-
<Button
|
|
216
|
-
style={{
|
|
217
|
-
color: !selectingMode ? '#F18b62' : undefined,
|
|
218
|
-
borderColor: 'currentcolor',
|
|
219
|
-
}}
|
|
220
|
-
onClick={(e) => {
|
|
221
|
-
e.stopPropagation();
|
|
222
|
-
setSelecting('');
|
|
223
|
-
}}
|
|
224
|
-
icon={<EnvironmentOutlined />}
|
|
225
|
-
></Button>
|
|
226
|
-
<Button
|
|
227
|
-
style={{
|
|
228
|
-
color: selectingMode === 'selection' ? '#F18b62' : undefined,
|
|
229
|
-
borderColor: 'currentcolor',
|
|
230
|
-
}}
|
|
231
|
-
onClick={(e) => {
|
|
232
|
-
e.stopPropagation();
|
|
233
|
-
setSelecting('selection');
|
|
234
|
-
}}
|
|
235
|
-
icon={<ExpandOutlined />}
|
|
236
|
-
></Button>
|
|
237
|
-
{selectingMode === 'selection' ? (
|
|
238
|
-
<Button
|
|
239
|
-
type="primary"
|
|
240
|
-
icon={<CheckOutlined />}
|
|
241
|
-
title={t('Confirm selection')}
|
|
242
|
-
onClick={onSelectingComplete}
|
|
243
|
-
></Button>
|
|
244
|
-
) : null}
|
|
245
|
-
</Space>
|
|
246
|
-
) : null}
|
|
247
|
-
</div>
|
|
248
|
-
<MapBlockDrawer record={record} setVisible={setRecord} />
|
|
249
|
-
<AMapComponent
|
|
250
|
-
{...field?.uiSchema?.['x-component-props']}
|
|
251
|
-
ref={mapRefCallback}
|
|
252
|
-
style={{ height: fixedBlock ? '100%' : null }}
|
|
253
|
-
zoom={zoom}
|
|
254
|
-
disabled
|
|
255
|
-
block
|
|
256
|
-
overlayCommonOptions={{
|
|
257
|
-
strokeColor: '#F18b62',
|
|
258
|
-
fillColor: '#F18b62',
|
|
259
|
-
}}
|
|
260
|
-
></AMapComponent>
|
|
261
|
-
</div>
|
|
262
|
-
);
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
const MapBlockDrawer = (props) => {
|
|
266
|
-
const { setVisible, record } = props;
|
|
267
|
-
const fieldSchema = useFieldSchema();
|
|
268
|
-
const schema: Schema = useMemo(
|
|
269
|
-
() =>
|
|
270
|
-
fieldSchema.reduceProperties((buf, current) => {
|
|
271
|
-
if (current.name === 'drawer') {
|
|
272
|
-
return current;
|
|
273
|
-
}
|
|
274
|
-
return buf;
|
|
275
|
-
}, null),
|
|
276
|
-
[fieldSchema],
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
return (
|
|
280
|
-
schema && (
|
|
281
|
-
<ActionContextProvider value={{ visible: !!record, setVisible }}>
|
|
282
|
-
<RecordProvider record={record}>
|
|
283
|
-
<RecursionField schema={schema} name={schema.name} />
|
|
284
|
-
</RecordProvider>
|
|
285
|
-
</ActionContextProvider>
|
|
286
|
-
)
|
|
287
|
-
);
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
function clearSelected(marker: AMap.Marker | AMap.Polygon | AMap.Polyline | AMap.Circle) {
|
|
291
|
-
if ((marker as AMap.Marker).dom) {
|
|
292
|
-
(marker as AMap.Marker).dom.style.filter = 'none';
|
|
293
|
-
|
|
294
|
-
// AMap.Polygon | AMap.Polyline | AMap.Circle 都有 setOptions 方法
|
|
295
|
-
} else if ((marker as AMap.Polygon).setOptions) {
|
|
296
|
-
(marker as AMap.Polygon).setOptions({
|
|
297
|
-
strokeColor: '#4e9bff',
|
|
298
|
-
fillColor: '#4e9bff',
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
function selectMarker(marker: AMap.Marker | AMap.Polygon | AMap.Polyline | AMap.Circle) {
|
|
304
|
-
if ((marker as AMap.Marker).dom) {
|
|
305
|
-
(marker as AMap.Marker).dom.style.filter = 'brightness(1.2) contrast(1.2) hue-rotate(180deg)';
|
|
306
|
-
|
|
307
|
-
// AMap.Polygon | AMap.Polyline | AMap.Circle 都有 setOptions 方法
|
|
308
|
-
} else if ((marker as AMap.Polygon).setOptions) {
|
|
309
|
-
(marker as AMap.Polygon).setOptions({
|
|
310
|
-
strokeColor: '#F18b62',
|
|
311
|
-
fillColor: '#F18b62',
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
}
|