194 lines
5.8 KiB
TypeScript
194 lines
5.8 KiB
TypeScript
|
|
import MarkerOption from '@/models/marker.option.js'
|
|
import PolygonOption from '@/models/polygon.option.js';
|
|
import * as acapi from '../assets/ac.min.js'
|
|
// import acapi from 'ac.min.js'
|
|
export default class PlayerUtils{
|
|
public api:any;
|
|
public initPlayer(domId,iid?){
|
|
const player = new acapi.DigitalTwinPlayer(process.env.VUE_APP_PALYER_URL,{
|
|
domId,
|
|
iid,
|
|
// reset:true,
|
|
apiOptions:{
|
|
onReady: this.onReady,
|
|
onLog: this.onLog, //可选参数,日志输出回调函数
|
|
onEvent: this.onEvent
|
|
},
|
|
ui:{
|
|
startupInfo:false,
|
|
mainUI:false
|
|
},
|
|
|
|
events: {
|
|
onVideoLoaded: this.onLoad, //可选参数,视频流加载成功回调函数
|
|
onConnClose: this.onClose, //可选参数,连接断开回调函数
|
|
mouseKeyListener:{
|
|
onMouseEnter:this.onMouseEnter,
|
|
onMouseLeave:this.onMouseLeave,
|
|
onMouseMove:this.onMouseMove,
|
|
onMouseDown:this.onMouseDown,
|
|
onMouseUp:this.onMouseUp,
|
|
onKeyDown:this.onKeyDown,
|
|
onKeyUp:this.onKeyUp,
|
|
onKeyPress:this.onKeyPress,
|
|
}
|
|
},
|
|
keyEventTarget: 'video',
|
|
})
|
|
this.api = player.getAPI();
|
|
return player
|
|
}
|
|
|
|
public onReady:any=null;
|
|
|
|
public onLog :any= null;
|
|
|
|
public onEvent :any = null;
|
|
|
|
public onLoad :any= null;
|
|
|
|
public onClose :any= null;
|
|
public onMouseEnter :any= null;
|
|
public onMouseLeave :any= null;
|
|
public onMouseMove :any= null;
|
|
public onMouseDown :any= null;
|
|
public onMouseUp :any= (res)=>{
|
|
this.api.camera.get((data)=>{
|
|
console.log(data)
|
|
})
|
|
};;
|
|
public onKeyDown :any= null;
|
|
public onKeyUp :any= null;
|
|
public onKeyPress :any= null;
|
|
|
|
|
|
public async addMarker(data:MarkerOption | MarkerOption[],fn?:any){
|
|
const option = {
|
|
range: [1, 10000],
|
|
autoHidePopupWindow:false,
|
|
displayMode:2,
|
|
coordinateType:1,
|
|
}
|
|
let params;
|
|
if(data instanceof Array){
|
|
params = data.map(item=>{
|
|
return Object.assign({},option,item)
|
|
})
|
|
}else{
|
|
params = Object.assign({},option,data)
|
|
}
|
|
await this.api.marker.add(params,fn);
|
|
}
|
|
|
|
public async addPolygon(data:PolygonOption | PolygonOption[],fn?:any){
|
|
const option = {
|
|
coordinateType:1,
|
|
}
|
|
let params;
|
|
if(data instanceof Array){
|
|
params = data.map(item=>{
|
|
return Object.assign({},option,item)
|
|
})
|
|
}else{
|
|
params = Object.assign({},option,data)
|
|
}
|
|
await this.api.polygon3d.add(params,fn);
|
|
}
|
|
// type:marker,polygon,polygon3d,marker3d等等
|
|
public remove(type:string,ids:string | string[],fn?){
|
|
this.api[type].delete(ids,fn)
|
|
}
|
|
public clearAll(type:string,fn?){
|
|
this.api[type].clear(fn)
|
|
}
|
|
public toggle(type:string,ids:string | string[],isShow:boolean,fn?){
|
|
if(isShow){
|
|
this.api[type].show(ids,fn)
|
|
}else{
|
|
this.api[type].hide(ids,fn)
|
|
}
|
|
}
|
|
public toggleAll(type:string,isShow:boolean,fn?){
|
|
if(isShow){
|
|
this.api[type].showAll(fn)
|
|
}else{
|
|
this.api[type].hideAll(fn)
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 投影坐标转经纬度坐标
|
|
* @param coordinates [x,y,z]- 世界坐标
|
|
* @param coordinateType - 经纬度坐标系类型0:世界 1:84 2:gcj02 3:bd09
|
|
* @param fn 完成后的回调
|
|
* @returns 经纬度 lon,lat]
|
|
*/
|
|
|
|
public async getLonLat(coordinates,coordinateType?,fn?){
|
|
if(!coordinateType){
|
|
// 1 84坐标系 2 GCJ02 3 BD09
|
|
coordinateType=1;
|
|
}
|
|
if(!coordinates[2]){
|
|
coordinates[2] = 0
|
|
}
|
|
const result = await this.api.coord.pcs2gcs(coordinates,coordinateType,fn)
|
|
if(result.resultMessage==="OK"){
|
|
return result.coordinates
|
|
}else{
|
|
return new Error(result.resultMessage)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 经纬度坐标转世界坐标
|
|
* @param coordinates [lon,lat]- 经纬度
|
|
* @param coordinateType - 经纬度坐标系类型 1:84 2:gcj02 3:bd09
|
|
* @param fn 完成后的回调
|
|
* @returns position [x,y,z]世界坐标
|
|
*/
|
|
|
|
public async getPosition(coordinates,coordinateType?,fn?){
|
|
if(!coordinateType){
|
|
// 1 84坐标系 2 GCJ02 3 BD09
|
|
coordinateType=1;
|
|
}
|
|
const result = await this.api.coord.gcs2pcs(coordinates,coordinateType)
|
|
if(result.resultMessage==="OK"){
|
|
return result.coordinates
|
|
}else{
|
|
return new Error(result.resultMessage)
|
|
}
|
|
}
|
|
/**
|
|
* 世界坐标转屏幕坐标
|
|
* @param position [x,y,z] - 世界坐标
|
|
* @param fn 完成后的回调
|
|
* @returns [x,y]屏幕坐标
|
|
*/
|
|
public getScreenPosition(position,fn?){
|
|
const result = this.api.coord.world2Screen(...position,fn);
|
|
if(result.resultMessage==="OK"){
|
|
return result.screenPosition
|
|
}else{
|
|
return new Error(result.resultMessage)
|
|
}
|
|
}
|
|
/**
|
|
* 屏幕坐标转世界坐标
|
|
* @param offest [x,y,] - 屏幕坐标
|
|
* @param fn 完成后的回调
|
|
* @returns [x,y,z]世界坐标
|
|
*/
|
|
public getPositionByOffset(offest,fn?){
|
|
const result = this.api.coord.world2Screen(...offest,fn);
|
|
if(result.resultMessage==="OK"){
|
|
return result.worldLocation
|
|
}else{
|
|
return new Error(result.resultMessage)
|
|
}
|
|
}
|
|
|
|
} |