飞天云平台-国产化
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.

201 lines
5.7 KiB

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