|
@@ -5,28 +5,23 @@ import { getLocation } from '@/utils/authorize';
|
5
|
5
|
import iconPath from '@/assets/icons/marker.png';
|
6
|
6
|
import style from './style.module.less';
|
7
|
7
|
|
|
8
|
+// location 逻辑
|
|
9
|
+// 如果 props.location 有值, 那么放弃地图定位的点, 使用 props.location
|
|
10
|
+// 否则使用 地图定位的点
|
|
11
|
+// 如果地图定位失败 或者 props.location 为空, 那么不产生数据交互
|
|
12
|
+// 但是地图上默认使用 霍山县人民政府 的定位
|
8
|
13
|
export default (props) => {
|
9
|
14
|
const { location, onLocChange } = props;
|
10
|
15
|
|
11
|
16
|
const [currentPos, setCurPos] = React.useState();
|
12
|
|
- const [lngLat, setLngLat] = React.useState([,]);
|
|
17
|
+ const [
|
|
18
|
+ markers,
|
|
19
|
+ lngLat,
|
|
20
|
+ ] = React.useMemo(() => {
|
|
21
|
+ const loc = location || currentPos || '116.354259,31.415587';
|
|
22
|
+ const [longitude, latitude] = loc.split(',');
|
13
|
23
|
|
14
|
|
- const markers = React.useMemo(() => {
|
15
|
|
- if (!location && !currentPos) return [];
|
16
|
|
-
|
17
|
|
- let longitude, latitude;
|
18
|
|
- if (location) {
|
19
|
|
- const [lng, lat] = location.split(',');
|
20
|
|
- longitude = lng - 0;
|
21
|
|
- latitude = lat - 0;
|
22
|
|
- } else {
|
23
|
|
- longitude = currentPos.longitude;
|
24
|
|
- latitude = currentPos.latitude;
|
25
|
|
- }
|
26
|
|
-
|
27
|
|
- setLngLat([longitude, latitude]);
|
28
|
|
-
|
29
|
|
- return [{
|
|
24
|
+ const mks = [{
|
30
|
25
|
id: 1,
|
31
|
26
|
longitude,
|
32
|
27
|
latitude,
|
|
@@ -34,15 +29,16 @@ export default (props) => {
|
34
|
29
|
width: 17,
|
35
|
30
|
height: 20
|
36
|
31
|
}];
|
|
32
|
+
|
|
33
|
+ return [
|
|
34
|
+ mks,
|
|
35
|
+ [longitude, latitude]
|
|
36
|
+ ]
|
37
|
37
|
}, [location, currentPos]);
|
38
|
38
|
|
39
|
39
|
React.useEffect(() => {
|
40
|
40
|
getLocation().then((res) => {
|
41
|
|
- setCurPos(res);
|
42
|
|
-
|
43
|
|
- if (onLocChange) {
|
44
|
|
- onLocChange([res.longitude, res.latitude].join(','));
|
45
|
|
- }
|
|
41
|
+ setCurPos([res.longitude, res.latitude].join(','));
|
46
|
42
|
}).catch((err) => {
|
47
|
43
|
console.error(err);
|
48
|
44
|
Taro.showToast({
|
|
@@ -51,6 +47,15 @@ export default (props) => {
|
51
|
47
|
})
|
52
|
48
|
});
|
53
|
49
|
}, []);
|
|
50
|
+
|
|
51
|
+ React.useEffect(() => {
|
|
52
|
+ if (!location && !currentPos) return;
|
|
53
|
+
|
|
54
|
+ const loc = location || currentPos;
|
|
55
|
+ if (loc) {
|
|
56
|
+ onLocChange(loc);
|
|
57
|
+ }
|
|
58
|
+ }, [location, currentPos]);
|
54
|
59
|
|
55
|
60
|
return (
|
56
|
61
|
<View className={style['map-wrapper']}>
|