Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/antvis/L7Editor into feat…
Browse files Browse the repository at this point in the history
…/add-tengxun-baidu
  • Loading branch information
syb01094648 committed Mar 11, 2024
2 parents 9476fed + 62dfa93 commit f6fb92f
Show file tree
Hide file tree
Showing 19 changed files with 274 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"i18n-ally.keystyle": "nested",
"i18n-ally.sortKeys": true,
"i18n-ally.enabledParsers": ["ts", "json"],
"i18n-ally.sourceLanguage": "en-US",
"i18n-ally.sourceLanguage": "zh-CN",
"i18n-ally.displayLanguage": "zh-CN",
"i18n-ally.enabledFrameworks": ["react"]
}
33 changes: 20 additions & 13 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ title: API
| wasmPath | sam 组件的 wasm 路径 | `string` | `\` |
| showDrawDistance | 绘制时是否展示距离文本 | `boolean` | `false` |
| showDrawArea | 绘制时是否展示面积文本 | `boolean` | `false` |
| customTiles | 自定义瓦片底图图层 | [CustomTilesProps](#customtilesprops) | `[]` |

#### `tabItems`

Expand Down Expand Up @@ -98,25 +99,30 @@ LngLat 文本编辑器,可以通过输入 LngLat 数据实现数据展示(目
}
```

#### `officialLayers`¸

底图数据选择

`['googleSatellite'] | ['amapSatellite','amapRoadNet','AmapBuildings', 'amapTraffic']`
#### CustomTilesProps

```js
{
officialLayers: ['amapSatellite', 'amapRoadNet'];
customTiles: [
{
id: 'GaodeSatellite',
image:
'https://mdn.alipayobjects.com/huamei_k6sfo0/afts/img/A*zi2jSqqZ2-8AAAAAAAAAAAAADjWqAQ/original',
title: '高德卫星底图',
layers: [
'https://webst01.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
],
},
];
}
```

| 属性 | 描述 |
| --------------- | ---------- |
| googleSatellite | 谷歌卫星图 |
| amapSatellite | 高德卫星图 |
| amapRoadNet | 高德路网图 |
| amapBuildings | 高德楼块图 |
| amapTraffic | 高德路况图 |
| 属性 | 描述 | 类型 |
| ------ | ------------ | ---------- |
| id | 唯一标识 | `string` |
| image | 图片 | `string` |
| title | 图层名称 | `string` |
| layers | 瓦片图层链接 | `string[]` |

#### coordConvert

Expand Down Expand Up @@ -156,6 +162,7 @@ LngLat 文本编辑器,可以通过输入 LngLat 数据实现数据展示(目
| mapAdministrativeControl | 查看当前行政区域控件 |
| logoControl | Logo 控件 |
| textLayerControl | 文本图层 控件 |
| exportImageControl | 导出图片 控件 |

#### toolbar

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/l7-editor",
"version": "1.1.9",
"version": "1.1.11",
"description": "Geographic data editing tool based on L7",
"files": [
"lib",
Expand Down Expand Up @@ -36,6 +36,7 @@
"@antv/larkmap": "^1.4.4",
"@antv/sam": "^0.1.0",
"@emotion/css": "^11.11.2",
"@mapbox/geojsonhint": "^3.3.0",
"@mapbox/togeojson": "^0.16.0",
"@turf/turf": "^6.5.0",
"ahooks": "^3.7.0",
Expand Down
1 change: 0 additions & 1 deletion src/components/app-header/btn/import-btn/file-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const FileUpload = forwardRef<any>(function FileUpload({}, ref) {
const { file, onSuccess, onError } = uploadRequestOption;
parserFileToSource(file, t)
.then((dataSource) => {
console.log(dataSource);
if (!dataSource?.columns) {
if (dataSource.data?.features?.length) {
const newData = uploadData;
Expand Down
48 changes: 48 additions & 0 deletions src/components/map-control-group/export-image-control/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ExportImageControl } from '@antv/larkmap';
import { Image, Modal } from 'antd';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { downloadImg } from '.././../../utils';
import useStyle from './styles';

export const ExportImage = () => {
const styles = useStyle();
const [imageData, setImageData] = useState('');
const [isModalOpen, setIsModalOpen] = useState(false);
const { t } = useTranslation();

const onExport = (value: string) => {
setIsModalOpen(true);
setImageData(value);
};

const handle = () => {
setIsModalOpen(false);
setImageData('');
};

const onOk = () => {
setIsModalOpen(false);
downloadImg(imageData);
setImageData('');
};
return (
<>
<ExportImageControl
onExport={onExport}
className={styles.l7ExportImg}
imageType="jpeg"
position={'bottomright'}
/>
<Modal
title={t('export-img-control_title')}
open={isModalOpen}
okText={t('btn.download_btn.xiaZai')}
onOk={onOk}
onCancel={handle}
>
<Image src={imageData} />
</Modal>
</>
);
};
28 changes: 28 additions & 0 deletions src/components/map-control-group/export-image-control/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { css } from '@emotion/css';
import { theme } from 'antd';

const useStyle = () => {
const { useToken } = theme;
const { token } = useToken();

const { colorBgContainer, colorIcon, colorText } =
token;
return {
l7ExportImg: css`
background: ${colorBgContainer};
color: ${colorIcon};
svg {
fill: ${colorIcon} !important;
}
:hover {
background: ${colorBgContainer} !important;
svg {
color: ${colorText} !important;
fill: ${colorText} !important;
}
}
`,
};
};
export default useStyle;
6 changes: 6 additions & 0 deletions src/components/map-control-group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import { AdministrativeSelect } from './administrative-select-control';
import { AutoControl } from './auto-control';
import { ClearControl } from './clear-control';
import DrawControl from './draw-control';
import { ExportImage } from './export-image-control';
import FilterControl from './filter-form-list-control';
import { L7MapOptionControl } from './l7-option-control';
import LayerColorControl from './layer-color-control';
import LocationSearchControl from './location-search-control';
import { MapAdministrativeControl } from './map-administrative-control';
Expand Down Expand Up @@ -45,6 +47,8 @@ const DefaultMapControl: MapControlProps = {
mapAdministrativeControl: true,
logoControl: true,
textLayerControl: true,
exportImageControl: true,
L7MapOptionControl: true,
};
export const MapControlGroup: React.FC<MapControlGroupProps> = ({
mapControl,
Expand Down Expand Up @@ -100,6 +104,8 @@ export const MapControlGroup: React.FC<MapControlGroupProps> = ({
)}
{layerType.includes(OfficeLayerEnum.GoogleSatellite) && <SamControl />}
{isControlGroupState.textLayerControl && <TextLayerControl />}
{isControlGroupState.exportImageControl && <ExportImage />}
{isControlGroupState.L7MapOptionControl && <L7MapOptionControl />}
</>
);
};
82 changes: 82 additions & 0 deletions src/components/map-control-group/l7-option-control/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { CustomControl, useScene } from '@antv/larkmap';
import { Button, Input, Modal, Tooltip, message } from 'antd';
import Clipboard from 'clipboard';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { IconFont } from '../../../components/iconfont';
import useStyles from '../styles';

const { TextArea } = Input;

export const L7MapOptionControl = () => {
const scene = useScene();
const styles = useStyles();
const { t } = useTranslation();
const [isModalOpen, setIsModalOpen] = useState(false);
const [textValue, setTextValue] = useState('');

const showModal = () => {
setIsModalOpen(true);
const optionJson = {
center: [scene.getCenter().lng, scene.getCenter().lat],
zoom: scene.getZoom(),
pitch: Number(scene.getPitch().toFixed(6)),
rotation: scene.getRotation(),
};
setTextValue(JSON.stringify(optionJson, null, 2));
};

const handleOk = () => {
const clipboard = new Clipboard(`#l7-option-copy_btn`, {
text: () => textValue,
});

clipboard.on('success', () => {
setIsModalOpen(false);
message.success(t('layer_contextmenu_popup.fuZhiChengGong'));
clipboard.destroy();
});
};

const handleCancel = () => {
setIsModalOpen(false);
};
return (
<CustomControl position="bottomleft">
<Tooltip placement="left" overlay={t('l7Options.huoqucanshu')}>
<button
className={styles.L7EditorControl}
id="text-layer-control"
onClick={showModal}
>
<IconFont type="icon-xitongzhuangtai" />
</button>
</Tooltip>
<Modal
title={t('l7Options.dangqiancanshu')}
open={isModalOpen}
onCancel={handleCancel}
width={800}
destroyOnClose
footer={
<>
<Button onClick={handleCancel}>
{t('btn.setting_btn.guanBi')}
</Button>
<Button type="primary" id="l7-option-copy_btn" onClick={handleOk}>
{t('layer_contextmenu_popup.fuZhi')}
</Button>
</>
}
>
<TextArea
rows={10}
value={textValue}
onChange={(e) => {
setTextValue(e.target.value);
}}
/>
</Modal>
</CustomControl>
);
};
39 changes: 15 additions & 24 deletions src/components/map-control-group/official-layer-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
OfficeLayerEnum,
} from '../../../constants';
import { useGlobal } from '../../../recoil';
import type { CustomTiles } from '../../../types/l7editor';
import useStyle from './styles';

const layout = {
Expand Down Expand Up @@ -58,14 +59,14 @@ export function OfficialLayerControl() {

const BASE_LAYER_GROUP = [
{
type: OfficeLayerEnum.VectorMap,
id: OfficeLayerEnum.VectorMap,
title: t('official_layer_control.index.shiLiangDiTu'),
image:
'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*qdFDSbvIalgAAAAAAAAAAAAADmJ7AQ/original',
layers: [],
},
{
type: OfficeLayerEnum.GoogleSatellite,
id: OfficeLayerEnum.GoogleSatellite,
title: t('official_layer_control.index.guGeWeiXingTu'),
image:
'https://mdn.alipayobjects.com/huamei_k6sfo0/afts/img/A*zi2jSqqZ2-8AAAAAAAAAAAAADjWqAQ/original',
Expand All @@ -91,15 +92,10 @@ export function OfficialLayerControl() {
return false; // 阻止antd组件自动上传
};

const onItemClick = (item: {
type: any;
image: string;
title: string;
layers: string[];
}) => {
setRadioValue(item.type);
const onItemClick = (item: CustomTiles) => {
setRadioValue(item.id);
setLayerType(
item.type === OfficeLayerEnum.VectorMap ? [] : ([item.type] as string[]),
item.id === OfficeLayerEnum.VectorMap ? [] : ([item.id] as string[]),
);
};

Expand All @@ -108,7 +104,7 @@ export function OfficialLayerControl() {
const cloneCustomTiles = cloneDeep(customTiles);
const newImgUrl = Array.isArray(e.img) ? e.img[0].url : `${base64}`;
cloneCustomTiles[editIndex - 2] = {
type: e.name,
id: e.name,
image: newImgUrl,
title: e.name,
layers: e.urls,
Expand All @@ -120,7 +116,7 @@ export function OfficialLayerControl() {
setCustomTiles((prevState) => [
...prevState,
{
type: e.name,
id: e.name,
image: `${base64}`,
title: e.name,
layers: e.urls,
Expand All @@ -142,18 +138,13 @@ export function OfficialLayerControl() {

const onConfirm = (
e: React.MouseEvent<HTMLElement> | undefined,
item: {
type: string;
image?: string;
title?: string;
layers?: string[];
},
item: CustomTiles,
) => {
e?.stopPropagation();
const newCustomTiles = customTiles.filter((val) => {
return val.type !== item.type;
return val.id !== item.id;
});
if (item.type === radioValue) {
if (item.id === radioValue) {
setRadioValue(OfficeLayerEnum.VectorMap);
setLayerType([]);
}
Expand Down Expand Up @@ -214,15 +205,15 @@ export function OfficialLayerControl() {
const rasterLayer = useMemo(() => {
if (layerType.length) {
const findItem = officeLayerGroup.find(
(item) => item.type === layerType[0],
(item) => item.id === layerType[0],
);
return findItem?.layers.map((item) => {
return (
// eslint-disable-next-line react/jsx-key
<RasterLayer
zIndex={1}
id={
findItem.type === OfficeLayerEnum.GoogleSatellite &&
findItem.id === OfficeLayerEnum.GoogleSatellite &&
item === GOOGLE_TILE_MAP_URL
? 'googleTileMap'
: undefined
Expand Down Expand Up @@ -260,10 +251,10 @@ export function OfficialLayerControl() {
{officeLayerGroup.map((item, index) => {
return (
<div
key={item.type}
key={item.id}
className={classNames([
styles.amapInfoItem,
item.type === radioValue
item.id === radioValue
? styles.itemBorderActive
: styles.itemBorder,
index === officeLayerGroup.length - 1 ? 'item-hover' : '',
Expand Down
2 changes: 1 addition & 1 deletion src/constants/iconfont.js

Large diffs are not rendered by default.

Loading

0 comments on commit f6fb92f

Please sign in to comment.