Blame view

src/components/inspection/inspectionTaskMap.vue 4.06 KB
59fd5759   王彪总   feat(map): 替换腾讯地图...
1
  <template>
48ea9c43   wuxw   巡检开发完成
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    <div class="inspection-task-map-container">
      <div id="inspectionTaskMap" style="width: 100%; height: 600px;"></div>
    </div>
  </template>
  
  <script>
  import { queryInspectionTaskDetail } from '@/api/inspection/inspectionPointApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'InspectionTaskMap',
    data() {
      return {
        map: null,
        communityId: '',
        taskPoints: [],
59fd5759   王彪总   feat(map): 替换腾讯地图...
18
19
20
        markers: [],
        texts: [],
        polylines: []
48ea9c43   wuxw   巡检开发完成
21
22
23
24
      }
    },
    mounted() {
      this.communityId = getCommunityId()
48ea9c43   wuxw   巡检开发完成
25
26
27
    },
    methods: {
      loadData(task) {
59fd5759   王彪总   feat(map): 替换腾讯地图...
28
        console.log('loadData', task)
48ea9c43   wuxw   巡检开发完成
29
30
31
32
        this.initMap()
        this.loadTask(task)
      },
      initMap() {
59fd5759   王彪总   feat(map): 替换腾讯地图...
33
        this.clearAll()
57c370b2   wuxw   v1.9 优化巡检地图展示问题
34
  
59fd5759   王彪总   feat(map): 替换腾讯地图...
35
36
37
        const center = [116.397128, 39.916527]
        const container = document.getElementById('inspectionTaskMap')
        if (!container) return
48ea9c43   wuxw   巡检开发完成
38
  
59fd5759   王彪总   feat(map): 替换腾讯地图...
39
        this.map = new window.AMap.Map(container, {
48ea9c43   wuxw   巡检开发完成
40
41
          center: center,
          zoom: 13,
59fd5759   王彪总   feat(map): 替换腾讯地图...
42
          resizeEnable: true
48ea9c43   wuxw   巡检开发完成
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
        })
      },
  
      async loadTask(task) {
        if (!task || !task.taskId) return
  
        try {
          const params = {
            communityId: this.communityId,
            taskId: task.taskId,
            page: 1,
            row: 1000
          }
  
          const response = await queryInspectionTaskDetail(params)
          this.taskPoints = response.data
          this.addPointsToMap(this.taskPoints)
        } catch (error) {
          console.error('获取任务点失败:', error)
          this.$message.error(this.$t('inspectionTaskMap.fetchError'))
        }
      },
  
      addPointsToMap(points) {
        if (!this.map || !points || points.length === 0) return
  
59fd5759   王彪总   feat(map): 替换腾讯地图...
69
        this.clearOverlays()
48ea9c43   wuxw   巡检开发完成
70
  
48ea9c43   wuxw   巡检开发完成
71
72
73
74
75
        const path = []
  
        points.forEach(point => {
          if (!point.lat || !point.lng) return
  
59fd5759   王彪总   feat(map): 替换腾讯地图...
76
77
          const position = [point.lng, point.lat]
          const isDone = point.state === '20200405'
48ea9c43   wuxw   巡检开发完成
78
  
59fd5759   王彪总   feat(map): 替换腾讯地图...
79
80
81
82
83
84
85
86
87
88
          // 标记
          const markerIcon = new window.AMap.Icon({
            size: new window.AMap.Size(25, 35),
            imageSize: new window.AMap.Size(25, 35),
            image: isDone ? '/img/inspection_do.png' : '/img/inspection.png'
          })
          const marker = new window.AMap.Marker({
            map: this.map,
            position: position,
            icon: markerIcon
48ea9c43   wuxw   巡检开发完成
89
          })
59fd5759   王彪总   feat(map): 替换腾讯地图...
90
          this.markers.push(marker)
48ea9c43   wuxw   巡检开发完成
91
  
59fd5759   王彪总   feat(map): 替换腾讯地图...
92
93
94
95
          // 标签
          const text = new window.AMap.Text({
            map: this.map,
            text: point.inspectionName,
48ea9c43   wuxw   巡检开发完成
96
            position: position,
59fd5759   王彪总   feat(map): 替换腾讯地图...
97
98
99
100
101
102
103
104
            offset: new window.AMap.Pixel(0, 15),
            style: {
              color: isDone ? '#CC0000' : '#3777FF',
              'font-size': '12px',
              'background-color': 'rgba(255,255,255,0.8)',
              'padding': '2px 4px',
              'border-radius': '2px'
            }
48ea9c43   wuxw   巡检开发完成
105
          })
59fd5759   王彪总   feat(map): 替换腾讯地图...
106
          this.texts.push(text)
48ea9c43   wuxw   巡检开发完成
107
  
48ea9c43   wuxw   巡检开发完成
108
109
110
          path.push(position)
        })
  
59fd5759   王彪总   feat(map): 替换腾讯地图...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
        // 路径 - 双色双层折线模拟描边效果
        if (path.length > 1) {
          // 外层(描边)
          const outerPolyline = new window.AMap.Polyline({
            map: this.map,
            path: path,
            strokeColor: '#FFF',
            strokeWeight: 10,
            strokeOpacity: 1,
            lineJoin: 'round'
          })
          this.polylines.push(outerPolyline)
  
          // 内层(主线)
          const innerPolyline = new window.AMap.Polyline({
            map: this.map,
            path: path,
            strokeColor: '#3777FF',
            strokeWeight: 6,
            strokeOpacity: 0.9,
            lineJoin: 'round'
          })
          this.polylines.push(innerPolyline)
        }
48ea9c43   wuxw   巡检开发完成
135
  
48ea9c43   wuxw   巡检开发完成
136
137
138
139
        if (path.length > 0) {
          this.map.setCenter(path[0])
          this.map.setZoom(16)
        }
59fd5759   王彪总   feat(map): 替换腾讯地图...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
      },
  
      clearAll() {
        this.clearOverlays()
        if (this.map) {
          this.map.destroy()
          this.map = null
        }
      },
  
      clearOverlays() {
        this.markers.forEach(m => m.setMap(null))
        this.markers = []
        this.texts.forEach(t => t.setMap(null))
        this.texts = []
        this.polylines.forEach(p => p.setMap(null))
        this.polylines = []
48ea9c43   wuxw   巡检开发完成
157
158
159
      }
    },
    beforeDestroy() {
59fd5759   王彪总   feat(map): 替换腾讯地图...
160
      this.clearAll()
48ea9c43   wuxw   巡检开发完成
161
162
163
164
165
166
167
168
169
    }
  }
  </script>
  
  <style scoped>
  .inspection-task-map-container {
    width: 100%;
    height: 100%;
  }
59fd5759   王彪总   feat(map): 替换腾讯地图...
170
  </style>