|
@@ -1,39 +1,47 @@
|
|
|
import { AMap, PathSimplifier } from '@/components';
|
|
import { AMap, PathSimplifier } from '@/components';
|
|
|
import { usePlaceSearch } from '@/components/AMapComponent/hooks';
|
|
import { usePlaceSearch } from '@/components/AMapComponent/hooks';
|
|
|
import { Marker } from 'react-amap';
|
|
import { Marker } from 'react-amap';
|
|
|
-import { useState } from 'react';
|
|
|
|
|
-import { Select } from 'antd';
|
|
|
|
|
|
|
+import { useEffect, useState } from 'react';
|
|
|
|
|
+import { Button, Select } from 'antd';
|
|
|
import { debounce } from 'lodash';
|
|
import { debounce } from 'lodash';
|
|
|
|
|
+import useDistance from '@/components/AMapComponent/hooks/Distance';
|
|
|
|
|
|
|
|
export default () => {
|
|
export default () => {
|
|
|
- const [speed] = useState(100000);
|
|
|
|
|
|
|
+ const { distance, onDistance } = useDistance();
|
|
|
|
|
+ const [speed, setSpeed] = useState(100000);
|
|
|
const [markerCenter, setMarkerCenter] = useState<any>({ longitude: 0, latitude: 0 });
|
|
const [markerCenter, setMarkerCenter] = useState<any>({ longitude: 0, latitude: 0 });
|
|
|
const [map, setMap] = useState(null);
|
|
const [map, setMap] = useState(null);
|
|
|
|
|
+ const [show, setShow] = useState(false);
|
|
|
|
|
|
|
|
const { data, search } = usePlaceSearch(map);
|
|
const { data, search } = usePlaceSearch(map);
|
|
|
|
|
|
|
|
|
|
+ const paths = [
|
|
|
|
|
+ [116.405289, 39.904987],
|
|
|
|
|
+ [113.964458, 40.54664],
|
|
|
|
|
+ [111.47836, 41.135964],
|
|
|
|
|
+ [108.949297, 41.670904],
|
|
|
|
|
+ [106.380111, 42.149509],
|
|
|
|
|
+ [103.774185, 42.56996],
|
|
|
|
|
+ [101.135432, 42.930601],
|
|
|
|
|
+ [98.46826, 43.229964],
|
|
|
|
|
+ [95.777529, 43.466798],
|
|
|
|
|
+ [93.068486, 43.64009],
|
|
|
|
|
+ [90.34669, 43.749086],
|
|
|
|
|
+ [87.61792, 43.793308],
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
const onSearch = (value: string) => {
|
|
const onSearch = (value: string) => {
|
|
|
search(value);
|
|
search(value);
|
|
|
};
|
|
};
|
|
|
- console.log(data);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ setSpeed((distance / 5) * 3.6);
|
|
|
|
|
+ }, [distance]);
|
|
|
|
|
|
|
|
const [pathData] = useState([
|
|
const [pathData] = useState([
|
|
|
{
|
|
{
|
|
|
name: '线路1',
|
|
name: '线路1',
|
|
|
- path: [
|
|
|
|
|
- [116.405289, 39.904987],
|
|
|
|
|
- [113.964458, 40.54664],
|
|
|
|
|
- [111.47836, 41.135964],
|
|
|
|
|
- [108.949297, 41.670904],
|
|
|
|
|
- [106.380111, 42.149509],
|
|
|
|
|
- [103.774185, 42.56996],
|
|
|
|
|
- [101.135432, 42.930601],
|
|
|
|
|
- [98.46826, 43.229964],
|
|
|
|
|
- [95.777529, 43.466798],
|
|
|
|
|
- [93.068486, 43.64009],
|
|
|
|
|
- [90.34669, 43.749086],
|
|
|
|
|
- [87.61792, 43.793308],
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ path: paths,
|
|
|
},
|
|
},
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
@@ -45,7 +53,9 @@ export default () => {
|
|
|
height: 500,
|
|
height: 500,
|
|
|
width: '100%',
|
|
width: '100%',
|
|
|
}}
|
|
}}
|
|
|
- onInstanceCreated={setMap}
|
|
|
|
|
|
|
+ onInstanceCreated={(_map) => {
|
|
|
|
|
+ setMap(_map);
|
|
|
|
|
+ }}
|
|
|
events={{
|
|
events={{
|
|
|
click: (e: any) => {
|
|
click: (e: any) => {
|
|
|
setMarkerCenter({
|
|
setMarkerCenter({
|
|
@@ -59,19 +69,24 @@ export default () => {
|
|
|
// @ts-ignore
|
|
// @ts-ignore
|
|
|
<Marker position={markerCenter} />
|
|
<Marker position={markerCenter} />
|
|
|
) : null}
|
|
) : null}
|
|
|
- <PathSimplifier pathData={pathData}>
|
|
|
|
|
- <PathSimplifier.PathNavigator
|
|
|
|
|
- speed={speed}
|
|
|
|
|
- onCreate={(nav) => {
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- nav.pause();
|
|
|
|
|
- }, 5000);
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- nav.resume(); // 恢复
|
|
|
|
|
- }, 7000);
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- </PathSimplifier>
|
|
|
|
|
|
|
+ {show && (
|
|
|
|
|
+ <PathSimplifier pathData={pathData}>
|
|
|
|
|
+ <PathSimplifier.PathNavigator
|
|
|
|
|
+ isAuto={false}
|
|
|
|
|
+ speed={speed}
|
|
|
|
|
+ onCreate={(nav) => {
|
|
|
|
|
+ onDistance(paths);
|
|
|
|
|
+
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ nav.start();
|
|
|
|
|
+ }, 300);
|
|
|
|
|
+ // setTimeout(() => {
|
|
|
|
|
+ // nav.resume(); // 恢复
|
|
|
|
|
+ // }, 7000);
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </PathSimplifier>
|
|
|
|
|
+ )}
|
|
|
</AMap>
|
|
</AMap>
|
|
|
<div style={{ position: 'absolute', top: 0 }}>
|
|
<div style={{ position: 'absolute', top: 0 }}>
|
|
|
<Select
|
|
<Select
|
|
@@ -84,6 +99,20 @@ export default () => {
|
|
|
console.log(key, node);
|
|
console.log(key, node);
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ setShow(false);
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ 清除
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ setShow(true);
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ 显示
|
|
|
|
|
+ </Button>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|