index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div>
  3. <div class="tools-container" :class="{hide:rightPanelHide}">
  4. <img src="@/assets/image/common/tools.png" alt="" @click="toOpenTools" />
  5. <div class="tools-menu" :class="{ isHide: !toolsShow }">
  6. <div class="tool" @click="toChangeMap" :class="{ active: isMapActive }"><i class="iconfont icon-tongyong-gongjuxiang-ditukongzhi" style="font-size: 34px"></i></div>
  7. <div class="tool" :class="{ active: isClActive }" @click="toCl"><i class="iconfont icon-icon_xiaogongju_20_s" style="font-size: 18px"></i></div>
  8. </div>
  9. <div class="measuring-tool" :class="{ clToolHide: !measureShow }">
  10. <div class="ranging" :class="{ active: rangingActive }" @click="measureRanging">测距</div>
  11. <div class="measureArea" :class="{ active: measureActive }" @click="measureArea">测面</div>
  12. </div>
  13. </div>
  14. <Controls v-if="isMapActive" />
  15. </div>
  16. </template>
  17. <script>
  18. import Controls from './controls/control.vue'
  19. export default {
  20. name: 'MapTools',
  21. data() {
  22. return {
  23. toolsShow: false,
  24. isMapActive: false,
  25. measureActive: false,
  26. rangingActive: false,
  27. isClActive: false,
  28. measureShow: false,
  29. rightPanelHide:false,
  30. distanceMeasure: null, // 测距工具实例
  31. isMeasuring: false, // 是否正在测量
  32. measureResult: '' // 测量结果
  33. }
  34. },
  35. components: {
  36. Controls
  37. },
  38. mounted() {
  39. this.$globalEventBus.$on('loadMap', () => {
  40. console.info('我加入')
  41. this.distanceMeasure = new this.mars3d.thing.Measure({
  42. label: {
  43. color: '#ffffff',
  44. font_family: '楷体',
  45. font_size: 20,
  46. background: false
  47. },
  48. isAutoEditing: false
  49. })
  50. // 将测距工具添加到地图
  51. window.map.addThing(this.distanceMeasure)
  52. })
  53. this.$globalEventBus.$on('toggleRightPanel',(val)=>{
  54. this.rightPanelHide = val
  55. })
  56. },
  57. methods: {
  58. toOpenTools() {
  59. this.toolsShow = !this.toolsShow
  60. },
  61. toChangeMap() {
  62. this.isMapActive = !this.isMapActive
  63. },
  64. toCl() {
  65. this.isClActive = !this.isClActive
  66. this.measureShow = this.isClActive ? true : false
  67. if (this.distanceMeasure) {
  68. this.distanceMeasure.clear()
  69. }
  70. },
  71. measureRanging() {
  72. this.rangingActive = !this.rangingActive
  73. if (this.rangingActive) {
  74. this.measureActive = false
  75. const graphic = this.distanceMeasure.distance({
  76. style: {
  77. color: '#4487D7',
  78. width: 20,
  79. clampToGround: false //是否贴地
  80. },
  81. showAddText: true,
  82. label: {
  83. // 自定义显示label的graphic类型
  84. type: 'div',
  85. color: '#ffffff',
  86. updateText: function (text, graphic) {
  87. graphic.html = `<div class="marsGreenGradientPnl" >${text}</div>`
  88. },
  89. // 下面是graphic对应类型本身的参数
  90. html: `<div class="marsGreenGradientPnl" ></div>`,
  91. horizontalOrigin: this.Cesium.HorizontalOrigin.CENTER,
  92. verticalOrigin: this.Cesium.VerticalOrigin.BOTTOM
  93. }
  94. })
  95. } else {
  96. this.distanceMeasure.clear()
  97. }
  98. },
  99. measureArea() {
  100. this.measureActive = !this.measureActive
  101. if (this.measureActive) {
  102. this.rangingActive = false
  103. const graphic = this.distanceMeasure.area({
  104. style: {
  105. color: '#4F9FFF',
  106. fill: true,
  107. materialType:"Color",
  108. fillColor: 'rgba(73,142,227,0.2)',
  109. outline:true,
  110. outlineColor: '#4F9FFF',
  111. outlineWidth: 10,
  112. clampToGround: false //贴地
  113. }
  114. })
  115. // 下面代码抬升面的高度到一个平面,来示意“水平”
  116. if (window.map.scene.mode === this.Cesium.SceneMode.SCENE3D) {
  117. const oldPositions = graphic.positionsShow
  118. const rang = this.mars3d.PolyUtil.getHeightRangeByDepth(oldPositions, window.map.scene)
  119. graphic.positions = this.mars3d.PointUtil.setPositionsHeight(oldPositions, rang.maxHeight)
  120. }
  121. } else {
  122. this.distanceMeasure.clear()
  123. }
  124. }
  125. },
  126. destroyed() {
  127. this.$globalEventBus.$off('loadMap')
  128. this.$globalEventBus.$off('toggleRightPanel')
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .tools-container {
  134. position: absolute;
  135. top: px-to-rem(45);
  136. right: 4.2rem;
  137. z-index: 41;
  138. img {
  139. width: px-to-rem(40);
  140. height: px-to-rem(40);
  141. }
  142. .tools-menu {
  143. background: #172536;
  144. border-radius: px-to-rem(4);
  145. padding-bottom: px-to-rem(10);
  146. width: px-to-rem(40);
  147. .tool {
  148. text-align: center;
  149. color: #fff;
  150. }
  151. .tool.active {
  152. color: #4f9fff;
  153. }
  154. }
  155. .measuring-tool {
  156. position: absolute;
  157. top: px-to-rem(95);
  158. right: px-to-rem(43);
  159. background-color: rgba(23, 37, 55, 0.9);
  160. border-radius: px-to-rem(8);
  161. color: #fff;
  162. cursor: pointer;
  163. width: px-to-rem(50);
  164. div {
  165. padding: px-to-rem(10);
  166. }
  167. .ranging.active,
  168. .measureArea.active {
  169. background: rgba(79, 159, 255, 0.4);
  170. color: #4f9fff;
  171. }
  172. }
  173. .isHide,
  174. .clToolHide {
  175. display: none;
  176. }
  177. }
  178. .hide{
  179. right: px-to-rem(30);
  180. }
  181. </style>