tool3DLookAroundAnalysis.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. define(function () {
  2. /**
  3. * 状态值
  4. * @type {Boolean}
  5. * @default false
  6. * @private
  7. */
  8. var status = {
  9. initialized: false, //是否初始化
  10. };
  11. /**
  12. * 模块数据 用于数据存储和外部调用
  13. * @type {Object}
  14. * 数据存放
  15. */
  16. var modValue = {
  17. title: "环视分析",
  18. };
  19. /**
  20. * 3D 环视初始化
  21. */
  22. function init() {
  23. if (!status.initialized) {
  24. subscribe();
  25. status.initialized = true;
  26. map3DViewer.lookAroundAnalysis({
  27. action: "add",
  28. callback: callback
  29. })
  30. }
  31. ONEMAP.C.publisher.publish({
  32. modName: 'tool3DLookAroundAnalysis'
  33. }, 'tools:active');
  34. };
  35. /**
  36. * 注册监听事件
  37. */
  38. function subscribe() {
  39. ONEMAP.C.publisher.subscribe(remove, 'tools:active');
  40. ONEMAP.C.publisher.subscribe(clear, 'cleanMap');
  41. ONEMAP.C.publisher.subscribe(removeEvent, 'change23D');
  42. };
  43. // 23D转换
  44. function removeEvent() {
  45. map3DViewer.lookAroundAnalysis({
  46. action: "remove"
  47. })
  48. $('#toolLookAroundAnalysisPanel').remove();
  49. if ($(".tools-lookAroundAnalysis").hasClass('cur')) {
  50. $(".tools-lookAroundAnalysis").removeClass('cur');
  51. }
  52. }
  53. /**
  54. * 3D环视 加载/移除 注册事件
  55. */
  56. function remove(options) {
  57. if (options.modName != 'tool3DLookAroundAnalysis') {
  58. if (options.modName == 'cleanMap') {
  59. clear();
  60. }
  61. removeAndClear();
  62. $(".tools-lookAroundAnalysis").removeClass('cur');
  63. } else {
  64. if ($(".tools-lookAroundAnalysis").hasClass('cur')) {
  65. $(".tools-lookAroundAnalysis").removeClass('cur');
  66. removeAndClear();
  67. } else {
  68. $(".tools-lookAroundAnalysis").addClass('cur');
  69. addPopup();
  70. }
  71. }
  72. }
  73. /**
  74. * 移除 3D环视
  75. */
  76. function removeAndClear() {
  77. map3DViewer.lookAroundAnalysis({
  78. action: "stop"
  79. })
  80. $('#toolLookAroundAnalysisPanel').remove();
  81. };
  82. /**
  83. * 清除绘制 3D环视
  84. */
  85. function clear(params) {
  86. map3DViewer.lookAroundAnalysis({
  87. action: "remove"
  88. })
  89. }
  90. /**
  91. * 3D环视分析后的回调
  92. */
  93. function callback() {
  94. // 退出
  95. ONEMAP.C.publisher.publish({
  96. modName: 'tool3DLookAroundAnalysis'
  97. }, 'tools:active');
  98. }
  99. // 添加 弹窗
  100. function addPopup() {
  101. var html = '<div id="toolLookAroundAnalysisPanel" class="viewHeightPopup class3d">' +
  102. ' <iframe frameborder="0" class="cover-iframe"></iframe>' +
  103. ' <div class="cover-content">' +
  104. ' <div class="">' +
  105. ' <div class="popup-lt"></div>' +
  106. ' <div class="popup-lb"></div>' +
  107. ' <div class="popup-rt"></div>' +
  108. ' <div class="popup-rb"></div>' +
  109. ' <div class="popup-ct">' +
  110. ' <button type="button" class="close"></button>' +
  111. ' <h3>' + modValue.title + '</h3>' +
  112. ' </div>' +
  113. ' <div class="popup-cb">' +
  114. ' <div class="panel">' +
  115. ' <span>视高:</span>' +
  116. ' <input class="input" value="3" id="viewHeight" /><span>米</span>' +
  117. ' <button class="btn btn2 sure">确定</button>' +
  118. ' <button class="btn btn2 cancel">取消</button>' +
  119. ' </div>' +
  120. ' </div>' +
  121. ' </div>' +
  122. ' </div>' +
  123. '</div>';
  124. $("body").append(html);
  125. $("#toolLookAroundAnalysisPanel .popup-ct").dragmove($('#toolLookAroundAnalysisPanel'));
  126. $('#toolLookAroundAnalysisPanel .sure').click(function () {
  127. var number = $('#toolLookAroundAnalysisPanel #viewHeight').val();
  128. if (isNaN(Number(number))) {
  129. ONEMAP.C.publisher.publish({
  130. type: 'warning',
  131. message: '请输入正确的视高!'
  132. }, 'noteBar::add');
  133. return
  134. }
  135. map3DViewer.lookAroundAnalysis({
  136. action: "start",
  137. viewHeight: Number(number),
  138. angleInterval: 5
  139. })
  140. $('#toolLookAroundAnalysisPanel').remove();
  141. })
  142. $('#toolLookAroundAnalysisPanel .cancel,#toolLookAroundAnalysisPanel .close').click(function () {
  143. // 退出
  144. ONEMAP.C.publisher.publish({
  145. modName: 'tool3DLookAroundAnalysis'
  146. }, 'tools:active');
  147. })
  148. }
  149. return ONEMAP.M.tool3DLookAroundAnalysis = {
  150. init: init
  151. }
  152. })