Skip to content

Commit

Permalink
fix: 城市点击失效问题 (#81)
Browse files Browse the repository at this point in the history
Co-authored-by: yxh01132861 <[email protected]>
  • Loading branch information
simplexiao and yxh01132861 authored Nov 17, 2023
1 parent 46ff346 commit cbc5b96
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default (props: AreaWidgetProps) => {
const [scene] = useScene();
const { position, showBounds } = props;
const style = useStyle();
const [cityName, setCityName] = useState('全国');
const [regionName, setRegionName] = useState('全国');
const [open, setOpen] = useState(false);
const [loading, setLoading] = useState(false);

Expand Down Expand Up @@ -57,8 +57,9 @@ export default (props: AreaWidgetProps) => {
setBoundBorder(res);
return;
}

if (scene && cityData) {
const data = treeToArr([cityData.cities]).find((item: ICity) => item.name === value.name);
const data = treeToArr([cityData.cities]).find((item: ICity) => item.name.indexOf(value.name) === 0);
if (data) {
scene.setZoomAndCenter(11, [data.lng, data.lat]);
}
Expand All @@ -73,13 +74,13 @@ export default (props: AreaWidgetProps) => {
const onSelectChange = (value: string) => {
const newValue = JSON.parse(value || '');
setOpen(false);
setCityName(newValue.name);
setRegionName(newValue.name);
if (newValue) getBoundsData(newValue);
};

const onClickItem = (v: ICity) => {
setOpen(false);
setCityName(v.name);
setRegionName(v.name);
if (v) getBoundsData(v);
};

Expand Down Expand Up @@ -121,7 +122,7 @@ export default (props: AreaWidgetProps) => {
onClick={() => onClickItem(hot as ICity)}
className={cls(`${CLS_PREFIX}__content-header-item`, style.tabContentItem)}
>
{hot.name.replace('市', '')}
{hot.name}
</div>
);
})}
Expand All @@ -141,14 +142,14 @@ export default (props: AreaWidgetProps) => {
}, [position]);

const onRest = () => {
setCityName('全国');
setRegionName('全国');
setBoundBorder(undefined);
};

const getTitle = () => {
return (
<div className={style.popoverName}>
<div>所在区域:{cityName.replace('市', '').replace('省', '')}</div>
<div>所在区域:{regionName.replace('市', '').replace('省', '')}</div>
<Button type="text" size="small" icon={<CloseOutlined />} onClick={() => onRest()} style={{ marginLeft: 8 }} />
</div>
);
Expand All @@ -170,7 +171,7 @@ export default (props: AreaWidgetProps) => {
<div className={cls(`${CLS_PREFIX}`, style.popoverContent)}>
<div className={cls(`${CLS_PREFIX}__title`, style.popoverTitle)}>
<div className={cls(`${CLS_PREFIX}__title-name`, style.popoverTitleName)}>
{cityName.replace('市', '').replace('省', '')}
{regionName.replace('市', '').replace('省', '')}
</div>
<CaretDownOutlined rotate={open ? 180 : 0} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ export const POPOVER_PLACEMENT_LEGEND = new Map<string | undefined, TooltipPlace

export const HotCityList = [
{ adcode: '100000', name: '全国', level: 'country' },
{ adcode: '110000', name: '北京市', level: 'province' },
{ adcode: '120000', name: '天津市', level: 'province' },
{ adcode: '210100', name: '沈阳市', level: 'city' },
{ adcode: '210200', name: '大连市', level: 'city' },
{ adcode: '310000', name: '上海市', level: 'province' },
{ adcode: '320100', name: '南京市', level: 'city' },
{ adcode: '320500', name: '苏州市', level: 'city' },
{ adcode: '330100', name: '杭州市', level: 'city' },
{ adcode: '370200', name: '青岛市', level: 'city' },
{ adcode: '410100', name: '郑州市', level: 'city' },
{ adcode: '420100', name: '武汉市', level: 'city' },
{ adcode: '430100', name: '长沙市', level: 'city' },
{ adcode: '440100', name: '广州市', level: 'city' },
{ adcode: '440300', name: '深圳市', level: 'city' },
{ adcode: '500000', name: '重庆市', level: 'province' },
{ adcode: '510100', name: '成都市', level: 'city' },
{ adcode: '610100', name: '西安市', level: 'city' },
{ adcode: '810000', name: '香港市', level: 'province' },
{ adcode: '820000', name: '澳门市', level: 'province' },
{ adcode: '110000', name: '北京', level: 'province' },
{ adcode: '120000', name: '天津', level: 'province' },
{ adcode: '210100', name: '沈阳', level: 'city' },
{ adcode: '210200', name: '大连', level: 'city' },
{ adcode: '310000', name: '上海', level: 'province' },
{ adcode: '320100', name: '南京', level: 'city' },
{ adcode: '320500', name: '苏州', level: 'city' },
{ adcode: '330100', name: '杭州', level: 'city' },
{ adcode: '370200', name: '青岛', level: 'city' },
{ adcode: '410100', name: '郑州', level: 'city' },
{ adcode: '420100', name: '武汉', level: 'city' },
{ adcode: '430100', name: '长沙', level: 'city' },
{ adcode: '440100', name: '广州', level: 'city' },
{ adcode: '440300', name: '深圳', level: 'city' },
{ adcode: '500000', name: '重庆', level: 'province' },
{ adcode: '510100', name: '成都', level: 'city' },
{ adcode: '610100', name: '西安', level: 'city' },
{ adcode: '810000', name: '香港', level: 'province' },
{ adcode: '820000', name: '澳门', level: 'province' },
];

0 comments on commit cbc5b96

Please sign in to comment.