Commit 0ad040a4b62e9ec4b87e89baa5560f875cdc9cd2
1 parent
540a0ebf
feat(src/packages): 图表地图 高德地图新增标注物点击弹窗
Showing
6 changed files
with
56 additions
and
52 deletions
... | ... | @@ -5,6 +5,12 @@ import { chartInitConfig } from '@/settings/designSetting' |
5 | 5 | import cloneDeep from 'lodash/cloneDeep' |
6 | 6 | import dataJson from './data.json' |
7 | 7 | |
8 | +export type dataExtraInfoType = typeof dataJson.markers[number]['extraInfo'] //data.json下的extraInfo类型 | |
9 | + | |
10 | +export type dataJsonType = typeof dataJson //data.json类型 | |
11 | + | |
12 | +export type dataJsonMarkersType = typeof dataJson.markers[number] //data.json markers类型 | |
13 | + | |
8 | 14 | export enum ThemeEnum { |
9 | 15 | NORMAL = 'normal', |
10 | 16 | DARK = 'dark', | ... | ... |
1 | 1 | { |
2 | 2 | "markers": [ |
3 | 3 | { |
4 | - "name": "x", | |
4 | + "name": "模拟1", | |
5 | 5 | "value": 20, |
6 | 6 | "position": [103.856504, 30.687278], |
7 | 7 | "extraInfo": { |
8 | - "tbDeviceId": "xxxxxxxxxxx", | |
9 | - "name": "xx", | |
10 | - "alias": "xx", | |
8 | + "tbDeviceId": "@xxxxxxxxxxx", | |
9 | + "name": "模拟1", | |
10 | + "alias": "模拟1", | |
11 | 11 | "organizationDTO": { |
12 | - "name": "xx" | |
12 | + "name": "模拟1" | |
13 | 13 | }, |
14 | 14 | "deviceState": "INACTIVE", |
15 | 15 | "deviceProfile": { |
... | ... | @@ -23,15 +23,15 @@ |
23 | 23 | } |
24 | 24 | }, |
25 | 25 | { |
26 | - "name": "xx", | |
26 | + "name": "模拟2", | |
27 | 27 | "value": 30, |
28 | 28 | "position": [104.095368, 30.716787], |
29 | 29 | "extraInfo": { |
30 | - "tbDeviceId": "xxxxxxxxxxxxxxx", | |
31 | - "name": "xxx", | |
32 | - "alias": "xx", | |
30 | + "tbDeviceId": "@xxxxxxxxxxxxxxx", | |
31 | + "name": "模拟2", | |
32 | + "alias": "模拟2", | |
33 | 33 | "organizationDTO": { |
34 | - "name": "xx" | |
34 | + "name": "模拟2" | |
35 | 35 | }, |
36 | 36 | "deviceState": "INACTIVE", |
37 | 37 | "deviceProfile": { | ... | ... |
src/packages/components/external/Charts/Maps/OverrideMapAmap/images/djx.png
deleted
100644 → 0
1.3 KB
src/packages/components/external/Charts/Maps/OverrideMapAmap/images/online.png
renamed from
src/packages/components/external/Charts/Maps/OverrideMapAmap/images/online1.png
514 Bytes
src/packages/components/external/Charts/Maps/OverrideMapAmap/images/zx.png
deleted
100644 → 0
1.35 KB
... | ... | @@ -8,10 +8,10 @@ import AMapLoader from '@amap/amap-jsapi-loader' |
8 | 8 | import { CreateComponentType } from '@/packages/index.d' |
9 | 9 | import { useChartDataFetch } from '@/hooks' |
10 | 10 | import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' |
11 | -import { MarkerEnum, ThemeEnum } from './config' | |
11 | +import { MarkerEnum, ThemeEnum, dataExtraInfoType, dataJsonType, dataJsonMarkersType } from './config' | |
12 | 12 | import { isArray } from '@/utils' |
13 | 13 | import djh from './images/djh.png' |
14 | -import online from './images/online1.png' | |
14 | +import online from './images/online.png' | |
15 | 15 | import lx1 from './images/lx1.png' |
16 | 16 | import { getDeviceActiveTime } from '@/api/external/common/index' |
17 | 17 | import dayjs from 'dayjs' |
... | ... | @@ -39,6 +39,7 @@ let { |
39 | 39 | marker |
40 | 40 | } = toRefs(props.chartConfig.option.mapOptions) |
41 | 41 | |
42 | +//官方没有高德地图api的ts,所以类型全用的any | |
42 | 43 | let mapIns: any = null |
43 | 44 | let markers: any = [] |
44 | 45 | let AMapIns: any = null |
... | ... | @@ -64,7 +65,7 @@ const initMap = (newData: any) => { |
64 | 65 | viewMode: viewMode.value, // 地图模式 |
65 | 66 | willReadFrequently: true |
66 | 67 | }) |
67 | - dataHandle(props.chartConfig.option.dataset) | |
68 | + dataHandle(props.chartConfig.option.dataset) //处理地图标点 | |
68 | 69 | let satellite = new AMap.TileLayer.Satellite() |
69 | 70 | let roadNet = new AMap.TileLayer.RoadNet() |
70 | 71 | if (newData.amapStyleKey === ThemeEnum.WEIXIN) { |
... | ... | @@ -85,12 +86,14 @@ const initMap = (newData: any) => { |
85 | 86 | }) |
86 | 87 | } |
87 | 88 | |
88 | -const createInfoWindow = async (extraInfo: any) => { | |
89 | +//创建信息弹窗 | |
90 | +const createInfoWindow = async (extraInfo: dataExtraInfoType) => { | |
89 | 91 | try { |
90 | 92 | const { name, alias, organizationDTO, deviceState, deviceProfile, deviceInfo, tbDeviceId } = extraInfo |
91 | - const res = await getDeviceActiveTime(tbDeviceId) | |
93 | + if (tbDeviceId.startsWith('@')) return //假的模拟数据则终止 | |
94 | + const res = await getDeviceActiveTime(tbDeviceId) //查询设备最后离线时间 | |
92 | 95 | let { lastUpdateTs } = res[0] |
93 | - lastUpdateTs = dayjs(lastUpdateTs).format('YYYY-MM-DD HH:mm:ss') | |
96 | + const lastUpdateFormatTs = dayjs(lastUpdateTs).format('YYYY-MM-DD HH:mm:ss') | |
94 | 97 | return ` |
95 | 98 | <div style="width:15vw;height:18vh;background-color:white;"> |
96 | 99 | <div style="margin:0px 10px"> |
... | ... | @@ -111,7 +114,9 @@ const createInfoWindow = async (extraInfo: any) => { |
111 | 114 | 设备位置:${!deviceInfo.address ? '该设备暂无地理位置' : deviceInfo.address} |
112 | 115 | </div> |
113 | 116 | <div style="margin-top:6px;"> |
114 | - ${deviceState === 'ONLINE' ? '在线' : deviceState === 'INACTIVE' ? '创建' : '离线'}时间:${lastUpdateTs} | |
117 | + ${ | |
118 | + deviceState === 'ONLINE' ? '在线' : deviceState === 'INACTIVE' ? '创建' : '离线' | |
119 | + }时间:${lastUpdateFormatTs} | |
115 | 120 | </div> |
116 | 121 | </div> |
117 | 122 | </div> |
... | ... | @@ -121,7 +126,26 @@ const createInfoWindow = async (extraInfo: any) => { |
121 | 126 | } |
122 | 127 | } |
123 | 128 | |
124 | -const dataHandle = (newData: any) => { | |
129 | +//地图点击 | |
130 | +const mapClick = (markerInstance: any, markerItem: dataJsonMarkersType) => { | |
131 | + markerInstance.setExtData({ | |
132 | + extraInfo: markerItem.extraInfo | |
133 | + }) | |
134 | + mapIns.add(markerInstance) | |
135 | + markerInstance.setLabel({ | |
136 | + content: markerItem.extraInfo.alias || markerItem.extraInfo.name | |
137 | + }) | |
138 | + markerInstance.on('click', async (e: any) => { | |
139 | + const { extraInfo } = e.target.getExtData() | |
140 | + let infoWindow = new AMapIns.InfoWindow({ | |
141 | + content: await createInfoWindow(extraInfo), | |
142 | + offset: new AMapIns.Pixel(0, -50) | |
143 | + }) | |
144 | + infoWindow.open(mapIns, e.target.getPosition()) | |
145 | + }) | |
146 | +} | |
147 | + | |
148 | +const dataHandle = (newData: dataJsonType) => { | |
125 | 149 | if (!mapIns && !AMapIns) { |
126 | 150 | initMap(props.chartConfig.option) |
127 | 151 | return |
... | ... | @@ -132,54 +156,28 @@ const dataHandle = (newData: any) => { |
132 | 156 | markers = [] |
133 | 157 | // 记录新标记 |
134 | 158 | if (mapMarkerType.value === MarkerEnum.MARKER) { |
135 | - newData.markers.forEach((markerItem: any) => { | |
159 | + newData.markers.forEach((markerItem: dataJsonMarkersType) => { | |
136 | 160 | const markerInstance = new AMapIns.Marker({ |
137 | 161 | position: [markerItem.position[0], markerItem.position[1]], |
138 | 162 | offset: new AMapIns.Pixel(-13, -30) |
139 | 163 | }) |
140 | - // markers.push(markerInstance) 原作者这种方式添加,地图标注获取不到当前点击对象 | |
164 | + // markers.push(markerInstance) 原作者这种方式添加,属于1.4.8版本的 | |
141 | 165 | // markerInstance.setMap(mapIns) |
142 | - markerInstance.setExtData({ | |
143 | - extraInfo: markerItem.extraInfo | |
144 | - }) | |
145 | - mapIns.add(markerInstance) | |
146 | - markerInstance.setLabel({ | |
147 | - content: markerItem.extraInfo.alias || markerItem.extraInfo.name | |
148 | - }) | |
149 | - markerInstance.on('click', async (e: any) => { | |
150 | - const { extraInfo } = e.target.getExtData() | |
151 | - let infoWindow = new AMapIns.InfoWindow({ | |
152 | - content: await createInfoWindow(extraInfo), | |
153 | - offset: new AMapIns.Pixel(0, -50) | |
154 | - }) | |
155 | - infoWindow.open(mapIns, e.target.getPosition()) | |
156 | - }) | |
166 | + mapClick(markerInstance, markerItem) | |
157 | 167 | }) |
158 | 168 | } else if (mapMarkerType.value === MarkerEnum.CIRCLE_MARKER) { |
159 | - newData.markers.forEach((markerItem: any) => { | |
169 | + newData.markers.forEach((markerItem: dataJsonMarkersType) => { | |
160 | 170 | const markerInstance = new AMapIns.CircleMarker({ |
161 | 171 | center: [ |
162 | 172 | !markerItem.position[0] ? 0 : markerItem.position[0], |
163 | 173 | !markerItem.position[1] ? 0 : markerItem.position[1] |
164 | 174 | ], |
165 | - radius: markerItem.value, | |
166 | - ...marker.value, | |
175 | + radius: markerItem.value, //圆圈半径大小 | |
176 | + ...marker.value | |
167 | 177 | }) |
168 | - // markers.push(markerInstance) //原作者这种方式添加,地图标注获取不到当前点击对象 | |
178 | + // markers.push(markerInstance) //原作者这种方式添加,属于1.4.8版本的 | |
169 | 179 | // markerInstance.setMap(mapIns) |
170 | - markerInstance.setExtData({ | |
171 | - extraInfo: markerItem.extraInfo | |
172 | - }) | |
173 | - mapIns.add(markerInstance) | |
174 | - markerInstance.on('click', async (e: any) => { | |
175 | - console.log(e) | |
176 | - const { extraInfo } = e.target.getExtData() | |
177 | - let infoWindow = new AMapIns.InfoWindow({ | |
178 | - content: await createInfoWindow(extraInfo), | |
179 | - offset: new AMapIns.Pixel(0, -50) | |
180 | - }) | |
181 | - infoWindow.open(mapIns, e.target.getPosition()) | |
182 | - }) | |
180 | + mapClick(markerInstance, markerItem) | |
183 | 181 | }) |
184 | 182 | } |
185 | 183 | } | ... | ... |