智慧矿山无人驾驶模块
生活随笔
收集整理的這篇文章主要介紹了
智慧矿山无人驾驶模块
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
先看效果圖
實(shí)現(xiàn)步驟
獲取點(diǎn)
在editHelper中獲取運(yùn)動(dòng)的路線
獲取的路線數(shù)據(jù)如下:
獲取車輛圖層
// 獲取圖層樹 const res = await __g.infoTree.get() // 獲取礦車id mainCarId = res.infotree.filter((item: any) => item.name === '礦車')[0].iD // 獲取圖層 const objRes = await __g.tileLayer.getObjectIDs(mainCarId) // 獲取圖層內(nèi)對(duì)象id objId = objRes.data[0].objectIds[0]隱藏多余圖層
let infoArr, hideArr const needHideArr: any = ['礦車', '礦坑輪廓線', '礦坑熱力', '隧道場(chǎng)景', '智慧農(nóng)業(yè)_底圖', '智慧農(nóng)業(yè)_底圖分塊', '智慧農(nóng)業(yè)地質(zhì)層', '智慧環(huán)保底板特效'] /*** 隱藏圖層*/ const hideNeed = async () => {// 獲取圖層樹infoArr = await __g.infoTree.get()// 過濾需要顯示的圖層hideArr = infoArr.infotree.filter((item: any) => needHideArr.includes(item.name)).map((item: any) => item.iD)// 隱藏圖層await __g.infoTree.hide(hideArr) }添加礦車
/*** 添加礦車* @param location 位置* @param id 車輛id* @param rotation 旋轉(zhuǎn)角度*/ const addCar = async (location: number[], id: string, rotation = [0, 0, 0]) => {await __g.customObject.addByTileLayer({id,tileLayerId: mainCarId,//注意5.3新增特性:數(shù)組參數(shù)objectId: [objId],location,rotation,smoothMotion: 1 //1: 平滑插值,0: 跳躍}) }添加mark標(biāo)簽
/*** 添加標(biāo)簽* @param id* @param coordinate 坐標(biāo)* @param text 文本*/ const addMark = async (id: string, coordinate: any, text = '礦車-正在工作') => {// 創(chuàng)建標(biāo)簽const markerObj = {id,groupId: 'markerAdd',coordinate, //坐標(biāo)位置coordinateType: 0, //默認(rèn)0是投影坐標(biāo)系,也可以設(shè)置為經(jīng)緯度空間坐標(biāo)系值為1range: [1, 100000], //可視范圍fixedSize: true, //圖片固定尺寸,取值范圍:false 自適應(yīng),近大遠(yuǎn)小,true 固定尺寸,默認(rèn)值:falsetext, //顯示的文字useTextAnimation: true, //打開文字展開動(dòng)畫效果textRange: [1, 100000], //文本可視范圍[近裁距離, 遠(yuǎn)裁距離]textOffset: [0, 0], // 文本偏移textBackgroundColor: [1.0, 1.0, 1.0, 0.5], //文本背景顏色fontSize: 12, //字體大小fontColor: Color.White, //字體顏色popupURL: `${window.origin}/tag/showWorkState.html?`, //彈窗HTML鏈接popupBackgroundColor: [1.0, 1.0, 1.0, 1.0], //彈窗背景顏色popupSize: [500, 350], //彈窗大小popupOffset: [0, 0], //彈窗偏移autoHidePopupWindow: true, //失去焦點(diǎn)后是否自動(dòng)關(guān)閉彈出窗口autoHeight: true, // 自動(dòng)判斷下方是否有物體displayMode: 4, //顯示模式clusterByImage: true, // 聚合時(shí)是否根據(jù)圖片路徑分類,即當(dāng)多個(gè)marker的imagePath路徑參數(shù)相同時(shí)按路徑對(duì)marker分類聚合priority: 1, //避讓優(yōu)先級(jí)occlusionCull: false //是否參與遮擋剔除}await __g.marker.add(markerObj) }車輛移動(dòng)
/*** 添加平移* @param carNumber 第幾輛車* @param carId 車輛id*/ const addMove = async (carNumber: number, carId: string) => {// 開始平移const pathPointArr = []for (let i = 0; i < __gps_pos[carNumber].length; i++) {//構(gòu)造數(shù)組元素 每2秒移動(dòng)一次const elementPoint = { time: i * 2, coordinate: __gps_pos[carNumber][i] }pathPointArr.push(elementPoint)}//設(shè)置跟隨相機(jī)__g.customObject.setRotation(carId, [0, -90, 0])//車輛按GPS軌跡移動(dòng)__g.customObject.startMove(carId, 0, pathPointArr) }設(shè)置標(biāo)簽跟隨
// 設(shè)置標(biāo)簽跟隨__g.marker.setAttachCustomObject({markerId: 'car_mark_1',objectId: 'car_move_1',offset: [0, 0, 0]})__g.marker.setAttachCustomObject({markerId: 'car_mark_2',objectId: 'car_move_2',offset: [0, 0, 0]})點(diǎn)擊車輛旋轉(zhuǎn)相機(jī)
在Event.ts判斷點(diǎn)擊物體
const OnEvent = async (e: { eventtype: string; PropertyName?: string; UserData?: string; ObjectID?: string; Id?: string; GroupID?: string; MouseClickPoint?: number[]; Type?: string }) => {console.log('鼠標(biāo)左鍵單擊', e)// 判斷是否為左鍵點(diǎn)擊的交互if (e.eventtype === 'LeftMouseButtonClick') {if (e.Type == 'marker' && e.Id == 'car_mark_3') {__g.camera.set(-601.601094, 361.158125, -60.57855, 0.393528, -118.390999, 1)}} }開始自動(dòng)駕駛模塊
/*** 無人駕駛*/ export const unmanned = async () => {setTheTime()clean()await addCar([-813.645264, 724.513428, -61.49287], 'car_move_1', [0, -28, 0])addMark('car_mark_1', [-882.71228, 774.266724, 0])await addCar([-665.85467529296875, 480.9832763671875, -64.897811889648438], 'car_move_2', [0, -28, 0])addMark('car_mark_2', [-665.85467529296875, 480.9832763671875, 0])// 設(shè)置標(biāo)簽跟隨__g.marker.setAttachCustomObject({markerId: 'car_mark_1',objectId: 'car_move_1',offset: [0, 0, 0]})__g.marker.setAttachCustomObject({markerId: 'car_mark_2',objectId: 'car_move_2',offset: [0, 0, 0]})addMove(0, 'car_move_1')addMove(1, 'car_move_2')// 添加靜止車輛await addCar([-609.2427978515625, 376.18206787109375, -61.138870239257813], 'car_move_3', [0, 0, 0])addMark('car_mark_3', [-823.35150146484375, 666.82122802734375, 0], '礦車-空閑')__g.marker.setAttachCustomObject({markerId: 'car_mark_3',objectId: 'car_move_3',offset: [0, 0, 0]})最后 離開頁面清除所有操作(很重要!!!)*
const clean = () => {__g.customObject.clear() }具體視頻效果,可以查看
總結(jié)
以上是生活随笔為你收集整理的智慧矿山无人驾驶模块的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php微信群,PHP微信群加群强制分享转
- 下一篇: 如何做浏览器兼容性测试?教你几招