CursorDeal.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import Common from './Common.js'
  2. //处理cursor优先级
  3. var CursorDeal = {
  4. priorityEvent : [//在前面的优先级高
  5. { pen_delPoint: `url({Potree.resourcePath}/images/polygon_mark/pic_pen_sub.png),auto`},
  6. { pen_addPoint: `url({Potree.resourcePath}/images/polygon_mark/pic_pen_add.png),auto`},
  7. { pen: `url({Potree.resourcePath}/images/polygon_mark/pic_pen.png),auto`},
  8. {'grabbing':'grabbing'},//通用
  9. {'hoverGrab':'grab'},//通用
  10. {'pointer':'pointer'},//通用
  11. {polygonMark_move:'move'},
  12. {polygonMark_hover: 'pointer'},
  13. {'zoomInCloud':'zoom-in'},
  14. {'hoverPano':'pointer'},
  15. {"notAllowed-default":'not-allowed'},
  16. {'connectPano':`url({Potree.resourcePath}/images/connect.png),auto`},
  17. {'disconnectPano':`url({Potree.resourcePath}/images/connect-dis.png),auto`},
  18. {'hoverLine':'pointer'},
  19. {'hoverTranHandle':'grab'},
  20. {"movePointcloud":'move'},
  21. {"polygon_isIntersectSelf":'not-allowed'},
  22. {"polygon_AtWrongPlace":'not-allowed'},
  23. {'delPoint':'url("https://4dkk.4dage.com/v4-test/www/sdk/images/polygon_mark/pic_pen_sub.png"), auto'},
  24. {"markerMove":'grab'},
  25. {'addPoint':'url("https://4dkk.4dage.com/v4-test/www/sdk/images/polygon_mark/pic_pen_add.png"), auto'},
  26. {'mapClipMove':'move'},
  27. {'mapClipRotate':`url({Potree.resourcePath}/images/rotate-cursor.png),auto`},
  28. {'rotatePointcloud':`url({Potree.resourcePath}/images/rotate-cursor.png),auto`},
  29. {'rotatePointcloud2':`url({Potree.resourcePath}/images/rotate-cursor.png),auto`},
  30. {'siteModelFloorDrag':'row-resize'},
  31. {'addSth':'cell'},//or crosshair
  32. ],
  33. list:[], //当前存在的cursor状态
  34. currentCursorIndex:null,
  35. init : function(viewer, viewers){
  36. this.priorityEvent.forEach(e=>{//刚开始Potree.resourcePath没值,现在换
  37. for(let i in e){
  38. e[i] = Common.replaceAll(e[i],'{Potree.resourcePath}',Potree.resourcePath)
  39. }
  40. })
  41. this.domElements = viewers.map(e=>e.renderArea)
  42. viewer.addEventListener("CursorChange",(e)=>{
  43. if(e.action == 'add'){
  44. this.add(e.name)
  45. }else{
  46. this.remove(e.name)
  47. }
  48. })
  49. },
  50. add : function(name){
  51. var priorityItem = this.priorityEvent.find(e=>e[name])
  52. if(!priorityItem){
  53. console.error('CursorDeal 未定义优先级 name:'+ name);
  54. return
  55. }
  56. if(!this.list.includes(name)){
  57. this.judge({addItem: priorityItem, name})
  58. this.list.push(name)
  59. }
  60. },
  61. remove : function(name){
  62. var index = this.list.indexOf(name);
  63. if(index > -1){
  64. this.list.splice(index, 1)
  65. this.judge()
  66. }
  67. },
  68. judge:function(o={}){
  69. //console.log(o,this.list)
  70. if(o.addItem){
  71. var addIndex = this.priorityEvent.indexOf(o.addItem)
  72. if(addIndex < this.currentCursorIndex || this.currentCursorIndex == void 0){
  73. this.domElements.forEach(e=>e.style.cursor = o.addItem[o.name] )
  74. this.currentCursorIndex = addIndex
  75. }
  76. }else{
  77. var levelMax = {index:Infinity, cursor:null }
  78. this.list.forEach(name=>{
  79. var priorityItem = this.priorityEvent.find(e=>e[name])
  80. var index = this.priorityEvent.indexOf(priorityItem)
  81. if(index < levelMax.index){
  82. levelMax.index = index;
  83. levelMax.cursor = priorityItem[name]
  84. }
  85. })
  86. this.currentCursorIndex = levelMax.index
  87. this.domElements.forEach(e=>e.style.cursor = levelMax.cursor || '')
  88. }
  89. }
  90. }
  91. export default CursorDeal;