轨迹动画
This commit is contained in:
parent
a330a7d102
commit
8aed47b3ad
|
|
@ -25,7 +25,6 @@ declare module 'vue' {
|
|||
MapEcharts: typeof import('./src/components/echarts/mapEcharts.vue')['default']
|
||||
MapEcharts2: typeof import('./src/components/echartsCom/mapEcharts2.vue')['default']
|
||||
MapLine: typeof import('./src/components/mapBaidu/mapLine.vue')['default']
|
||||
'MapLine copy': typeof import('./src/components/mapBaidu/mapLine copy.vue')['default']
|
||||
Pie3dCom: typeof import('./src/components/echartsCom/Pie3dCom.vue')['default']
|
||||
Pie3dCom1: typeof import('./src/components/echartsCom/Pie3dCom1.vue')['default']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
<title>Vite App</title>
|
||||
</head>
|
||||
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=cClgLBaLgGUdQDilX9dGvieL"></script>
|
||||
<script src="http://mapopen.bj.bcebos.com/github/BMapGLLib/TrackAnimation/src/TrackAnimation.min.js"></script>
|
||||
<script src="http://api.map.baidu.com/api?type=webgl&v=2.0&ak=cClgLBaLgGUdQDilX9dGvieL"></script>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
|
|
|
|||
|
|
@ -1,71 +1,113 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||
<style type="text/css">
|
||||
body, html {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
|
||||
#allmap{width:100%;height:500px;}
|
||||
p{margin-left:5px; font-size:14px;}
|
||||
</style>
|
||||
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=cClgLBaLgGUdQDilX9dGvieL"></script>
|
||||
<title>添加自定义覆盖物</title>
|
||||
<meta charset="utf-8">
|
||||
<title>轨迹视角动画暂停与继续</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
|
||||
<style>
|
||||
body,
|
||||
html,
|
||||
#container {
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
font-family: "微软雅黑";
|
||||
}
|
||||
ul li {
|
||||
list-style: none;
|
||||
}
|
||||
.drawing-panel {
|
||||
z-index: 999;
|
||||
position: fixed;
|
||||
bottom: 3.5rem;
|
||||
margin-left: 3rem;
|
||||
padding: 1rem 1rem;
|
||||
border-radius: .25rem;
|
||||
background-color: #fff;
|
||||
box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
|
||||
}
|
||||
.btn {
|
||||
width: 90px;
|
||||
height: 30px;
|
||||
float: left;
|
||||
background-color: #fff;
|
||||
color: rgba(27, 142, 236, 1);
|
||||
font-size: 14px;
|
||||
border:1px solid rgba(27, 142, 236, 1);
|
||||
border-radius: 5px;
|
||||
margin: 0 5px;
|
||||
text-align: center;
|
||||
line-height: 30px;
|
||||
}
|
||||
.btn:hover {
|
||||
background-color: rgba(27, 142, 236, 0.8);
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
<script src="//mapopen.bj.bcebos.com/github/BMapGLLib/TrackAnimation/src/TrackAnimation.min.js"></script>
|
||||
<script src="//api.map.baidu.com/api?type=webgl&v=2.0&ak=cClgLBaLgGUdQDilX9dGvieL"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="allmap"></div>
|
||||
<p>图示中为房产覆盖物,鼠标移到覆盖物上,自动显示房屋套数</p>
|
||||
<div id="container"></div>
|
||||
<ul class="drawing-panel" style="z-index: 99;">
|
||||
<li class = "btn" onclick = "pauseAni()">暂停</li>
|
||||
<li class = "btn" onclick = "continueAni()">继续</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
<script type="text/javascript">
|
||||
// 百度地图API功能
|
||||
const mp = new BMap.Map("allmap");
|
||||
mp.centerAndZoom(new BMap.Point(116.3964,39.9093), 15);
|
||||
mp.enableScrollWheelZoom();
|
||||
// 复杂的自定义覆盖物
|
||||
const initCustomDot=()=>{
|
||||
function ComplexCustomOverlay(point){
|
||||
this._point = point;
|
||||
|
||||
}
|
||||
ComplexCustomOverlay.prototype = new BMap.Overlay();
|
||||
ComplexCustomOverlay.prototype.initialize = function(map){
|
||||
this._map = map;
|
||||
const pixel = map.pointToOverlayPixel(this._point,{
|
||||
useRound:false, // 设置此参数,防止抖动
|
||||
fixPosition:true // 覆盖物跨越180时修正位置
|
||||
});
|
||||
const div = this._div = document.createElement("div");
|
||||
div.style.position = "absolute";
|
||||
div.style.width = "16px";
|
||||
div.style.height = "16px";
|
||||
div.style.background = "#0d84ec";
|
||||
div.style.borderRadius = "50%";
|
||||
const divInner = this._divInner = document.createElement("div");
|
||||
divInner.style.position = "absolute";
|
||||
divInner.style.width = "10px";
|
||||
divInner.style.height = "10px";
|
||||
divInner.style.left = "3px";
|
||||
divInner.style.top = "3px";
|
||||
divInner.style.background = "#f00";
|
||||
divInner.style.borderRadius = "50%";
|
||||
mp.getPanes().labelPane.appendChild(div);
|
||||
mp.getPanes().labelPane.appendChild(divInner);
|
||||
|
||||
return div;
|
||||
}
|
||||
ComplexCustomOverlay.prototype.draw = function(){
|
||||
const map = this._map;
|
||||
const pixel = map.pointToOverlayPixel(new BMap.Point(116.3964,39.9093));
|
||||
this._div.style.left = pixel.x + "px";
|
||||
this._div.style.top = pixel.y + "px";
|
||||
this._divInner.style.left = pixel.x +3+ "px";
|
||||
this._divInner.style.top = pixel.y +3+ "px";
|
||||
}
|
||||
const myCompOverlay = new ComplexCustomOverlay(new BMap.Point(116.3964,39.9093) );
|
||||
mp.addOverlay(myCompOverlay);
|
||||
}
|
||||
|
||||
initCustomDot()
|
||||
<script>
|
||||
var bmap = new BMapGL.Map("container");
|
||||
bmap.centerAndZoom(new BMapGL.Point(116.297611, 40.047363), 17);
|
||||
bmap.enableScrollWheelZoom(true);
|
||||
var path = [{
|
||||
'lng': 116.297611,
|
||||
'lat': 40.047363
|
||||
}, {
|
||||
'lng': 116.302839,
|
||||
'lat': 40.048219
|
||||
}, {
|
||||
'lng': 116.308301,
|
||||
'lat': 40.050566
|
||||
}, {
|
||||
'lng': 116.305732,
|
||||
'lat': 40.054957
|
||||
}, {
|
||||
'lng': 116.304754,
|
||||
'lat': 40.057953
|
||||
}, {
|
||||
'lng': 116.306487,
|
||||
'lat': 40.058312
|
||||
}, {
|
||||
'lng': 116.307223,
|
||||
'lat': 40.056379
|
||||
}];
|
||||
var point = [];
|
||||
for (var i = 0; i < path.length; i++) {
|
||||
point.push(new BMapGL.Point(path[i].lng, path[i].lat));
|
||||
}
|
||||
var pl = new BMapGL.Polyline(point,{
|
||||
strokeColor:"#f00",
|
||||
strokeWeight:4
|
||||
});
|
||||
setTimeout('start()', 3000);
|
||||
trackAni = new BMapGLLib.TrackAnimation(bmap, pl, {
|
||||
overallView:true,
|
||||
tilt: 30,
|
||||
duration: 3000,
|
||||
delay: 300
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
function start () {
|
||||
trackAni.start();
|
||||
}
|
||||
function pauseAni () {
|
||||
trackAni.pause();
|
||||
}
|
||||
function continueAni () {
|
||||
trackAni.continue();
|
||||
}
|
||||
</script>
|
||||
|
|
@ -1,164 +0,0 @@
|
|||
<template>
|
||||
<div id="equipmentIdMap" class="map">
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getImg } from "@/utils/index"
|
||||
import { apiBmCompanyInfoTimeListTime } from "http/api/echartApi"
|
||||
let map: any = null
|
||||
let point: any = null
|
||||
onMounted(() => {
|
||||
console.log("map", "map")
|
||||
|
||||
})
|
||||
|
||||
const linePointList:any = []
|
||||
let centerPoint:any = null
|
||||
const initMap = () => {
|
||||
map = new BMap.Map("equipmentIdMap");
|
||||
|
||||
map.centerAndZoom(new BMap.Point(116.3944, 39.9063), 18);
|
||||
console.log("map", map)
|
||||
map.enableScrollWheelZoom();
|
||||
setTimeout(() => {
|
||||
|
||||
const startIcon = {
|
||||
imgUrl: '/src/assets/img/mapStart.png',
|
||||
position: [116.3964, 39.9093],
|
||||
size: [60, 60]
|
||||
|
||||
}
|
||||
|
||||
const endIcon = {
|
||||
imgUrl: '/src/assets/img/mapStart.png',
|
||||
position: [116.3964, 39.9093],
|
||||
size: [60, 60]
|
||||
|
||||
}
|
||||
initIcon(startIcon.imgUrl, startIcon.position, startIcon.size)
|
||||
initIcon(endIcon.imgUrl, endIcon.position, endIcon.size)
|
||||
initCustomDot(centerPoint)
|
||||
|
||||
initPolyline()
|
||||
setViewPortFn()
|
||||
}, 200)
|
||||
}
|
||||
|
||||
|
||||
const initCustomDot = (point:any) => {
|
||||
function ComplexCustomOverlay(point) {
|
||||
this._point = point;
|
||||
|
||||
}
|
||||
ComplexCustomOverlay.prototype = new BMap.Overlay();
|
||||
ComplexCustomOverlay.prototype.initialize = function (map) {
|
||||
const div = this._div = document.createElement("div");
|
||||
div.style.position = "absolute";
|
||||
div.style.width = "30px";
|
||||
div.style.height = "30px";
|
||||
div.style.background = "#fff";
|
||||
div.style.borderRadius = "50%";
|
||||
const divInner = this._divInner = document.createElement("div");
|
||||
divInner.style.position = "absolute";
|
||||
divInner.style.width = "20px";
|
||||
divInner.style.height = "20px";
|
||||
divInner.style.left = "5px";
|
||||
divInner.style.top = "5px";
|
||||
divInner.style.background = "#0788e6";
|
||||
divInner.style.borderRadius = "50%";
|
||||
map.getPanes().labelPane.appendChild(div);
|
||||
map.getPanes().labelPane.appendChild(divInner);
|
||||
|
||||
return div;
|
||||
}
|
||||
ComplexCustomOverlay.prototype.draw = function () {
|
||||
|
||||
const pixel = map.pointToOverlayPixel(point);
|
||||
this._div.style.left = pixel.x + "px";
|
||||
this._div.style.top = pixel.y + "px";
|
||||
this._divInner.style.left = pixel.x + 5 + "px";
|
||||
this._divInner.style.top = pixel.y + 5 + "px";
|
||||
}
|
||||
const myCompOverlay: any = new ComplexCustomOverlay(point);
|
||||
map.addOverlay(myCompOverlay);
|
||||
}
|
||||
|
||||
|
||||
const initPolyline = () => {
|
||||
var polyline = new BMap.Polyline(linePointList, { strokeColor: "blue", strokeWeight: 8, strokeOpacity: 1. });
|
||||
map.addOverlay(polyline);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
const initIcon = (imgUrl: any, position: any, size: any) => {
|
||||
var myIcon = new BMap.Icon("https://api.map.baidu.com/img/markers.png", new BMap.Size(60, 60));
|
||||
// 创建Marker标注,使用小车图标
|
||||
var pt = new BMap.Point(...position);
|
||||
var marker = new BMap.Marker(pt, {
|
||||
icon: myIcon
|
||||
});
|
||||
// 将标注添加到地图
|
||||
map.addOverlay(marker);
|
||||
}
|
||||
|
||||
const setViewPortFn = () => {
|
||||
const boundList =linePointList
|
||||
map.setViewport(boundList)
|
||||
}
|
||||
|
||||
|
||||
// var pointArr = [new BMap.Point(106.607421,29.570857),new BMap.Point(106.620931,29.586185)];
|
||||
|
||||
const getcenterpoiont=(pointStart:any,pointEnd:any)=>{
|
||||
const lng1 = parseFloat(pointStart.lng);
|
||||
const lat1 = parseFloat(pointStart.lat);
|
||||
|
||||
const lng2 = parseFloat(pointEnd.lng);
|
||||
const lat2 = parseFloat(pointEnd.lat);
|
||||
|
||||
const lngca = (Math.max(lng1,lng2)-Math.min(lng1,lng2))/2;
|
||||
const latca = (Math.max(lat1,lat2)-Math.min(lat1,lat2))/2;
|
||||
|
||||
const lngcenter = Math.min(lng1,lng2)+lngca;
|
||||
const latcenter = Math.min(lat1,lat2)+latca;
|
||||
|
||||
const pointcenter = new BMap.Point(lngcenter,latcenter);
|
||||
return pointcenter;
|
||||
|
||||
}
|
||||
const initMapLine = (params: any) => {
|
||||
|
||||
initApiBmCompanyInfoTimeListTime(params)
|
||||
}
|
||||
|
||||
const initApiBmCompanyInfoTimeListTime = async (val: any) => {
|
||||
|
||||
try {
|
||||
const res: any = await apiBmCompanyInfoTimeListTime(val)
|
||||
console.log("apiBmCompanyInfoTimeListTime", res)
|
||||
res.forEach((ele:any) => {
|
||||
linePointList.push( new BMap.Point(Number(ele.lon),Number(ele.lat)))
|
||||
})
|
||||
centerPoint = getcenterpoiont(res[0],res[res.length-1])
|
||||
initMap()
|
||||
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
defineExpose({
|
||||
initMapLine
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.map {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -13,6 +13,7 @@ let map: any = null
|
|||
let centerPoint: any = null
|
||||
let domId = ref("0")
|
||||
let domShow = ref(false)
|
||||
let animiationLineList = []
|
||||
onMounted(() => {
|
||||
console.log("map", "map")
|
||||
})
|
||||
|
|
@ -20,8 +21,8 @@ onMounted(() => {
|
|||
const linePointList: any = []
|
||||
|
||||
const initMap = () => {
|
||||
map = new BMap.Map("equipmentIdMap" + domId.value);
|
||||
map.centerAndZoom(new BMap.Point(116.3944, 39.9063), 18);
|
||||
map = new BMapGL.Map("equipmentIdMap" + domId.value);
|
||||
map.centerAndZoom(new BMapGL.Point(116.3944, 39.9063), 18);
|
||||
console.log("map", map)
|
||||
map.enableScrollWheelZoom();
|
||||
setTimeout(() => {
|
||||
|
|
@ -40,7 +41,8 @@ const initMap = () => {
|
|||
}
|
||||
initIcon(startIcon.imgUrl, startIcon.position, startIcon.size)
|
||||
initIcon(endIcon.imgUrl, endIcon.position, endIcon.size)
|
||||
initPolyline()
|
||||
// initPolyline()
|
||||
initPolylineAnimation()
|
||||
setViewPortFn()
|
||||
}, 200)
|
||||
}
|
||||
|
|
@ -49,7 +51,7 @@ const initMap = () => {
|
|||
const initCustomDot = (centerPoint: any) => {
|
||||
function ComplexCustomOverlay(centerPoint) {
|
||||
}
|
||||
ComplexCustomOverlay.prototype = new BMap.Overlay();
|
||||
ComplexCustomOverlay.prototype = new BMapGL.Overlay();
|
||||
ComplexCustomOverlay.prototype.initialize = function (map) {
|
||||
const div = this._div = document.createElement("div");
|
||||
div.style.position = "absolute";
|
||||
|
|
@ -83,15 +85,35 @@ const initCustomDot = (centerPoint: any) => {
|
|||
|
||||
|
||||
const initPolyline = () => {
|
||||
var polyline = new BMap.Polyline(linePointList, { strokeColor: '#0788e6', strokeWeight: 4, strokeOpacity: 1. });
|
||||
var polyline = new BMapGL.Polyline(linePointList, { strokeColor: '#0788e6', strokeWeight: 4, strokeOpacity: 1. });
|
||||
map.addOverlay(polyline);
|
||||
}
|
||||
|
||||
const initPolylineAnimation = () => {
|
||||
var pl = new BMapGL.Polyline(linePointList, {
|
||||
strokeColor: "#0e83ed",
|
||||
strokeWeight: 4
|
||||
});
|
||||
// setTimeout('start()', 3000);
|
||||
const trackAni = new BMapGLLib.TrackAnimation(map, pl, {
|
||||
overallView: true,
|
||||
tilt: 30,
|
||||
duration: 200,
|
||||
delay: 300,
|
||||
});
|
||||
start()
|
||||
function start() {
|
||||
trackAni.start();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
const initIcon = (imgUrl: any, position: any, size: any) => {
|
||||
var myIcon = new BMap.Icon("https://api.map.baidu.com/img/markers.png", new BMap.Size(60, 60));
|
||||
var myIcon = new BMapGL.Icon("https://api.map.baidu.com/img/markers.png", new BMapGL.Size(60, 60));
|
||||
// 创建Marker标注,使用小车图标
|
||||
var pt = new BMap.Point(...position);
|
||||
var marker = new BMap.Marker(pt, {
|
||||
var pt = new BMapGL.Point(...position);
|
||||
var marker = new BMapGL.Marker(pt, {
|
||||
icon: myIcon
|
||||
});
|
||||
// 将标注添加到地图
|
||||
|
|
@ -119,7 +141,7 @@ const getcenterpoiont = (pointStart: any, pointEnd: any) => {
|
|||
const lngcenter = Math.min(lng1, lng2) + lngca;
|
||||
const latcenter = Math.min(lat1, lat2) + latca;
|
||||
|
||||
const pointcenter = new BMap.Point(lngcenter, latcenter);
|
||||
const pointcenter = new BMapGL.Point(lngcenter, latcenter);
|
||||
return pointcenter;
|
||||
|
||||
}
|
||||
|
|
@ -136,7 +158,7 @@ const initApiBmCompanyInfoTimeListTime = async (val: any) => {
|
|||
domShow.value = true
|
||||
console.log("apiBmCompanyInfoTimeListTime", res)
|
||||
res.forEach((ele: any) => {
|
||||
linePointList.push(new BMap.Point(Number(ele.lon), Number(ele.lat)))
|
||||
linePointList.push(new BMapGL.Point(Number(ele.lon), Number(ele.lat)))
|
||||
})
|
||||
nextTick(() => {
|
||||
initMap()
|
||||
|
|
|
|||
Loading…
Reference in New Issue