olRender.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {
  2. olMapConfig
  3. } from '../../static/mapConfig.js';
  4. import olMapClass from './olMap.js';
  5. export const olRenderJs = {
  6. name: "openlayer-map",
  7. data() {
  8. return {
  9. tdtLayersSl: [],
  10. tdtLayersYx: [],
  11. gwLayers: [],
  12. pipeInfo: null,
  13. jzLayers: [],
  14. siteLayers: [],
  15. mapObj: null,
  16. userLocVisible: true
  17. };
  18. },
  19. mounted() {
  20. this.mapObj = new olMapClass()
  21. this.initOlMap()
  22. },
  23. methods: {
  24. initOlMap() {
  25. this.$ownerInstance.callMethod('methodForRenderJs', {
  26. type: 'startInitMap'
  27. });
  28. console.log('初始化ol地图')
  29. // 等待dom容器,否则挂不上
  30. setTimeout(() => {
  31. this.mapObj.initOlMap('ol-map-view', olMapConfig.center, olMapConfig.zoom)
  32. olMapConfig.layerTdt.sl.forEach((tdtUrl, index) => {
  33. this.mapObj.addMapLayers('base', `sl${index}`, 'tdt', tdtUrl, true)
  34. this.tdtLayersSl.push(`sl${index}`)
  35. })
  36. olMapConfig.layerTdt.yx.forEach((tdtUrl, index) => {
  37. this.mapObj.addMapLayers('base', `yx${index}`, 'tdt', tdtUrl, false)
  38. this.tdtLayersYx.push(`yx${index}`)
  39. })
  40. // 添加用户位置标签
  41. let userMarker = [{
  42. longitude: "104.06",
  43. latitude: "30.67",
  44. name: "用户位置标签",
  45. id: "user-loc-marker",
  46. }]
  47. let icon = {
  48. anchor: [0.5, 1],
  49. src: './static/images/components/mapSearch/user-loc.png'
  50. }
  51. this.mapObj.addVectorLayers('userLoc', 'userLoc', this.userLocVisible, userMarker, true, icon, null)
  52. // 添加弹窗
  53. this.mapObj.addPopUp('gwPop', 'ol-popup-box', false)
  54. this.mapObj.initOlMapEvent('singleclick', async (event) => {
  55. console.log(event)
  56. })
  57. this.$ownerInstance.callMethod('methodForRenderJs', {
  58. type: 'initMap'
  59. });
  60. }, 3000)
  61. }
  62. }
  63. }