Skip to content

Commit

Permalink
feat: 新增导出图片组件
Browse files Browse the repository at this point in the history
  • Loading branch information
syb01094648 committed Feb 20, 2024
1 parent f83f565 commit 0f91885
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ LngLat 文本编辑器,可以通过输入 LngLat 数据实现数据展示(目
| mapAdministrativeControl | 查看当前行政区域控件 |
| logoControl | Logo 控件 |
| textLayerControl | 文本图层 控件 |
| exportImageControl | 导出图片 控件 |

#### toolbar

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;
3 changes: 3 additions & 0 deletions src/components/map-control-group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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 LayerColorControl from './layer-color-control';
import LocationSearchControl from './location-search-control';
Expand Down Expand Up @@ -45,6 +46,7 @@ const DefaultMapControl: MapControlProps = {
mapAdministrativeControl: true,
logoControl: true,
textLayerControl: true,
exportImageControl: true,
};
export const MapControlGroup: React.FC<MapControlGroupProps> = ({
mapControl,
Expand Down Expand Up @@ -99,6 +101,7 @@ export const MapControlGroup: React.FC<MapControlGroupProps> = ({
)}
{layerType.includes(OfficeLayerEnum.GoogleSatellite) && <SamControl />}
{isControlGroupState.textLayerControl && <TextLayerControl />}
{isControlGroupState.exportImageControl && <ExportImage />}
</>
);
};
10 changes: 8 additions & 2 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export enum LocalStorageKey {
firstOpening = 'firstOpening',
wasmPath = 'wasmPath',
customTiles = 'customTiles',
showDrawDistance = "showDrawDistance",
showDrawArea = "showDrawArea"
showDrawDistance = 'showDrawDistance',
showDrawArea = 'showDrawArea',
}

export enum LayerId {
Expand All @@ -46,10 +46,16 @@ export const FeatureKey = {
export const MapBoxConfig = {
token:
'pk.eyJ1IjoibGl1dmlnb25nenVvc2hpIiwiYSI6ImNsaGs2czBrcTBvczUzbnFzOHU0dzk2ZWQifQ.hVvTgcbg_Ym-VQz36psLRg',
WebGLParams: {
preserveDrawingBuffer: true,
},
};

export const GaodeConfig = {
token: '5ae4492ef912cbbc93034fea0e66ff2a',
WebGLParams: {
preserveDrawingBuffer: true,
},
};

export const LayerZIndex = 100;
Expand Down
1 change: 1 addition & 0 deletions src/locales/langs/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export default {
'text-layer-control_wenBenTuCengPeiZhi': 'Text Layer Configuration',
'text-layer-control_description':
'Open the text layer configuration, you can display the serial number of all the current data, you can also use the multi-select box to properties fields in the data to select different data for display.',
'export-img-control_title': 'Preview Picture',
'btn.setting_btn.mianJi': 'Show area text when drawing',
'btn.setting_btn.juLi': 'Whether to display distance text when drawing',
};
1 change: 1 addition & 0 deletions src/locales/langs/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export default {
'text-layer-control_wenBenTuCengPeiZhi': '文本图层配置',
'text-layer-control_description':
'开启文本图层配置,可以显示当前所有数据的序号,也可以通过多选框在数据中properties字段去选择不同的数据来进行展示',
'export-img-control_title': '预览图片',
'btn.setting_btn.mianJi': '绘制时是否展示面积文本',
'btn.setting_btn.juLi': '绘制时是否展示距离文本',
};
1 change: 1 addition & 0 deletions src/types/l7editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface MapControlProps {
administrativeSelectControl?: boolean;
mapAdministrativeControl?: boolean;
textLayerControl?: boolean;
exportImageControl?: boolean;
}

export interface ToolbarProps {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export const downloadText = (text: string, ext: string | 'json' | 'txt') => {
aTag.click();
};

export const downloadImg = (link: string) => {
const aTag = document.createElement('a');
aTag.href = link;
aTag.download = `${dayjs().format('YYYY-MM-DD HH:mm:ss')}.jpeg`;
aTag.dispatchEvent(new MouseEvent('click'));
};

export const getParamsNew = (key: string) => {
const temData = new URLSearchParams(window.location.search);
return temData.get(key);
Expand Down

0 comments on commit 0f91885

Please sign in to comment.