|
|
@@ -7,7 +7,7 @@
|
|
|
|
|
|
<script setup lang='ts'>
|
|
|
import AMapLoader from '@amap/amap-jsapi-loader'
|
|
|
-import { onMounted, ref } from 'vue'
|
|
|
+import { onMounted, watch } from 'vue'
|
|
|
import useStore from '@/pages/store/index'
|
|
|
import { useNotification } from 'naive-ui'
|
|
|
import img36 from '@/assets/img/36.png'
|
|
|
@@ -58,6 +58,19 @@ function addMark(position:number[], icon:string, size?:{w:number, h:number}) {
|
|
|
Maps.add(mark)
|
|
|
}
|
|
|
|
|
|
+function addLine(path:number[][], color?:string, width?:number) {
|
|
|
+ if (!Maps) return
|
|
|
+ const polyline = new AMaps.Polyline({
|
|
|
+ path,
|
|
|
+ strokeWeight: width || 5,
|
|
|
+ borderWeight: width || 5, // 线条宽度,默认为 1
|
|
|
+ strokeColor: color || 'red', // 线条颜色
|
|
|
+ lineJoin: 'bevel', // 折线拐点连接处样式
|
|
|
+ geodesic: true
|
|
|
+ })
|
|
|
+ Maps.add(polyline)
|
|
|
+}
|
|
|
+
|
|
|
onMounted(() => {
|
|
|
AMapLoader.load({
|
|
|
key: '0c5c83112cafefa77154769b4433c3df',
|
|
|
@@ -95,22 +108,6 @@ onMounted(() => {
|
|
|
}
|
|
|
store.setWeather(data)
|
|
|
})
|
|
|
- // 添加mark
|
|
|
- const mark = new AMap.Marker({
|
|
|
- title: 'test',
|
|
|
- position: [ 103.006916, 29.983835 ],
|
|
|
- cursor: 'pointer',
|
|
|
- icon: new AMap.Icon({
|
|
|
- image: img36,
|
|
|
- imageSize: new AMap.Size(36, 36)
|
|
|
- }),
|
|
|
- autoRotation: true,
|
|
|
- offset: new AMap.Pixel(-5, -20),
|
|
|
- angle: 0,
|
|
|
- anchor: 'center',
|
|
|
- extData: '1'// 设置自定义属性
|
|
|
- })
|
|
|
- map.add(mark)
|
|
|
// 镂空雅安 511800 adcode
|
|
|
AMapUI.loadUI([ 'geo/DistrictExplorer' ], (DistrictExplorer: any) => {
|
|
|
const districtExplorer = new DistrictExplorer({ map })
|
|
|
@@ -139,37 +136,72 @@ onMounted(() => {
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
- // 增加路线
|
|
|
- const driving = new AMap.Driving({
|
|
|
- map
|
|
|
+
|
|
|
+ // 添加mark
|
|
|
+ const mark = new AMap.Marker({
|
|
|
+ title: 'test',
|
|
|
+ position: [ 103.006916, 29.983835 ],
|
|
|
+ cursor: 'pointer',
|
|
|
+ icon: new AMap.Icon({
|
|
|
+ image: img36,
|
|
|
+ imageSize: new AMap.Size(36, 36)
|
|
|
+ }),
|
|
|
+ autoRotation: true,
|
|
|
+ offset: new AMap.Pixel(-5, -20),
|
|
|
+ angle: 0,
|
|
|
+ anchor: 'center',
|
|
|
+ extData: '1'// 设置自定义属性
|
|
|
})
|
|
|
+ map.add(mark)
|
|
|
|
|
|
- // 根据起终点名称规划驾车导航路线
|
|
|
- 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}`)
|
|
|
- }
|
|
|
+ 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
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+watch(() => store.socektData, (v) => {
|
|
|
+ if (v && v.BUS_LINE_INFO) {
|
|
|
+ console.log('line', v)
|
|
|
+ }
|
|
|
+}, { deep: true })
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|