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