label.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. class Label2D extends THREE.EventDispatcher {
  2. constructor(o = {}) {
  3. super()
  4. this.title = o.title
  5. this.position = o.position
  6. console.log(o);
  7. this.elem = $(`<div class="room-label ${o.labeltype ? o.labeltype : ''} ${o.posi == 'right' ? 'right' : ''}" >
  8. <a><p>
  9. <span>${o.title}</span>
  10. ${o.labeltype ? `
  11. <div class="sline"></div>
  12. <span class="enspan">${o.entitle}</span>` : ''}
  13. </p></a>
  14. ${o.labeltype ? `<div class="picdetail">
  15. <div class="header">
  16. <span>岁寒三友</span>
  17. <img src="images/video.png" alt="">
  18. </div>
  19. <div class="pinfo">
  20. <img src="images/temp.jpg" alt="">
  21. <p>南宋赵孟坚经历丧国的痛楚,把松竹梅在一起创作出《岁寒三友图》,借用“岁寒三友”来比喻自己为身处乱世不变其节的忠贞之士。</p>
  22. </div>
  23. </div>`: ''}
  24. </div>`);
  25. $(".widgets-doll-labels").append(this.elem)
  26. this.pos2d = new THREE.Vector3
  27. this.elem.css({ position: 'absolute', 'z-index': 999 })
  28. this.clickFun = o.clickFun;
  29. this.clickFun && this.elem.on('click', this.clickFun.bind(this))
  30. {
  31. let update = (e) => {
  32. this.update()
  33. }
  34. viewer.addEventListener("view.changed", update) //确保player存在
  35. this.addEventListener('dispose', (e) => { })
  36. }
  37. this.visible = true
  38. this.shelterByModel = o.shelterByModel
  39. this.update()
  40. }
  41. update() {
  42. if (!this.position || !this.visible) return
  43. var p = convertTool.getPos2d(this.position, viewer.camera, $("#player")[0]);
  44. if (!p || !p.trueSide) {
  45. this.elem.css('display', 'none'); return;
  46. }
  47. //判断label是否被模型遮挡,遮挡则消失(如果是漫游模式最好提前计算visiblePanos)
  48. if (this.shelterByModel && convertTool.ifShelter(this.position, p.vector, viewer.camera, viewer.model.children, 0.05)) {
  49. this.elem.css('display', 'none'); return;
  50. }
  51. this.elem.css({
  52. left: p.pos.x + 'px',
  53. top: p.pos.y + 'px'
  54. })
  55. /* if(settings.vrEnabled){
  56. this.elem.css({transform:'rotate('+window.screenFaceOrient+'deg)'})
  57. }else{
  58. this.elem.css({transform:''})
  59. } */
  60. this.elem.css('display', 'block');
  61. this.pos2d = p.vector;
  62. }
  63. setVisible(visi, reason, level = 0, type) {
  64. convertTool.updateVisible(this, reason, visi, level, type)
  65. if (!this.visible) {
  66. this.elem.css('display', 'none');
  67. } else {
  68. this.update()
  69. }
  70. }
  71. setTitle(title) {
  72. this.title = title || ''
  73. this.elem.html(`<a><p><span>${this.title}</span></p></a>`)
  74. }
  75. setPos(pos) {
  76. this.position = pos;
  77. this.update()
  78. }
  79. dispose() {
  80. this.elem.remove();
  81. this._listeners = {}
  82. this.dispatchEvent({ type: 'dispose' })
  83. }
  84. }