| | |
| | | import calculate from '@/utils/map/calculate'; |
| | | import Layer from '@/utils/map/3dLayer'; |
| | | import sector from '@/utils/map/sector'; |
| | | import map from '@/utils/map/index_old'; |
| | | import { map } from '@/utils/map/index_old'; |
| | | import util from '@/utils/map/util'; |
| | | import car_driving from '@/assets/mipmap/car_driving.png'; |
| | | import boat_driving from '@/assets/mipmap/boat_driving.png'; |
| | | |
| | | function MapAnimation() { |
| | | // 非连续坐标点最大距离(米) |
| | | this.maxD = 500; |
| | | // 当前绘制的监测因子类型 |
| | | this.factorType = 0; |
| | | this.factorType; |
| | | this.factorDatas; |
| | | // 载具类型 |
| | | this.vehicleType = 0; // 0: 车辆;1:无人机:2:无人船 |
| | |
| | | this._fps = this.frameAnimation.fps; |
| | | // 绘制图形缓存 |
| | | this.moveViews = {}; |
| | | this.clear = true; |
| | | } |
| | | |
| | | MapAnimation.prototype = { |
| | |
| | | var fData2 = factorDatas.getByIndex(i + 1, i + 2); |
| | | |
| | | // 计算动画轨迹 |
| | | for (let i = 0; i < count - 1; i++) { |
| | | for (let i = 0; i < count; i++) { |
| | | // path |
| | | var length = d * (i + 1); |
| | | if (isNaN(angle)) { |
| | |
| | | animationData, |
| | | function (data, index, count) { |
| | | var length = data.length(); |
| | | var start = length - count + 1; |
| | | var start = length - count; |
| | | // 1.获取数据 |
| | | var d = data.getByIndex(0, start + index + 1); |
| | | var f = d.factor[that.factorType + 1 + '']; |
| | | var f = d.factor[that.factorType]; |
| | | // 2.绘制图形 |
| | | if (length > count || index > 0) { |
| | | // 3d图形 |
| | | // var lnglat = d.lnglats_GD[d.lnglats_GD.length - 1]; |
| | | Layer.drawMesh(d, f); |
| | | // MapUtil.drawLine(lnglat) |
| | | |
| | | // 风向风速 |
| | | sector.drawSector(d, start + index); |
| | | // if (d.factor['17'] != undefined && d.factor['16'] != undefined) { |
| | | // var windDir = d.factor['17'].datas; |
| | | // windDir = windDir[windDir.length - 1].factorData; |
| | | // var windSpeed = d.factor['16'].datas; |
| | | // windSpeed = windSpeed[windSpeed.length - 1].factorData; |
| | | // MapUtil.drawSector4(lnglat, windDir, windSpeed); |
| | | // } |
| | | sector.drawSectorAna(d, start + index); |
| | | // 执行监听函数 |
| | | if (typeof that.OnEachFrameCallback === 'function') { |
| | | that.OnEachFrameCallback(d, start + index); |
| | | } |
| | | // 绘制3D图形时,最少需要2个点才可绘制图形 |
| | | // 因此此处索引只到倒数第二个点就结束,此时执行这段任务结束的监听回调 |
| | | if (typeof that.OnEachTaskEndCallback === 'function') { |
| | | that.OnEachTaskEndCallback(d); |
| | | } |
| | | } |
| | | |
| | | var pos = d.lnglats_GD[d.lnglats_GD.length - 1]; |
| | |
| | | this.start(); |
| | | }, |
| | | |
| | | /** |
| | | * 设置每一帧的监听函数 |
| | | * @param {Function} callback |
| | | */ |
| | | setOnEachFrameCallback(callback) { |
| | | this.OnEachFrameCallback = callback; |
| | | }, |
| | | |
| | | /** |
| | | * 设置每一段任务结束的监听函数 |
| | | * @param {Function} callback |
| | | */ |
| | | setOnEachTaskEndCallback(callback) { |
| | | this.OnEachTaskEndCallback = callback; |
| | | }, |
| | | |
| | | /*******************************动画任务逻辑 -start ******************************/ |
| | | start: function () { |
| | | sector.clearSector(); |
| | | if (this.frameAnimation.isStop) { |
| | | sector.clearSector(); |
| | | } |
| | | this.frameAnimation.start(); |
| | | }, |
| | | changeSpeed: function (speed) { |
| | |
| | | stop: function () { |
| | | this.factorDatas = undefined; |
| | | this.frameAnimation.addOnNextTasks(undefined); |
| | | // this.OnEachFrameCallback = undefined; |
| | | // this.OnEachTaskEndCallback = undefined; |
| | | this.frameAnimation.stop(); |
| | | }, |
| | | setOnStopCallback: function (callback) { |
| | |
| | | /*******************************动画任务逻辑 -end ******************************/ |
| | | |
| | | _clearMap: function () { |
| | | if (!this.clear) return; |
| | | |
| | | var list = []; |
| | | for (const key in this.moveViews) { |
| | | list.push(this.moveViews[key]); |
| | |
| | | var url; |
| | | switch (this.vehicleType) { |
| | | case 0: |
| | | url = './asset/mipmap/car_driving.png'; |
| | | url = car_driving; |
| | | break; |
| | | case 1: |
| | | url = './asset/mipmap/car_driving.png'; |
| | | url = car_driving; |
| | | break; |
| | | case 2: |
| | | url = './asset/mipmap/boat_driving.png'; |
| | | url = boat_driving; |
| | | break; |
| | | default: |
| | | url = './asset/mipmap/car_driving.png'; |
| | | url = car_driving; |
| | | break; |
| | | } |
| | | // var url = "./asset/mipmap/car_offline.png"; |
| | |
| | | // break; |
| | | // } |
| | | |
| | | // eslint-disable-next-line no-undef |
| | | var icon = new AMap.Icon({ |
| | | // eslint-disable-next-line no-undef |
| | | size: new AMap.Size(60, 30), |
| | | // eslint-disable-next-line no-undef |
| | | imageSize: new AMap.Size(54, 21), |
| | | image: url |
| | | // imageOffset: new AMap.Pixel(-16, -16) // 相对于基点的偏移位置 |
| | | }); |
| | | |
| | | // eslint-disable-next-line no-undef |
| | | var car = new AMap.Marker({ |
| | | icon: icon, |
| | | position: lnglat, // 基点位置 |
| | | // eslint-disable-next-line no-undef |
| | | offset: new AMap.Pixel(-20, -15) // 相对于基点的偏移位置 |
| | | }); |
| | | |
| | | MapUtil._map.add(car); |
| | | map.add(car); |
| | | this.moveViews['car'] = car; |
| | | |
| | | // 时间 |
| | | // eslint-disable-next-line no-undef |
| | | var text = new AMap.Text({ |
| | | text: time, |
| | | position: lnglat, |
| | | // eslint-disable-next-line no-undef |
| | | offset: new AMap.Pixel(5, 20), |
| | | style: { |
| | | 'font-size': '13px', |
| | |
| | | padding: '0 4px' |
| | | } |
| | | }); |
| | | MapUtil._map.add(text); |
| | | map.add(text); |
| | | this.moveViews['text'] = text; |
| | | } else { |
| | | MapUtil.setCenter(lnglat); |
| | | util.setCenter(lnglat); |
| | | this.moveViews['car'].setPosition(lnglat); |
| | | this.moveViews['text'].setPosition(lnglat); |
| | | this.moveViews['text'].setText(time); |
| | |
| | | } |
| | | }; |
| | | |
| | | export { MapAnimation }; |
| | | const realTimeMapAnimation = new MapAnimation(); |
| | | realTimeMapAnimation.clear = false; |
| | | |
| | | export { realTimeMapAnimation, MapAnimation }; |