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,14 +15,8 @@ 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) {
try {
chartDom.destroy()
} catch (e) {
// ignore
}
const key = await getMapKey() const key = await getMapKey()
chartDom = new Scene({ const mapInstance = new Scene({
id: chartId, id: chartId,
map: new GaodeMap({ map: new GaodeMap({
token: key ?? undefined, token: key ?? undefined,
@ -33,17 +27,11 @@ export async function baseFlowMapOption(chartDom, chartId, chart, action) {
logoVisible: false logoVisible: false
}) })
init = true 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))