|
@@ -11,9 +11,10 @@ import { onMounted, watch } from 'vue'
|
|
|
import useStore from '@/pages/store/index'
|
|
import useStore from '@/pages/store/index'
|
|
|
import { useNotification } from 'naive-ui'
|
|
import { useNotification } from 'naive-ui'
|
|
|
import img36 from '@/assets/img/36.png'
|
|
import img36 from '@/assets/img/36.png'
|
|
|
-import path from 'path'
|
|
|
|
|
|
|
+import NetService from '@/services/net.service'
|
|
|
|
|
|
|
|
const store = useStore()
|
|
const store = useStore()
|
|
|
|
|
+const netService = new NetService()
|
|
|
const notification = useNotification()
|
|
const notification = useNotification()
|
|
|
const props = withDefaults(defineProps<{
|
|
const props = withDefaults(defineProps<{
|
|
|
zoom?: number
|
|
zoom?: number
|
|
@@ -25,7 +26,7 @@ let AMaps = null as Any
|
|
|
window._AMapSecurityConfig = {
|
|
window._AMapSecurityConfig = {
|
|
|
securityJsCode: '184c86be3bbd9a8a941bcaaf6b09c7cd'
|
|
securityJsCode: '184c86be3bbd9a8a941bcaaf6b09c7cd'
|
|
|
}
|
|
}
|
|
|
-const lines = {} as Any
|
|
|
|
|
|
|
+const marks = {} as Any
|
|
|
|
|
|
|
|
function getAllRings(feature: { geometry: { coordinates: Any[]; }; }) {
|
|
function getAllRings(feature: { geometry: { coordinates: Any[]; }; }) {
|
|
|
const coords = feature.geometry.coordinates
|
|
const coords = feature.geometry.coordinates
|
|
@@ -74,6 +75,12 @@ function addLine(path:number[][], color?:string, width?:number) {
|
|
|
return polyline
|
|
return polyline
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 获取路线
|
|
|
|
|
+async function getLines() {
|
|
|
|
|
+ const { data } = await netService.get('/busLine/getList')
|
|
|
|
|
+ console.log(666, data)
|
|
|
|
|
+}
|
|
|
|
|
+getLines()
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
AMapLoader.load({
|
|
AMapLoader.load({
|
|
|
key: '0c5c83112cafefa77154769b4433c3df',
|
|
key: '0c5c83112cafefa77154769b4433c3df',
|
|
@@ -156,45 +163,6 @@ onMounted(() => {
|
|
|
extData: '1'// 设置自定义属性
|
|
extData: '1'// 设置自定义属性
|
|
|
})
|
|
})
|
|
|
map.add(mark)
|
|
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
|
|
Maps = map
|
|
|
AMaps = AMap
|
|
AMaps = AMap
|
|
|
})
|
|
})
|
|
@@ -202,18 +170,17 @@ onMounted(() => {
|
|
|
|
|
|
|
|
watch(() => store.socektData, (v) => {
|
|
watch(() => store.socektData, (v) => {
|
|
|
if (v && v.BUS_LINE_INFO) {
|
|
if (v && v.BUS_LINE_INFO) {
|
|
|
- console.log('line', v)
|
|
|
|
|
for (let k = 0; k < v.BUS_LINE_INFO.length; k++) {
|
|
for (let k = 0; k < v.BUS_LINE_INFO.length; k++) {
|
|
|
const el = v.BUS_LINE_INFO[k]
|
|
const el = v.BUS_LINE_INFO[k]
|
|
|
const paths = el.inboundAndOutboundStations.map((es: { lat: number; lng: number }) => [ es.lng, es.lat ])
|
|
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 {
|
|
} else {
|
|
|
// 添加
|
|
// 添加
|
|
|
console.log('添加', paths)
|
|
console.log('添加', paths)
|
|
|
- lines[el.lineId] = { ...el, lineMap: addLine(paths) }
|
|
|
|
|
|
|
+ marks[el.lineId] = { ...el, lineMap: addLine(paths) }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|