Browse Source

地图增加路线接口

Caner 2 years ago
parent
commit
cf3e8ce0e5
2 changed files with 13 additions and 54 deletions
  1. 13 46
      src/components/map.vue
  2. 0 8
      src/pages/views/home/services/index.ts

+ 13 - 46
src/components/map.vue

@@ -11,9 +11,10 @@ import { onMounted, watch } from 'vue'
 import useStore from '@/pages/store/index'
 import { useNotification } from 'naive-ui'
 import img36 from '@/assets/img/36.png'
-import path from 'path'
+import NetService from '@/services/net.service'
 
 const store = useStore()
+const netService = new NetService()
 const notification = useNotification()
 const props = withDefaults(defineProps<{
   zoom?: number
@@ -25,7 +26,7 @@ let AMaps = null as Any
 window._AMapSecurityConfig = {
   securityJsCode: '184c86be3bbd9a8a941bcaaf6b09c7cd'
 }
-const lines = {} as Any
+const marks = {} as Any
 
 function getAllRings(feature: { geometry: { coordinates: Any[]; }; }) {
   const coords = feature.geometry.coordinates
@@ -74,6 +75,12 @@ function addLine(path:number[][], color?:string, width?:number) {
   return polyline
 }
 
+// 获取路线
+async function getLines() {
+  const { data } = await netService.get('/busLine/getList')
+  console.log(666, data)
+}
+getLines()
 onMounted(() => {
   AMapLoader.load({
     key: '0c5c83112cafefa77154769b4433c3df',
@@ -156,45 +163,6 @@ onMounted(() => {
       extData: '1'// 设置自定义属性
     })
     map.add(mark)
-
-    const polyline = new AMap.Polyline({
-      path: [],
-      strokeWeight: 5,
-      borderWeight: 5, // 线条宽度,默认为 1
-      strokeColor: 'red', // 线条颜色
-      lineJoin: 'bevel', // 折线拐点连接处样式
-      geodesic: true
-    })
-    map.add(polyline)
-    console.log(6666, polyline)
-
-    // 增加路线
-    // const driving = new AMap.Driving({
-    //   map
-    // })
-
-    // 根据起终点名称规划驾车导航路线
-    // driving.search([
-    //   { keyword: '鑫源大厦', city: '雅安市' },
-    //   { keyword: '雅安农业大学', city: '雅安市' }
-    // ], (status:string, result:Any) => {
-    //   if (status === 'complete') {
-    //     // const { routes } = result
-    //     // const paths = routes[0].steps.map((el: { path: Any }) => (el.path))
-    //     console.log('导航数据获取成功', result)
-    //     // const polyline = new AMap.Polyline({
-    //     //   path: paths,
-    //     //   strokeWeight: 5,
-    //     //   borderWeight: 5, // 线条宽度,默认为 1
-    //     //   strokeColor: 'red', // 线条颜色
-    //     //   lineJoin: 'bevel', // 折线拐点连接处样式
-    //     //   geodesic: true
-    //     // })
-    //     // map.add(polyline)
-    //   } else {
-    //     console.error(`获取驾车数据失败:${result}`)
-    //   }
-    // })
     Maps = map
     AMaps = AMap
   })
@@ -202,18 +170,17 @@ onMounted(() => {
 
 watch(() => store.socektData, (v) => {
   if (v && v.BUS_LINE_INFO) {
-    console.log('line', v)
     for (let k = 0; k < v.BUS_LINE_INFO.length; k++) {
       const el = v.BUS_LINE_INFO[k]
       const paths = el.inboundAndOutboundStations.map((es: { lat: number; lng: number }) => [ es.lng, es.lat ])
-      if (lines[el.lineId]) {
+      if (marks[el.lineId]) {
         // 更新
-        console.log('更新', lines[el.lineId].lineMap)
-        lines[el.lineId].lineMap.setPath(paths)
+        console.log('更新', v)
+        marks[el.lineId].lineMap.setPath(paths)
       } else {
         // 添加
         console.log('添加', paths)
-        lines[el.lineId] = { ...el, lineMap: addLine(paths) }
+        marks[el.lineId] = { ...el, lineMap: addLine(paths) }
       }
     }
   }

+ 0 - 8
src/pages/views/home/services/index.ts

@@ -1,8 +0,0 @@
-import { injectable, Service } from '@/services/service'
-
-
-@injectable
-export default class HomeService extends Service {
-
-
-}