import Common from './Common.js' //处理cursor优先级 var CursorDeal = { priorityEvent : [//在前面的优先级高 { pen_delPoint: `url({Potree.resourcePath}/images/polygon_mark/pic_pen_sub.png),auto`}, { pen_addPoint: `url({Potree.resourcePath}/images/polygon_mark/pic_pen_add.png),auto`}, { pen: `url({Potree.resourcePath}/images/polygon_mark/pic_pen.png),auto`}, {'grabbing':'grabbing'},//通用 {'hoverGrab':'grab'},//通用 {'pointer':'pointer'},//通用 {'zoomInCloud':'zoom-in'}, {'hoverPano':'pointer'}, {"notAllowed-default":'not-allowed'}, {'connectPano':`url({Potree.resourcePath}/images/connect.png),auto`}, {'disconnectPano':`url({Potree.resourcePath}/images/connect-dis.png),auto`}, {'hoverLine':'pointer'}, {'hoverTranHandle':'grab'}, {"movePointcloud":'move'}, {"polygon_isIntersectSelf":'not-allowed'}, {"polygon_AtWrongPlace":'not-allowed'}, {'delPoint':'url("https://4dkk.4dage.com/v4-test/www/sdk/images/polygon_mark/pic_pen_sub.png"), auto'}, {"markerMove":'grab'}, {'addPoint':'url("https://4dkk.4dage.com/v4-test/www/sdk/images/polygon_mark/pic_pen_add.png"), auto'}, {'mapClipMove':'move'}, {'mapClipRotate':`url({Potree.resourcePath}/images/rotate-cursor.png),auto`}, {'rotatePointcloud':`url({Potree.resourcePath}/images/rotate-cursor.png),auto`}, {'siteModelFloorDrag':'row-resize'}, {'addSth':'cell'},//or crosshair ], list:[], //当前存在的cursor状态 currentCursorIndex:null, init : function(viewer, viewers){ this.priorityEvent.forEach(e=>{//刚开始Potree.resourcePath没值,现在换 for(let i in e){ e[i] = Common.replaceAll(e[i],'{Potree.resourcePath}',Potree.resourcePath) } }) this.domElements = viewers.map(e=>e.renderArea) viewer.addEventListener("CursorChange",(e)=>{ if(e.action == 'add'){ this.add(e.name) }else{ this.remove(e.name) } }) }, add : function(name){ var priorityItem = this.priorityEvent.find(e=>e[name]) if(!priorityItem){ console.error('CursorDeal 未定义优先级 name:'+ name); return } if(!this.list.includes(name)){ this.judge({addItem: priorityItem, name}) this.list.push(name) } }, remove : function(name){ var index = this.list.indexOf(name); if(index > -1){ this.list.splice(index, 1) this.judge() } }, judge:function(o={}){ //console.log(o,this.list) if(o.addItem){ var addIndex = this.priorityEvent.indexOf(o.addItem) if(addIndex < this.currentCursorIndex || this.currentCursorIndex == void 0){ this.domElements.forEach(e=>e.style.cursor = o.addItem[o.name] ) this.currentCursorIndex = addIndex } }else{ var levelMax = {index:Infinity, cursor:null } this.list.forEach(name=>{ var priorityItem = this.priorityEvent.find(e=>e[name]) var index = this.priorityEvent.indexOf(priorityItem) if(index < levelMax.index){ levelMax.index = index; levelMax.cursor = priorityItem[name] } }) this.currentCursorIndex = levelMax.index this.domElements.forEach(e=>e.style.cursor = levelMax.cursor || '') } } } export default CursorDeal;