AppGallery Connect:map組件如何實(shí)現(xiàn)指定marker的移動(dòng)動(dòng)畫(huà)

來(lái)源: 華為開(kāi)發(fā)者論壇
作者:Mayism
時(shí)間:2021-01-08
17269
map地圖組件可以實(shí)現(xiàn)指定 marker 的移動(dòng)動(dòng)畫(huà)。以下示例展示了 marker 在地圖組件中的移動(dòng)。marker 的圖標(biāo)是一輛小車(chē),在起點(diǎn)位置沒(méi)有任何的旋轉(zhuǎn),點(diǎn)擊地圖,觸發(fā)小車(chē)向目標(biāo)地點(diǎn)移動(dòng),并且在移動(dòng)過(guò)程中,小車(chē)的圖標(biāo)自動(dòng)進(jìn)行旋轉(zhuǎn),始終保持車(chē)頭朝向目標(biāo)地點(diǎn)。

需求場(chǎng)景:

map地圖組件可以實(shí)現(xiàn)指定 marker 的移動(dòng)動(dòng)畫(huà)。

以下示例展示了 marker 在地圖組件中的移動(dòng)。marker 的圖標(biāo)是一輛小車(chē),在起點(diǎn)位置沒(méi)有任何的旋轉(zhuǎn),點(diǎn)擊地圖,觸發(fā)小車(chē)向目標(biāo)地點(diǎn)移動(dòng),并且在移動(dòng)過(guò)程中,小車(chē)的圖標(biāo)自動(dòng)進(jìn)行旋轉(zhuǎn),始終保持車(chē)頭朝向目標(biāo)地點(diǎn)。

示例截圖:

0900086000150224722.20201230173705.96763035308330239158723749802036.png

示例代碼:

<template>

  <div>

    <map

      style="width:{{width}}; height:{{height}}"

      id="map"

      scale="{{scale}}"

      markers="{{markers}}"

      polylines="{{polylines}}"

      @tap="tap"

    >

    </map>

  </div>

</template>

<script>

  const POINT1 = { latitude: 39.9090371069, longitude: 116.3953853161 }

  const POINT2 = { latitude: 39.9089550115, longitude: 116.3992842749 }

  export default {

    private: {

      width: '100%',

      height: '50%',

      scale: 17,

      markers: [

        {

          id: 1,

          latitude: POINT1.latitude,

          longitude: POINT1.longitude,

          anchor: { x: 0.5, y: 0.5 },

          iconPath: '../Common/carA.png',

          width: '100px'

        }

      ],

      polylines: [{ points: [POINT1, POINT2] }]

    },

    tap() {

      this.$element('map').translateMarker({

        markerId: 1,

        destination: POINT2,

        autoRotate: true,

        duration: 5000

      })

    }

  }

</script>

更多map組件參考:

https://developer.huawei.com/consumer/cn/doc/development/quickApp-References/quickapp-component-map#translateMarker_para

立即登錄,閱讀全文
版權(quán)說(shuō)明:
本文內(nèi)容來(lái)自于華為開(kāi)發(fā)者論壇,本站不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。文章內(nèi)容系作者個(gè)人觀點(diǎn),不代表快出海對(duì)觀點(diǎn)贊同或支持。如有侵權(quán),請(qǐng)聯(lián)系管理員(zzx@kchuhai.com)刪除!
優(yōu)質(zhì)服務(wù)商推薦
更多
掃碼登錄
打開(kāi)掃一掃, 關(guān)注公眾號(hào)后即可登錄/注冊(cè)
加載中
二維碼已失效 請(qǐng)重試
刷新
賬號(hào)登錄/注冊(cè)
個(gè)人VIP
小程序
快出海小程序
公眾號(hào)
快出海公眾號(hào)
商務(wù)合作
商務(wù)合作
投稿采訪
投稿采訪
出海管家
出海管家