Skip to content

79.TranslateMarker #79

Open
Open
@webVueBlog

Description

@webVueBlog
No description provided.

Activity

added
小程序微信小程序、百度小程序、支付宝小程序、头条小程序等
on Mar 19, 2020
webVueBlog

webVueBlog commented on Mar 19, 2020

@webVueBlog
MemberAuthor
//index.js
//获取应用实例
const app = getApp()

var isStrtaPoint = true;
var point1 = {
  longitude: 113.26988,
  latitude: 23.135402
};
var point2 = {
  longitude: 113.27188,
  latitude: 23.135402
};
let markerId = 2222;
var isPlay = false;// 是否在播放
Page({
  data: {
    longitude: 113.27088,
    latitude: 23.135402,
    markers: [],
    polyline: [
      {
        points: [
          point1,
          point2
        ],
        color: '#0976f2',
        width: 5
      }
    ],
  },
  
  onLoad: function () {
    this.mapCtx = wx.createMapContext('myMap');
    let marker = {};
    marker.id = markerId;
    marker.latitude = point1.latitude;
    marker.longitude = point1.longitude;
    marker.iconPath = '../../images/location.png'
    this.setData({
      markers: [marker]
    })
	  console.log('YK写的');
	  console.log('YK写的2');

	  console.log('我再试一试YK');


    console.log('KEN写的');
    console.log('KEN写的2');

  },
  // 播放 或者 暂停 marker移动
  click1:function(){
    isPlay = !isPlay;
    if (isPlay){
      this.playMarker();
    }
  },
  /** 打开这里的代码,就一切正常了
  onHide:function(){
    isPlay = false;
  },
   */
  // 界面跳转
  click2: function () {
    wx.navigateTo({
      url: '../next/next',
    })
  },
  // 播放
  playMarker:function(){
    let point = isStrtaPoint ? point2 : point1;
    this.mapCtx.translateMarker({
      markerId: markerId,
      destination: {
        latitude: point.latitude,
        longitude: point.longitude,
      },
      autoRotate: false,
      rotate: 0,
      duration: 1000,
      animationEnd: function () {
        console.log('marker end')
      },
      fail: function (res) {
        console.log(res)
      }
    })
    isStrtaPoint = !isStrtaPoint;
    var that = this;
    setTimeout(function () {
      if (isPlay) {
        that.playMarker()
      }
    }, 1000)
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    小程序微信小程序、百度小程序、支付宝小程序、头条小程序等

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @webVueBlog

        Issue actions

          79.TranslateMarker · Issue #79 · weekCodeing/interview-answe