Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 添加腾讯和百度底图 #56

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/components/app-header/base-map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,25 @@ export const BaseMap = () => {
label: 'Mapbox',
value: 'Mapbox',
},
{
img: 'https://mdn.alipayobjects.com/huamei_k6sfo0/afts/img/A*YKJtR5vfbtIAAAAAAAAAAAAADjWqAQ/original',
label: t('btn.setting_btn.tencent'),
value: 'Tencent',
},
{
img: 'https://mdn.alipayobjects.com/huamei_k6sfo0/afts/img/A*kRvdTLte60cAAAAAAAAAAAAADjWqAQ/original',
label: t('btn.setting_btn.baidu'),
value: 'Baidu',
},
];

const handleChange = (e: 'Gaode' | 'Mapbox') => {
const handleChange = (e: 'Gaode' | 'Mapbox' | 'Baidu' | 'Tencent') => {
setBaseMap(e);
setMapOptions({
...mapOptions,
style: theme === 'dark' ? 'dark' : 'normal',
});
setCoordConvert(e === 'Gaode' ? 'GCJ02' : 'WGS84');
setCoordConvert(e === 'Gaode' ? 'GCJ02' : e === 'Baidu' ? 'BD09' : 'WGS84');
if (e !== baseMap) {
location.reload();
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/app-header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export const AppHeader: React.FC<AppHeaderProps> = ({ toolbar }) => {
<Dropdown
menu={{
items: DropdownMenuItems,
onClick: ({ key }) => {
onClick: ({ key }: any) => {
onDownload(key);
},
}}
Expand Down
18 changes: 10 additions & 8 deletions src/components/app-map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { message } from 'antd';
import type { ReactNode } from 'react';
import React, { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { GaodeConfig, MapBoxConfig } from '../../constants';
import { BaiduConfig, GaodeConfig, MapBoxConfig } from '../../constants';
import { useFeature, useGlobal } from '../../recoil';
import { getParamsNew, getUrlFeatureCollection } from '../../utils';
import { prettierText } from '../../utils/prettier-text';
Expand Down Expand Up @@ -35,14 +35,16 @@ export const AppMap: React.FC<AppMapProps> = ({ children }) => {
});

const mapOptions = useMemo(() => {
if (baseMap === 'Mapbox') {
return {
...MapBoxConfig,
...baseMapOptions,
};
}
const mapConfigMapping = {
Mapbox: MapBoxConfig,
Baidu: BaiduConfig,
Tencent: {},
} as any;

const config = mapConfigMapping[baseMap] || GaodeConfig;

return {
...GaodeConfig,
...config,
...baseMapOptions,
};
}, [baseMap, baseMapOptions]);
Expand Down
1 change: 1 addition & 0 deletions src/components/map-content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const MapContent: React.FC<MapContentProps> = ({
options={[
{ label: 'GCJ02', value: 'GCJ02' },
{ label: 'WGS84', value: 'WGS84' },
{ label: 'BD09', value: 'BD09' },
]}
onChange={setCoordConvert}
/>
Expand Down
3 changes: 2 additions & 1 deletion src/components/map-control-group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export const MapControlGroup: React.FC<MapControlGroupProps> = ({
{baseMap === 'Gaode' && isControlGroupState.officialLayerControl && (
<OfficialLayerControl />
)}
{isControlGroupState.mapThemeControl && <MapThemeControl />}
{isControlGroupState.mapThemeControl &&
(baseMap === 'Gaode' || baseMap === 'Mapbox') && <MapThemeControl />}
{isControlGroupState.geoLocateControl && (
<GeoLocateControl position="topleft" className={styles.fullScreen} />
)}
Expand Down
5 changes: 5 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export const GaodeConfig = {
},
};

export const BaiduConfig = {
token: '2TVUvWQGt8J3HwJpkZ4qVLYBVpxzudTa',
};


export const LayerZIndex = 100;

export const GOOGLE_TILE_MAP_URL =
Expand Down
2 changes: 2 additions & 0 deletions src/locales/langs/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export default {
'btn.setting_btn.kaiQi': 'Open',
'btn.setting_btn.shiFouZhanShiYuan': 'Display serial number on layer',
'btn.setting_btn.gaoDe': 'Gaode',
'btn.setting_btn.tencent': 'Tencent',
'btn.setting_btn.baidu': 'Baidu',
'btn.setting_btn.diTuDiTuQie': 'Switch base map',
'btn.setting_btn.ziDongSuoFangZhi': 'Auto zoom to all elements visible',
'btn.setting_btn.huaRu': 'Mouse on',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/langs/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export default {
'btn.setting_btn.kaiQi': '开启',
'btn.setting_btn.shiFouZhanShiYuan': '是否展示元素序号',
'btn.setting_btn.gaoDe': '高德',
'btn.setting_btn.tencent': '腾讯',
'btn.setting_btn.baidu': '百度',
'btn.setting_btn.diTuDiTuQie': '地图底图切换',
'btn.setting_btn.ziDongSuoFangZhi': '自动缩放至所有元素可见',
'btn.setting_btn.huaRu': '划入',
Expand Down
2 changes: 1 addition & 1 deletion src/recoil/atomState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const popupTriggerState = atom<'click' | 'hover'>({
effects: [localStorageEffect(LocalStorageKey.PopupTrigger)],
});

const baseMapState = atom<'Gaode' | 'Mapbox'>({
const baseMapState = atom<'Gaode' | 'Mapbox' | 'Baidu' | 'Tencent'>({
key: 'baseMap',
effects: [localStorageEffect(LocalStorageKey.BaseMap)],
});
Expand Down
34 changes: 32 additions & 2 deletions src/recoil/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ import { useTranslation } from 'react-i18next';
import { useRecoilState } from 'recoil';
import { FeatureKey } from '../constants';
import type { FilterField, IFeatures } from '../types';
import { gcj02towgs84, transformFeatures, wgs84togcj02 } from '../utils';
import {
bd09togcj02,
bd09towgs84,
gcj02tobd09,
gcj02towgs84,
transformFeatures,
wgs84tobd09,
wgs84togcj02,
} from '../utils';
import { prettierText } from '../utils/prettier-text';
import {
editorTextState,
Expand Down Expand Up @@ -154,14 +162,36 @@ export default function useFeature() {
const revertCoord = useCallback(
(newFeatures: Feature[]) => {
let data = [...newFeatures];
if (coordConvert === 'WGS84' && baseMap === 'Gaode') {
if (
coordConvert === 'WGS84' &&
(baseMap === 'Gaode' || baseMap === 'Tencent')
) {
data = data.map((item) => {
return gcj02towgs84(cloneDeep(item));
});
} else if (coordConvert === 'GCJ02' && baseMap === 'Mapbox') {
data = data.map((item) => {
return wgs84togcj02(cloneDeep(item));
});
} else if (coordConvert === 'GCJ02' && baseMap === 'Baidu') {
data = data.map((item) => {
return bd09togcj02(cloneDeep(item));
});
} else if (coordConvert === 'WGS84' && baseMap === 'Baidu') {
data = data.map((item) => {
return bd09towgs84(cloneDeep(item));
});
} else if (
coordConvert === 'BD09' &&
(baseMap === 'Gaode' || baseMap === 'Tencent')
) {
data = data.map((item) => {
return gcj02tobd09(cloneDeep(item));
});
} else if (coordConvert === 'BD09' && baseMap === 'Mapbox') {
data = data.map((item) => {
return wgs84tobd09(cloneDeep(item));
});
}
return data;
},
Expand Down
32 changes: 32 additions & 0 deletions src/utils/gcoord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,35 @@ export const gcj02towgs84 = (feature: Feature) => {
// @ts-ignore
return gcoord.transform(feature, gcoord.GCJ02, gcoord.WGS84) as Feature;
};

export const gcj02tobd09 = (feature: Feature) => {
if (feature.geometry.type.match(/polygon/i)) {
feature.geometry = JSON.parse(JSON.stringify(feature.geometry));
}
// @ts-ignore
return gcoord.transform(feature, gcoord.GCJ02, gcoord.BD09) as Feature;
};

export const bd09togcj02 = (feature: Feature) => {
if (feature.geometry.type.match(/polygon/i)) {
feature.geometry = JSON.parse(JSON.stringify(feature.geometry));
}
// @ts-ignore
return gcoord.transform(feature, gcoord.BD09, gcoord.GCJ02) as Feature;
};

export const wgs84tobd09 = (feature: Feature) => {
if (feature.geometry.type.match(/polygon/i)) {
feature.geometry = JSON.parse(JSON.stringify(feature.geometry));
}
// @ts-ignore
return gcoord.transform(feature, gcoord.WGS84, gcoord.BD09) as Feature;
};

export const bd09towgs84 = (feature: Feature) => {
if (feature.geometry.type.match(/polygon/i)) {
feature.geometry = JSON.parse(JSON.stringify(feature.geometry));
}
// @ts-ignore
return gcoord.transform(feature, gcoord.BD09, gcoord.WGS84) as Feature;
};
Loading