<template>
<div class="container">
<div id="map"></div>
</div>
</template>
<script>
import TMap from "@/utils/initMap";
export default {
name: 'pathMap',
data() {
return {
TXMap:null,
tMap:null,
markerLayer:null,
editor:null,
carPath:[],
polylineLayer:null
}
},
mounted() {
this.$nextTick(()=>{
this.init()
setTimeout(()=>{
this.lookCarPath()
},250)
})
},
methods: {
init(){
TMap.init().then((TMap) => {
this.TXMap = TMap;
this.tMap = new TMap.Map("map", {
center: new TMap.LatLng(23.030886,113.757800),
zoom: 15,
viewMode: "3D",
});
});
},
lookCarPath(){
let path = [
new this.TXMap.LatLng(23.030886,113.757800),
new this.TXMap.LatLng(23.031128,113.758686),
new this.TXMap.LatLng(23.031369,113.759726),
new this.TXMap.LatLng(23.031177,113.760241),
new this.TXMap.LatLng(23.030362,113.760815),
new this.TXMap.LatLng(23.029602,113.761277),
new this.TXMap.LatLng(23.028506,113.761722),
new this.TXMap.LatLng(23.026847,113.762156),
new this.TXMap.LatLng(23.025687,113.762886),
new this.TXMap.LatLng(23.025193,113.762977),
new this.TXMap.LatLng(23.023944,113.761582),
new this.TXMap.LatLng(23.022310,113.758718),
new this.TXMap.LatLng(23.021802,113.755826),
new this.TXMap.LatLng(23.021806,113.754957),
new this.TXMap.LatLng(23.018212,113.754147),
new this.TXMap.LatLng(23.014534,113.753600),
new this.TXMap.LatLng(23.013309,113.757248),
new this.TXMap.LatLng(23.011690,113.760037),
new this.TXMap.LatLng(22.994348,113.747377),
new this.TXMap.LatLng(22.985222,113.737679),
new this.TXMap.LatLng(22.968588,113.718839),
new this.TXMap.LatLng(22.967798,113.709869),
new this.TXMap.LatLng(22.969852,113.701200),
new this.TXMap.LatLng(22.972026,113.698239),
new this.TXMap.LatLng(22.964321,113.695750),
new this.TXMap.LatLng(22.955390,113.687339),
new this.TXMap.LatLng(22.946736,113.678713),
new this.TXMap.LatLng(22.937211,113.670259),
new this.TXMap.LatLng(22.925591,113.663907),
new this.TXMap.LatLng(22.920769,113.662019),
new this.TXMap.LatLng(22.902862,113.661718),
new this.TXMap.LatLng(22.888669,113.660002),
new this.TXMap.LatLng(22.873249,113.662448),
new this.TXMap.LatLng(22.859132,113.671460)
]
let carImg = '~@/../car.png'
let map = this.tMap
this.polylineLayer = new this.TXMap.MultiPolyline({
map,
styles: {
style_blue: new this.TXMap.PolylineStyle({
color: '#3777FF',
width: 4,
borderWidth: 2,
borderColor: '#FFF',
lineCap: 'round',
eraseColor: 'rgba(190,188,188,1)',
}),
},
geometries: [
{
id: 'erasePath',
styleId: 'style_blue',
paths: path,
},
],
});
this.markerLayer = new this.TXMap.MultiMarker({
map,
styles: {
'car-down': new this.TXMap.MarkerStyle({
'width': 40,
'height': 40,
'anchor': {
x: 20,y: 20,
},
'faceTo': 'map',
'rotate': 180,
'src': carImg,
}),
start: new this.TXMap.MarkerStyle({
width: 25,
height: 35,
anchor: { x: 16, y: 32 },
src: 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/start.png',
}),
end: new this.TXMap.MarkerStyle({
width: 25,
height: 35,
anchor: { x: 16, y: 32 },
src: 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/end.png',
})
},
geometries: [
{
id: 'car',
styleId: 'car-down',
position: new this.TXMap.LatLng(23.030886,113.757800),
},
{
id: 'start',
styleId: 'start',
position: new this.TXMap.LatLng(23.030886,113.757800),
},
{
id: 'end',
styleId: 'end',
position: new this.TXMap.LatLng(22.859132,113.671460),
}
]
});
this.markerLayer.moveAlong({
"car": {
path,
speed: 90
}
}, {
autoRotation:true
}
)
this.markerLayer.on('moving', (e) => {
console.log(e)
var passedLatLngs = e.car && e.car.passedLatLngs;
if (passedLatLngs) {
this.polylineLayer.eraseTo(
'erasePath',
passedLatLngs.length - 1,
passedLatLngs[passedLatLngs.length - 1]
);
}
});
},
}
}
</script>