飞天云平台-国产化
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
4.7 KiB

2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
  1. <template>
  2. <div style="position: relative; width: 100%; height: 680px; ">
  3. <div id="fengmap" />
  4. <div class="rightMask" />
  5. </div>
  6. </template>
  7. <script>
  8. import fengmap from '@/assets/fengmap/fengmap.map.min'
  9. import { FMControlPosition, FMToolbar, FMScaleBar } from '@/assets/fengmap/fengmap.plugin.ui.min.js'
  10. export default {
  11. name: 'FengMap',
  12. props: {
  13. mapData: {
  14. type: Object,
  15. require: true,
  16. default: function() {
  17. return {}
  18. }
  19. }
  20. },
  21. data() {
  22. return {
  23. map: null,
  24. level: null,
  25. levelName: null,
  26. levels: null,
  27. marker: null,
  28. scrollFloorControl: null,
  29. scaleBar: null
  30. }
  31. },
  32. watch: {
  33. mapData: {
  34. handler(newVal, oldVal) {
  35. if (!newVal) {
  36. console.log('newVal-null')
  37. return
  38. }
  39. },
  40. deep: true
  41. }
  42. },
  43. mounted() {
  44. console.log('mapData', this.mapData)
  45. },
  46. methods: {
  47. dispose() {
  48. if (this.scrollFloorControl) {
  49. this.scrollFloorControl.remove()
  50. }
  51. if (this.map) {
  52. this.map.dispose()
  53. this.map = null
  54. }
  55. },
  56. initMap() {
  57. window.vueInstance = null
  58. try {
  59. console.log('this.level', this.level)
  60. console.log('开始初始化地图')
  61. const options = {
  62. container: document.getElementById('fengmap'),
  63. appName: this.mapData && this.mapData.appName,
  64. key: this.mapData && this.mapData.mapKey,
  65. mapID: this.mapData && this.mapData.appId,
  66. // mapURL: '/fengmap/data/',
  67. // themeID: '1574346301450625025',
  68. // themeURL: '/fengmap/data/theme/',
  69. level: this.level,
  70. mapZoom: 19.5,
  71. backgroundColor: '#fff'
  72. }
  73. console.log('地图配置:', options)
  74. this.map = new fengmap.FMMap(options)
  75. console.log('地图实例已创建')
  76. // this.map.on('loadingProcess', (event) => {
  77. // console.log('加载进度:', event.progress)
  78. // this.debugInfo = `加载进度: ${event.progress}%`
  79. // })
  80. this.map.on('loaded', () => {
  81. console.log('地图加载完成')
  82. this.map.setViewMode(fengmap.FMViewMode.MODE_3D)
  83. // 楼层控件
  84. const scrollFloorCtlOpt = {
  85. position: FMControlPosition.RIGHT_TOP,
  86. floorButtonCount: 5,
  87. offset: {
  88. x: -20,
  89. y: 150
  90. },
  91. viewModeControl: true,
  92. floorModeControl: true,
  93. needAllLayerBtn: true
  94. }
  95. this.scrollFloorControl = new FMToolbar(scrollFloorCtlOpt)
  96. this.scrollFloorControl.addTo(this.map)
  97. // 比例尺控件
  98. const scrollScaleBarCtlOpt = {
  99. fontSize: 18,
  100. height: 30,
  101. position: FMControlPosition.LEFT_BOTTOM,
  102. offset: {
  103. x: 20,
  104. y: -20
  105. }
  106. }
  107. this.scaleBar = new FMScaleBar(scrollScaleBarCtlOpt)
  108. this.scaleBar.addTo(this.map)
  109. window.vueInstance = this
  110. console.log('Vue实例已全局挂载:', window.vueInstance)
  111. }, { passive: true })
  112. this.map.on('click', (e) => {
  113. this.marker && this.marker.remove()
  114. this.marker = null
  115. }, { passive: true })
  116. this.map.on('mapInitError', (err) => {
  117. console.error('地图初始化错误:', err)
  118. this.debugInfo = `地图初始化错误: ${err.message}`
  119. })
  120. this.map.on('levelChanged', function(event) {
  121. console.log('levelChanged:', event)
  122. console.log('当前楼层:', event.level)
  123. console.log('楼层name2', window.vueInstance.map.getFloor(event.level).name)
  124. })
  125. } catch (error) {
  126. console.error('初始化地图失败:', error)
  127. this.debugInfo = `初始化失败: ${error.message}`
  128. }
  129. },
  130. getCurrentLevel() {
  131. this.level = this.map.getLevel()
  132. this.levelName = this.map.getFloor(this.level).name
  133. // floorID level name
  134. console.log('楼层info', this.map.getFloor(this.level))
  135. console.log('楼层name1', this.map.getFloor(this.level).name)
  136. // 所有
  137. console.log('getFloorInfos', this.map.getFloorInfos())
  138. window.vueInstance.$emit('refreshLevel', this.level, this.levelName)
  139. }
  140. }
  141. }
  142. </script>
  143. <style scoped lang="scss">
  144. @import "~@/assets/fengmap/toolBarStyle.css";
  145. #fengmap {
  146. position: absolute;
  147. top: 0;
  148. left: 0;
  149. width: 100%;
  150. height: 100%;
  151. background: #f5f5f5;
  152. }
  153. .rightMask{
  154. width: 162px;
  155. height: 42px;
  156. position: absolute;
  157. bottom: 0;
  158. right: 0;
  159. background: #fff;
  160. }
  161. </style>