微信小程序?qū)崿F(xiàn)軌跡回放的示例代碼
更新時(shí)間:2019年12月13日 10:24:04 作者:鋒子の日記
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)軌跡回放的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
在微信小程序?qū)崿F(xiàn)軌跡回放的效果
1、wxml
<map id="map" longitude="{{longitude}}" latitude="{{latitude}}" scale="16"
bindcontroltap="controltap" bindmarkertap="markertap" markers="{{markers}}" polyline="{{polyline}}"
bindregionchange="regionchange" show-location style="width: 100%; height:{{height}}px;" ></map>
<view class="padding flex flex-wrap justify-between align-center bg-white">
<button class='cu-btn bg-green shadow sm' bindtap='beginTrack'> 開(kāi)始 </button>
<button class='cu-btn bg-orange shadow sm' bindtap='pauseTrack'> 暫停 </button>
<button class='cu-btn bg-red shadow sm' bindtap='endTrack'> 結(jié)束 </button>
</view>
2、js
//index.js
//獲取應(yīng)用實(shí)例
const app = getApp()
Page({
data: {
StatusBar: app.globalData.StatusBar,
CustomBar: app.globalData.CustomBar,
height: wx.getSystemInfoSync().windowHeight,
latitude: 0,
longitude: 0,
playIndex: 0,
timer: null,
markers: [],
polyline: [],
pointsInfo:[]
},
regionchange(e) {
//console.log(e.type)
},
markertap(e) {
//console.log(e.markerId)
},
controltap(e) {
//console.log(e.controlId)
},
beginTrack:function(e){
},
onLoad: function (options){
var that = this;
wx.request({
url: 'http://**/getTrack',
data: {
beginTime:"開(kāi)始時(shí)間",
endTime:"結(jié)束時(shí)間"
},
method: "post",
success: function (res) {
that.setData({
pointsInfo:res.data.pointsInfos,
polyline: [{
points: res.data.points,
color: "#FF0000DD",
width: 4,
dottedLine: true
}],
markers: [{
iconPath: '../../img/location.jpg',
id: 0,
latitude: res.data.points[0].latitude,
longitude: res.data.points[0].longitude,
width: 30,
height: 30,
title: that.data.brandNumber,
callout: {
content: that.data.brandNumber + ' \n 時(shí)間:' + res.data.pointsInfos[0].create_time + ' \n 速度:' + res.data.pointsInfos[0].speed + ' km/h',
color: "#000000",
fontSize: 13,
borderRadius: 2,
bgColor: "#fff",
display: "ALWAYS",
boxShadow: "5px 5px 10px #aaa"
}
}],
latitude: res.data.points[0].latitude,
longitude: res.data.points[0].longitude,
})
}
})
},
/**
* 開(kāi)始
*/
beginTrack:function(){
var that = this;
var i = that.data.playIndex == 0 ? 0 : that.data.playIndex;
that.timer = setInterval(function () {
i ++
that.setData({
playIndex: i,
latitude: that.data.polyline[0].points[i].latitude,
longitude: that.data.polyline[0].points[i].longitude,
markers: [{
iconPath: '../../img/car/e0.png',
id: 0,
latitude: that.data.polyline[0].points[i].latitude,
longitude: that.data.polyline[0].points[i].longitude,
width: 30,
height: 30,
title: that.data.brandNumber,
callout: {
content: that.data.brandNumber + ' \n 時(shí)間:' + that.data.pointsInfo[i].create_time + ' \n 速度:' + that.data.pointsInfo[i].speed + ' km/h',
color: "#000000",
fontSize: 13,
borderRadius: 2,
bgColor: "#fff",
display: "ALWAYS",
boxShadow: "5px 5px 10px #aaa"
}
}]
})
if ((i+1) >= that.data.polyline[0].points.length) {
that.endTrack();
}
}, 500)
},
/**
* 暫停
*/
pauseTrack:function(){
var that = this;
clearInterval(this.timer)
},
/**
* 結(jié)束
*/
endTrack:function(){
var that = this;
that.setData({
playIndex: 0,
latitude: that.data.polyline[0].points[0].latitude,
longitude: that.data.polyline[0].points[0].longitude,
markers: [{
iconPath: '../../img/car/e0.png',
id: 0,
latitude: that.data.polyline[0].points[0].latitude,
longitude: that.data.polyline[0].points[0].longitude,
width: 30,
height: 30,
title: that.data.brandNumber,
callout: {
content: that.data.brandNumber + ' \n 時(shí)間:' + that.data.pointsInfo[0].create_time + ' \n 速度:' + that.data.pointsInfo[0].speed + ' km/h',
color: "#000000",
fontSize: 13,
borderRadius: 2,
bgColor: "#fff",
display: "ALWAYS",
boxShadow: "5px 5px 10px #aaa"
}
}]
})
clearInterval(this.timer)
}
})
后臺(tái)數(shù)據(jù)使用的是百度鷹眼的數(shù)據(jù)。最終效果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
javascript 封裝的一個(gè)實(shí)用的焦點(diǎn)圖切換效果
之前有一篇博客,實(shí)用的焦點(diǎn)圖切換效果,結(jié)構(gòu)行為相分離 解釋的比較詳細(xì),腳本是分離式的,但在易用性和重用性方面并不理想,這里原作者進(jìn)行了,優(yōu)化。2010-07-07
JS判斷不同分辨率調(diào)用不同的CSS樣式文件實(shí)現(xiàn)思路及測(cè)試代碼
最近看一個(gè)網(wǎng)站,發(fā)現(xiàn)顯示器不同的分辨率,樣式文件調(diào)用的也不一樣,于是很好奇研究并寫(xiě)了一個(gè),經(jīng)測(cè)試感覺(jué)還不錯(cuò),感興趣的你可以來(lái)看看哦2013-01-01
javascript 網(wǎng)頁(yè)跳轉(zhuǎn)的方法
昨天練習(xí)的時(shí)候正好要用到跳轉(zhuǎn)代碼,在網(wǎng)上找了一下,覺(jué)得下面幾個(gè)不錯(cuò)...整理了一下發(fā)上來(lái)...2008-12-12
JavaScript中關(guān)于e.keycode的使用
這篇文章主要介紹了JavaScript中關(guān)于e.keycode的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12
利用JS實(shí)現(xiàn)二叉樹(shù)遍歷算法實(shí)例代碼
眾所周知javascript語(yǔ)言中只提供了幾種基本類(lèi)型的數(shù)據(jù)類(lèi)型,而二叉樹(shù)是一種數(shù)據(jù)結(jié)構(gòu),在一些查詢(xún)等操作中能提供較好的性能,這篇文章主要給大家介紹了關(guān)于利用JS實(shí)現(xiàn)二叉樹(shù)遍歷算法的相關(guān)資料,需要的朋友可以參考下2021-11-11

