ToolBox.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <transition
  3. appear
  4. name="animate__animated animate__move"
  5. enter-active-class="animate__flipInX"
  6. leave-active-class="animate__flipOutX"
  7. >
  8. <div class="widget-ToolBox" ref="widget-ToolBox">
  9. <div class="tool-list">
  10. <div
  11. class="list-item"
  12. v-for="item of toolList"
  13. :key="item.name"
  14. :title="item.name"
  15. v-show="isFold"
  16. @click="activeEvent(item.name)"
  17. >
  18. <img :src="item.imgUrl" />
  19. </div>
  20. <div class="list-item" :title="'工具栏'" @click="isFold = !isFold">
  21. <img :src="unfoldUrl" />
  22. </div>
  23. </div>
  24. <div class="roam-panel" v-show="isRoaming">
  25. <ViewManagement :show="isRoaming" />
  26. </div>
  27. </div>
  28. </transition>
  29. </template>
  30. <script lang="ts">
  31. import { Vue, Component, Prop, Watch } from 'vue-property-decorator'
  32. import ViewManagement from '@/views/groupPage/districtPageModules/customTools/viewManagement.vue'
  33. const Cesium = (window as any).Cesium
  34. const viewMemoryType = {
  35. none: 'none',
  36. pre: 'pre',
  37. after: 'after'
  38. } //记录视图
  39. //工具栏
  40. @Component({ name: 'ToolBox', components: { ViewManagement } })
  41. export default class ToolBox extends Vue {
  42. toolList: Array<any> = [
  43. { imgUrl: require('@/views/groupPage/images/工具栏/基础地图.png'), name: '基础地图' },
  44. { imgUrl: require('@/views/groupPage/images/工具栏/初始范围.png'), name: '初始范围' },
  45. { imgUrl: require('@/views/groupPage/images/工具栏/俯视.png'), name: '俯视' },
  46. { imgUrl: require('@/views/groupPage/images/工具栏/左视图.png'), name: '上一视图' },
  47. { imgUrl: require('@/views/groupPage/images/工具栏/右视图.png'), name: '下一视图' },
  48. { imgUrl: require('@/views/groupPage/images/工具栏/漫游.png'), name: '漫游' }
  49. // { imgUrl: require('@/views/groupPage/images/工具栏/图片.png'), name: '截图' },
  50. // { imgUrl: require('@/views/groupPage/images/工具栏/鹰眼.png'), name: '鹰眼' }
  51. ]
  52. unfoldUrl = require('@/views/groupPage/images/工具栏/展开.png')
  53. isFold: boolean = false
  54. isRoaming: boolean = false //漫游面板
  55. g_preViews = [] //前一视图
  56. g_afterViews = [] //后一视图
  57. g_viewType = viewMemoryType.none //前或后视图
  58. viewer
  59. get mapConfig() {
  60. return this.$store.state.bigScreen.mapConfig
  61. }
  62. get isInitViewer() {
  63. return this.$store.state.bigScreen.isInitViewer
  64. }
  65. @Watch('isInitViewer')
  66. onChangeMethod() {
  67. this.viewer = (window as any).viewer
  68. this.cameraMoveEvent()
  69. }
  70. mounted() {
  71. let target = this.$refs['widget-ToolBox'] as any
  72. target.style.setProperty('--right', '2.291667rem')
  73. }
  74. activeEvent(type) {
  75. var id = type
  76. switch (id) {
  77. case '初始范围':
  78. this.initPosition()
  79. break
  80. case '上一视图':
  81. this.preView()
  82. break
  83. case '下一视图':
  84. this.afterView()
  85. break
  86. case '俯视':
  87. this.lookDown()
  88. break
  89. case '漫游':
  90. this.roaming()
  91. break
  92. }
  93. }
  94. //初始位置
  95. initPosition() {
  96. // const degre = Cesium.Cartographic.fromCartesian(this.viewer.camera.position)
  97. // console.log({
  98. // lon: Cesium.Math.toDegrees(degre.longitude),
  99. // lat: Cesium.Math.toDegrees(degre.latitude),
  100. // height: degre.height
  101. // })
  102. const initPosition = this.mapConfig.initPosition
  103. const carto = Cesium.Cartographic.fromDegrees(
  104. parseFloat(initPosition.lon),
  105. parseFloat(initPosition.lat),
  106. parseFloat(initPosition.height)
  107. )
  108. let camera = Cesium.Cartographic.toCartesian(carto)
  109. if (!camera) return
  110. this.viewer.camera.setView({
  111. destination: new Cesium.Cartesian3(camera.x, camera.y, camera.z),
  112. orientation: {
  113. heading: 0,
  114. pitch: Cesium.Math.toRadians(-90),
  115. roll: 0
  116. }
  117. })
  118. }
  119. //前一视图
  120. preView() {
  121. if (!this.g_preViews || this.g_preViews.length === 0) {
  122. return
  123. }
  124. this.g_viewType = viewMemoryType.pre
  125. const camera = this.viewer.camera
  126. const pos = Cesium.Cartesian3.clone(camera.position)
  127. const heading = camera.heading
  128. const pitch = camera.pitch
  129. const roll = camera.roll
  130. const currentview = {
  131. destination: pos,
  132. orientation: {
  133. heading: heading,
  134. pitch: pitch,
  135. roll: roll
  136. }
  137. }
  138. const view = this.g_preViews[this.g_preViews.length - 1]
  139. this.g_preViews.pop()
  140. this.g_afterViews.push(currentview)
  141. this.viewer.camera.setView({
  142. destination: view.destination,
  143. orientation: view.orientation
  144. })
  145. }
  146. //后一视图
  147. afterView() {
  148. if (!this.g_afterViews || this.g_afterViews.length === 0) {
  149. return
  150. }
  151. this.g_viewType = viewMemoryType.after
  152. const camera = this.viewer.camera
  153. const pos = Cesium.Cartesian3.clone(camera.position)
  154. const heading = camera.heading
  155. const pitch = camera.pitch
  156. const roll = camera.roll
  157. const currentview = {
  158. destination: pos,
  159. orientation: {
  160. heading: heading,
  161. pitch: pitch,
  162. roll: roll
  163. }
  164. }
  165. const view = this.g_afterViews[this.g_afterViews.length - 1]
  166. this.g_afterViews.pop()
  167. this.g_preViews.push(currentview)
  168. this.viewer.camera.setView({
  169. destination: view.destination,
  170. orientation: view.orientation
  171. })
  172. }
  173. //地图视图移动事件
  174. cameraMoveEvent() {
  175. this.viewer.camera.moveStart.addEventListener((e) => {
  176. const camera = this.viewer.camera
  177. const pos = Cesium.Cartesian3.clone(camera.position)
  178. const heading = camera.heading
  179. const pitch = camera.pitch
  180. const roll = camera.roll
  181. const view = {
  182. destination: pos,
  183. orientation: {
  184. heading: heading,
  185. pitch: pitch,
  186. roll: roll
  187. }
  188. }
  189. if (this.g_viewType === viewMemoryType.none) {
  190. this.g_afterViews.length = 0
  191. this.g_afterViews = []
  192. if (this.g_preViews && this.g_preViews.length === 10) {
  193. this.g_preViews.shift()
  194. }
  195. this.g_preViews.push(view)
  196. } else if (this.g_viewType === viewMemoryType.pre) {
  197. if (this.g_afterViews && this.g_afterViews.length === 10) {
  198. this.g_afterViews.shift()
  199. }
  200. } else {
  201. if (this.g_preViews && this.g_preViews.length === 10) {
  202. this.g_preViews.shift()
  203. }
  204. }
  205. this.g_viewType = viewMemoryType.none
  206. })
  207. }
  208. //俯视
  209. lookDown() {
  210. const camera = this.viewer.camera
  211. camera.flyTo({
  212. destination: camera.position,
  213. orientation: {
  214. // 视角
  215. heading: 0,
  216. pitch: Cesium.Math.toRadians(-90),
  217. roll: camera.roll
  218. }
  219. })
  220. }
  221. //漫游面板操作
  222. roaming() {
  223. this.isRoaming = true
  224. }
  225. }
  226. </script>
  227. <style lang="scss" scoped>
  228. .animate__flipInX,
  229. .animate__flipOutX {
  230. animation-duration: 3s; //动画持续时间
  231. animation-delay: 0s; //动画延迟时间
  232. }
  233. .widget-ToolBox {
  234. $size10: 0.052083rem /* 10/192 */;
  235. $size20: 0.104167rem /* 20/192 */;
  236. z-index: 2;
  237. //position
  238. bottom: 0.052083rem /* 10/192 */;
  239. margin-right: var(--right); //2.291667rem /* 440/192 */;
  240. position: absolute;
  241. right: 0;
  242. //size
  243. //background
  244. color: #eee;
  245. //font
  246. font-family: Source Han Sans CN;
  247. .tool-list {
  248. display: flex;
  249. flex-flow: column;
  250. justify-content: center;
  251. align-items: flex-end;
  252. .list-item {
  253. width: 0.177083rem /* 34/192 */;
  254. height: 0.177083rem /* 34/192 */;
  255. background: rgba(7, 51, 84, 0.9);
  256. border-radius: 0.010417rem /* 2/192 */;
  257. margin: 0.026042rem /* 5/192 */;
  258. display: flex;
  259. justify-content: center;
  260. align-items: center;
  261. cursor: pointer;
  262. transition: width 0.3s;
  263. img {
  264. height: 0.09375rem /* 18/192 */;
  265. width: 0.09375rem /* 18/192 */;
  266. object-fit: contain; //保持原有尺寸比例。内容被缩放。
  267. }
  268. }
  269. .list-item:hover {
  270. width: 0.229167rem /* 44/192 */;
  271. background: rgba(7, 51, 84, 1);
  272. }
  273. }
  274. .roam-panel {
  275. position: absolute;
  276. width: 1.354167rem /* 260/192 */;
  277. height: 1.546875rem /* 297/192 */;
  278. border: 1px solid rgba(43, 174, 253, 0.34);
  279. background: rgba(43, 174, 253, 0.34);
  280. right: 0.416667rem /* 80/192 */;
  281. bottom: 0.026042rem /* 5/192 */;
  282. }
  283. }
  284. </style>