欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

前端Vue3引入高德地圖并展示行駛軌跡動(dòng)畫的步驟

 更新時(shí)間:2024年09月04日 10:18:55   作者:大嘴史努比  
最近在Vue項(xiàng)目中引入高德地圖,實(shí)現(xiàn)地圖展示與交互的方法和技術(shù),這里跟大家分享下,這篇文章主要給大家介紹了關(guān)于前端Vue3引入高德地圖并展示行駛軌跡動(dòng)畫的相關(guān)資料,需要的朋友可以參考下

預(yù)覽效果:

一、獲取高德地圖API的key(相當(dāng)于獲取開發(fā)許可權(quán),沒(méi)有就用不了)

注冊(cè)高德賬號(hào),注冊(cè)成功后復(fù)制 Key 值到組件,就可以使用。

二、安裝依賴

cnpm install @amap/amap-jsapi-loade

三、頁(yè)面代碼

<template>
  <div class="h-md flex justify-center">
    <topBar></topBar>
    <div class="h-[600px] w-[1000px] mt-40" id="container"></div>
  </div>
  <div
    class="fixed right-[30px] bottom-[30px] p-4 rounded-3xl border shadow-md border-blue-400 shadow-blue-700"
  >
    <h4>軌跡回放控制</h4>
    <div class="flex mb-1">
      <a-button class="mr-1" @click="startAnimation">開始動(dòng)畫</a-button>
      <a-button @click="pauseAnimation">暫停動(dòng)畫</a-button>
    </div>
    <div class="flex">
      <a-button class="mr-1" @click="resumeAnimation">繼續(xù)動(dòng)畫</a-button>
      <a-button @click="stopAnimation">停止動(dòng)畫</a-button>
    </div>
  </div>
</template>

<script setup>
import { onMounted, onUnmounted, ref } from 'vue'
import topBar from '../shopCenter/topBar.vue'
import AMapLoader from '@amap/amap-jsapi-loader'

let map = null
const marker = ref()
const lineArr = ref([
  [116.478935, 39.997761],
  [116.478939, 39.997825],
  [116.478912, 39.998549],
  [116.478912, 39.998549],
  [116.478998, 39.998555],
  [116.478998, 39.998555],
  [116.479282, 39.99856],
  [116.479658, 39.998528],
  [116.480151, 39.998453],
  [116.480784, 39.998302],
  [116.480784, 39.998302],
  [116.481149, 39.998184],
  [116.481573, 39.997997],
  [116.481863, 39.997846],
  [116.482072, 39.997718],
  [116.482362, 39.997718],
  [116.483633, 39.998935],
  [116.48367, 39.998968],
  [116.484648, 39.999861]
])

//開始動(dòng)畫
const startAnimation = () => {
  marker.value.moveAlong(lineArr.value, {
    duration: 500,
    autoRotation: true
  })
}
//暫停動(dòng)畫
const pauseAnimation = () => {
  marker.value.pauseMove()
}
//繼續(xù)動(dòng)畫
const resumeAnimation = () => {
  marker.value.resumeMove()
}
//停止動(dòng)畫
const stopAnimation = () => {
  marker.value.stopMove()
}

onMounted(() => {
  AMapLoader.load({
    key: '111111111111111111111111', // 申請(qǐng)好的Web端開發(fā)者Key,首次調(diào)用 load 時(shí)必填
    version: '2.0', // 指定要加載的 JSAPI 的版本,缺省時(shí)默認(rèn)為 1.4.15
    plugins: [] // 需要使用的的插件列表,如比例尺'AMap.Scale'等
  })
    .then((AMap) => {
      // JSAPI2.0 使用覆蓋物動(dòng)畫必須先加載動(dòng)畫插件
      AMap.plugin('AMap.MoveAnimation', function () {
        map = new AMap.Map('container', {
          // 設(shè)置地圖容器id
          viewMode: '3D', // 是否為3D地圖模式
          zoom: 17, // 初始化地圖級(jí)別
          resizeEnable: true,
          //   center: [116.397428, 39.90923] // 初始化地圖中心點(diǎn)位置
          center: [116.478935, 39.997761] // 初始化地圖中心點(diǎn)位置
        })

        //小車配置
        marker.value = new AMap.Marker({
          map: map,
          position: [116.478935, 39.997761],
          icon: 'https://a.amap.com/jsapi_demos/static/demo-center-v2/car.png',
          offset: new AMap.Pixel(-13, -26)
        })

        // 繪制軌跡
        var polyline = new AMap.Polyline({
          map: map,
          path: lineArr.value,
          showDir: true,
          strokeColor: '#28F', //線顏色
          // strokeOpacity: 1,     //線透明度
          strokeWeight: 6 //線寬
          // strokeStyle: "solid"  //線樣式
        })

        //移動(dòng)后的軌跡
        var passedPolyline = new AMap.Polyline({
          map: map,
          strokeColor: '#AF5', //線顏色
          strokeWeight: 6 //線寬
        })

        marker.value.on('moving', function (e) {
          console.log('!!')
          passedPolyline.setPath(e.passedPath)
          map.setCenter(e.target.getPosition(), true)
        })

        map.setFitView()
      })
    })
    .catch((e) => {
      console.log(e)
    })
})

onUnmounted(() => {
  map?.destroy()
})
</script>

<style scoped></style>

官網(wǎng)示例:軌跡回放-點(diǎn)標(biāo)記-示例中心-JS API 2.0 示例 | 高德地圖API (amap.com)

總結(jié)

到此這篇關(guān)于前端Vue3引入高德地圖并展示行駛軌跡動(dòng)畫的文章就介紹到這了,更多相關(guān)Vue3引入高德地圖展示行駛軌跡內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue 實(shí)現(xiàn)監(jiān)聽窗口關(guān)閉事件,并在窗口關(guān)閉前發(fā)送請(qǐng)求

    Vue 實(shí)現(xiàn)監(jiān)聽窗口關(guān)閉事件,并在窗口關(guān)閉前發(fā)送請(qǐng)求

    這篇文章主要介紹了Vue 實(shí)現(xiàn)監(jiān)聽窗口關(guān)閉事件,并在窗口關(guān)閉前發(fā)送請(qǐng)求,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-09-09
  • vue.config.js中配置Vue的路徑別名的方法

    vue.config.js中配置Vue的路徑別名的方法

    這篇文章主要介紹了vue.config.js中配置Vue的路徑別名的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02
  • Vue3兄弟組件傳值之mitt的超詳細(xì)講解

    Vue3兄弟組件傳值之mitt的超詳細(xì)講解

    之前只是淺顯的使用插件進(jìn)行vue開發(fā)展示,最近深入的研究了下,下面這篇文章主要給大家介紹了關(guān)于Vue3兄弟組件傳值之mitt的超詳細(xì)講解,需要的朋友可以參考下
    2022-06-06
  • vue如何解決sass-loader的版本過(guò)高導(dǎo)致的編譯錯(cuò)誤

    vue如何解決sass-loader的版本過(guò)高導(dǎo)致的編譯錯(cuò)誤

    這篇文章主要介紹了vue如何解決sass-loader的版本過(guò)高導(dǎo)致的編譯錯(cuò)誤問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • vue cli3 實(shí)現(xiàn)分環(huán)境打包的步驟

    vue cli3 實(shí)現(xiàn)分環(huán)境打包的步驟

    這篇文章主要介紹了vue cli3 實(shí)現(xiàn)分環(huán)境打包的步驟,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03
  • vue獲取form表單的值示例

    vue獲取form表單的值示例

    今天小編就為大家分享一篇vue獲取form表單的值示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-10-10
  • Vue3中watchEffect高級(jí)偵聽器的具體使用

    Vue3中watchEffect高級(jí)偵聽器的具體使用

    Vue3中新增了一種特殊的監(jiān)聽器watchEffect,本文主要介紹了Vue3中watchEffect高級(jí)偵聽器的具體使用,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-01-01
  • 最新評(píng)論