ソースを参照

fix map around

张延森 5 年 前
コミット
5fd85a3b3f
共有4 個のファイルを変更した58 個の追加16 個の削除を含む
  1. 4
    4
      config/dev.js
  2. 2
    2
      src/pages/project/detail/Around/Pannel.js
  3. 12
    10
      src/pages/project/detail/Around/index.js
  4. 40
    0
      src/utils/amap.js

+ 4
- 4
config/dev.js ファイルの表示

@@ -7,10 +7,10 @@ module.exports = {
7 7
     // WSS_HOST: '"wss://47.101.36.130:8085"',
8 8
     // HOST:  '"https://dev.jinchengjiaye.com"',//测试
9 9
     // WSS_HOST: '"wss://dev.jinchengjiaye.com"',
10
-    // HOST: '"https://lt.pawoma.cn"',
11
-    // WSS_HOST: '"wss://lt.pawoma.cn"',
12
-    HOST: '"http://192.168.0.238:8080"',
13
-    WSS_HOST: '"ws://192.168.0.238:8080"',
10
+    HOST: '"https://lt.pawoma.cn"',
11
+    WSS_HOST: '"wss://lt.pawoma.cn"',
12
+    // HOST: '"http://192.168.0.238:8080"',
13
+    // WSS_HOST: '"ws://192.168.0.238:8080"',
14 14
   },
15 15
   weapp: {},
16 16
   h5: {}

+ 2
- 2
src/pages/project/detail/Around/Pannel.js ファイルの表示

@@ -36,7 +36,7 @@ export default class Pannel extends Component {
36 36
 
37 37
   initData = (props) => {
38 38
     const { data = [] } = props.dataset || {}
39
-    const markerList = JSON.parse(data)
39
+    const markerList = data
40 40
     let activeIndex = -1
41 41
     let currentMarkerPos = undefined
42 42
 
@@ -100,7 +100,7 @@ export default class Pannel extends Component {
100 100
             })
101 101
           }
102 102
           {
103
-            manualData.length && (
103
+            manualData.length && this.state.markerList.length && (
104 104
               <View className="around-cell-title">其他</View>
105 105
             )
106 106
           }

+ 12
- 10
src/pages/project/detail/Around/index.js ファイルの表示

@@ -3,30 +3,32 @@ import { View } from '@tarojs/components'
3 3
 import PoiAround from '@components/amap/PoiAround'
4 4
 import Tab from './Tab'
5 5
 import Pannel from './Pannel'
6
+import { POI_TYPES } from '@utils/amap'
6 7
 import './style.scss'
7 8
 
8 9
 export default function Around(props) {
9 10
   const detail = props.building || {}
10 11
   
11 12
   const [lat, lng] = (detail.coordinate || '').split(',')
12
-  const poiDatas = detail.mapJson ? JSON.parse(detail.mapJson) : []
13
-  const ty = Object.prototype.toString
13
+  const poiDatas = typeof detail.mapJson === 'string' ? JSON.parse(detail.mapJson) : []
14 14
 
15 15
   // 展示内容数组
16
-  const dataList = poiDatas.map((item) => {
17
-    const key = item.key
18
-    const manualData = (detail[`building${key}`] === '' ? [] : (detail[`building${key}`] || '').split(','))
19
-    
16
+  const dataList = POI_TYPES.map((poi) => {
17
+    const jsonData = poiDatas.filter(x => x.key === poi.key)[0] || {}
18
+    const data = JSON.parse(jsonData.data || '[]')
19
+    const manualData = (detail[`building${poi.key}`] === '' ? [] : (detail[`building${poi.key}`] || '').split(','))
20
+
20 21
     return {
21
-      ...item,
22
+      ...poi,
23
+      data,
22 24
       manualData,
23
-      num: (ty.call(item.data) === '[object String]' ? JSON.parse(item.data) : []).length + manualData.length,
25
+      num: data.length + manualData.length,
24 26
     }
25 27
   }).filter(x => x.num)
26
-
28
+  
27 29
   // 所有的 markers
28 30
   const markersList = dataList.map((item) => {
29
-    const mapJson = JSON.parse(item.data) 
31
+    const mapJson = item.data || '[]'
30 32
     return (mapJson || []).map((it) => {
31 33
       const [longitude, latitude] = (it.location || '').split(',')
32 34
 

+ 40
- 0
src/utils/amap.js ファイルの表示

@@ -0,0 +1,40 @@
1
+const POI_TYPES = [
2
+  {
3
+    key: 'Transport',
4
+    label: '交通',
5
+    types: ['150100', '150200', '150300', '150400', '150500', '150600'],
6
+  },
7
+  {
8
+    key: 'Mall',
9
+    label: '商业',
10
+    types: ['060100', '060200', '060300', '060400', '060500', '060600',
11
+            '060700', '060800', '060900', '061000', '061100', '061200',
12
+            '061300', '061400', '080100', '080200', '080300', '080400',
13
+            '080500', '080600'],
14
+  },
15
+  {
16
+    key: 'Edu',
17
+    label: '学校',
18
+    types: ['141200'],
19
+  },
20
+  {
21
+    key: 'Hospital',
22
+    label: '医院',
23
+    types: ['090100', '090200', '090300', '090400', '090500', '090600', '090700'],
24
+  },
25
+  {
26
+    key: 'Bank',
27
+    label: '银行',
28
+    types: ['160100'],
29
+  },
30
+  {
31
+    key: 'Restaurant',
32
+    label: '餐饮',
33
+    types: ['050100', '050200', '050300', '050400', '050500', '050600',
34
+            '050700', '050800', '050900'],
35
+  },
36
+]
37
+
38
+export {
39
+  POI_TYPES,
40
+}