Merge pull request #9021 from dataease/pr@dev@fix_flow_map

fix(视图): 流向地图显示异常
This commit is contained in:
wisonic-s 2024-04-09 17:26:31 +08:00 committed by GitHub
commit 99c39e3153
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,7 +3,7 @@ import { GaodeMap } from '@antv/l7-maps'
import { getLanguage } from '@/lang' import { getLanguage } from '@/lang'
import { queryMapKey } from '@/api/map/map' import { queryMapKey } from '@/api/map/map'
export async function baseFlowMapOption(chartDom, chartId, chart, action) { export async function baseFlowMapOption(chartId, chart) {
const xAxis = JSON.parse(chart.xaxis) const xAxis = JSON.parse(chart.xaxis)
const xAxisExt = JSON.parse(chart.xaxisExt) const xAxisExt = JSON.parse(chart.xaxisExt)
let customAttr let customAttr
@ -15,35 +15,23 @@ export async function baseFlowMapOption(chartDom, chartId, chart, action) {
const mapStyle = `amap://styles/${color.mapStyle ? color.mapStyle : 'normal'}` const mapStyle = `amap://styles/${color.mapStyle ? color.mapStyle : 'normal'}`
const lang = getLanguage().includes('zh') ? 'zh' : 'en' const lang = getLanguage().includes('zh') ? 'zh' : 'en'
let init = false let init = false
if (!chartDom?.map) { const key = await getMapKey()
try { const mapInstance = new Scene({
chartDom.destroy() id: chartId,
} catch (e) { map: new GaodeMap({
// ignore token: key ?? undefined,
} lang: lang,
const key = await getMapKey() pitch: size.mapPitch,
chartDom = new Scene({ style: mapStyle
id: chartId, }),
map: new GaodeMap({ logoVisible: false
token: key ?? undefined, })
lang: lang, init = true
pitch: size.mapPitch,
style: mapStyle
}),
logoVisible: false
})
init = true
} else {
if (chartDom.map) {
chartDom.setPitch(size.mapPitch)
chartDom.setMapStyle(mapStyle)
}
}
if (xAxis?.length < 2 || xAxisExt?.length < 2) { if (xAxis?.length < 2 || xAxisExt?.length < 2) {
chartDom.removeAllLayer() await mapInstance.removeAllLayer()
return chartDom return mapInstance
} }
chartDom.removeAllLayer() mapInstance.removeAllLayer()
.then(() => { .then(() => {
const lineLayer = new LineLayer({ const lineLayer = new LineLayer({
name: 'line', name: 'line',
@ -80,16 +68,16 @@ export async function baseFlowMapOption(chartDom, chartId, chart, action) {
.color(color.mapLineSourceColor) .color(color.mapLineSourceColor)
} }
if (!init) { if (!init) {
chartDom.addLayer(lineLayer) mapInstance.addLayer(lineLayer)
} }
chartDom.on('loaded', () => { mapInstance.on('loaded', () => {
chartDom.addLayer(lineLayer) mapInstance.addLayer(lineLayer)
}) })
}) })
return chartDom return mapInstance
} }
const getMapKey = async() => { const getMapKey = async () => {
const key = 'online-map-key' const key = 'online-map-key'
if (!localStorage.getItem(key)) { if (!localStorage.getItem(key)) {
await queryMapKey().then(res => localStorage.setItem(key, res.data)) await queryMapKey().then(res => localStorage.setItem(key, res.data))