vue 3.0高德地图【marker点击显示驾车路线规划】

  <div id="my-panel"></div>
  <div id="container"></div>
const point = [
    { lnglat: ['121.473701', '31.230416'], city: '上海', number: 10 },
    { lnglat: ['113.264434', '23.129162'], city: '广州', number: 10 },
    { lnglat: ['104.065735', '30.659462'], city: '成都', number: 10 }
  ]
  const map = new AMap.Map('container', {
    zoom: 5,
    animateEnable: true
  })
  let markers = []
  // marker 制作
  function makeMarker({ lnglat, city, number }) {
    const marker = new AMap.Marker({
      position: lnglat
    })
    const content = `
    <div class="amap-info-container">
        <div class="amap-info-window">${city}${number}</div>
        <div class="amap-info-sharp"></div>
    </div>`
    const labelConfig = {
      offset: [0, 0],
      content,
      direction: 'top'
    }
    marker.setLabel(labelConfig)
    marker.on('click', (e) => {
      makeDriving()
    })
    return marker
  }
  point.forEach((item) => {
    const itemMarker = makeMarker(item)
    markers.push(itemMarker)
  })
  map.add(markers)
  // 路径规划
  function makeDriving() {
    const position = [116.379028, 39.885042]
    const marker = new AMap.Marker({
      map: map,
      position,
      icon: 'https://webapi.amap.com/images/car.png',
      offset: new AMap.Pixel(-26, -13),
      autoRotation: true,
      angle: -90
    })
    map.plugin('AMap.Driving', function () {
      var driving = new AMap.Driving({
        policy: 0,
        map: map,
        panel: 'my-panel'
      })
      driving.search(
        [116.379028, 39.865042],
        [116.427281, 39.903719],
        {
          waypoints: [position]
        },
        function (status, result) {}
      )
      // 搜索完成后,将自动绘制路线到地图上
    })
    map.add(marker)
    map.setFitView()
  }
#my-panel {
  width: 380px;
  position: absolute;
  top: 10px;
  right: 10px;
  background-color: #fff;
  z-index: 99;
}

.amap-marker-label {
  border: none;
}
.amap-info-container {
  position: relative;
  .amap-info-window {
    background: #fff;
    border-radius: 3px;
    padding: 3px 7px;
    box-shadow: 0 2px 6px 0 rgba(114, 124, 245, 0.5);
    position: relative;
  }
  .amap-info-sharp {
    position: absolute;
    top: 16px;
    bottom: 0;
    left: 50%;
    margin-left: -8px;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #fff;
  }
}
  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
您好!对于Vue项目中使用高德地图marker点击跳转页面的需求,您可以按照以下步骤进行操作: 1. 首先,确保您已经成功引入了高德地图相关的 JavaScript API,并在Vue项目中初始化地图组件。 2. 在Vue组件中,您可以通过创建一个`InfoWindow`组件来实现marker点击事件。 ```vue <template> <div> <el-button @click="showInfoWindow">显示Marker</el-button> <el-dialog v-if="showDialog" :visible.sync="showDialog"> <!-- 在此处添加您自定义的内容,可以是跳转链接或其他操作 --> <a href="your-link">跳转页面</a> </el-dialog> </div> </template> <script> export default { data() { return { showDialog: false }; }, methods: { showInfoWindow() { this.showDialog = true; } } }; </script> ``` 3. 在地图初始化后,创建并添加Marker时,您可以通过监听marker的`click`事件来触发`showInfoWindow`方法,显示弹窗。 ```vue // 在合适的钩子函数中初始化地图,并添加Marker mounted() { // 初始化地图 // ... // 创建并添加Marker const marker = new AMap.Marker({ position: [longitude, latitude], map: mapInstance // mapInstance为地图实例 }); // 监听marker的click事件 marker.on('click', () => { this.showInfoWindow(); }); }, ``` 在上述示例中,点击"显示Marker"按钮将会弹出对话框,您可以在对话框中添加自定义的内容,如跳转链接或其他操作。请注意,在`<a href="your-link">跳转页面</a>`处,将"your-link"替换为您想要跳转的链接。 希望能对您有所帮助!如果有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

web_Hsir

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值