fix: 修复地图下钻后切换方向可能出错的问题

This commit is contained in:
chenjinsong
2022-08-30 17:28:51 +08:00
parent 72f3877eb4
commit 5ebcab59e1

View File

@@ -63,9 +63,9 @@ export default {
locationOptions, locationOptions,
myChart: null, myChart: null,
polygonSeries: null, polygonSeries: null,
countrySeries: [], countrySeries: null,
worldImageSeries: null, worldImageSeries: null,
countryImageSeries: [], countryImageSeries: null,
// Server | Client // Server | Client
trafficDirection: 'Server', trafficDirection: 'Server',
location: '' location: ''
@@ -94,24 +94,13 @@ export default {
this.worldImageSeries.mapImages.template.events.on('hit', async ev => { this.worldImageSeries.mapImages.template.events.on('hit', async ev => {
this.$store.commit('setNpmLocationCountry', ev.target.dataItem.dataContext.name) this.$store.commit('setNpmLocationCountry', ev.target.dataItem.dataContext.name)
this.location = ev.target.dataItem.dataContext.name this.location = ev.target.dataItem.dataContext.name
this.cleanCountry()
const countryId = ev.target.dataItem.dataContext.id const countryId = ev.target.dataItem.dataContext.id
ev.target.isHover = false ev.target.isHover = false
await this.drill(countryId) await this.drill(countryId)
}) })
}, },
cleanCountry () {
this.countrySeries.forEach(s => {
s.value.dispose()
})
this.countryImageSeries.forEach(s => {
s.value.dispose()
})
},
loadAm4ChartMap (polygonSeries, imageSeries) { loadAm4ChartMap (polygonSeries, imageSeries) {
try { try {
// 清除数据
// polygonSeries.data.splice(0)
this.toggleLoading(true) this.toggleLoading(true)
// 清除legend // 清除legend
this.myChart.children.each((s, i) => { this.myChart.children.each((s, i) => {
@@ -127,6 +116,7 @@ export default {
country: this.location country: this.location
} }
getData(api.npm.location.map, params).then(res => { getData(api.npm.location.map, params).then(res => {
if (res.length > 0) {
// 计算分数 // 计算分数
const tcpRequest = get(api.npm.location.mapTcp, params) const tcpRequest = get(api.npm.location.mapTcp, params)
const httpRequest = get(api.npm.location.mapHttp, params) const httpRequest = get(api.npm.location.mapHttp, params)
@@ -160,6 +150,9 @@ export default {
}) })
this.loadMarkerData(imageSeries, mapData) this.loadMarkerData(imageSeries, mapData)
}) })
} else {
imageSeries.data = [{}]
}
}).finally(() => { }).finally(() => {
this.toggleLoading(false) this.toggleLoading(false)
}) })
@@ -270,15 +263,19 @@ export default {
targetMapObject.series.chart.zoomToMapObject(targetMapObject) targetMapObject.series.chart.zoomToMapObject(targetMapObject)
const geoData = await getGeoData(countryId) const geoData = await getGeoData(countryId)
if (geoData) { if (geoData) {
const countrySeries = shallowRef(this.polygonSeriesFactory()) if (!this.countrySeries) {
countrySeries.value.geodata = geoData this.countrySeries = this.polygonSeriesFactory()
const countryImageSeries = shallowRef(this.imageSeriesFactory('score', countrySeries.value)) }
this.countrySeries.push(countrySeries) if (!this.countryImageSeries) {
this.countryImageSeries.push(countryImageSeries) this.countryImageSeries = this.imageSeriesFactory('score', this.countrySeries)
}
this.countrySeries.show()
this.countryImageSeries.show()
this.countrySeries.geodata = geoData
this.polygonSeries.hide() this.polygonSeries.hide()
this.worldImageSeries.hide() this.worldImageSeries.hide()
this.$nextTick(() => { this.$nextTick(() => {
this.loadAm4ChartMap(countrySeries.value, countryImageSeries.value) this.loadAm4ChartMap(this.countrySeries, this.countryImageSeries)
}) })
} }
} }
@@ -295,13 +292,14 @@ export default {
}, },
async location (n) { async location (n) {
this.$store.commit('setNpmLocationCountry', n) this.$store.commit('setNpmLocationCountry', n)
this.cleanCountry()
if (n) { if (n) {
const countryId = countryNameIdMapping[n] const countryId = countryNameIdMapping[n]
await this.drill(countryId) await this.drill(countryId)
} else { } else {
this.polygonSeries.show() this.polygonSeries.show()
this.worldImageSeries.show() this.worldImageSeries.show()
this.countrySeries.hide()
this.countryImageSeries.hide()
this.myChart.zoomToGeoPoint(this.myChart.homeGeoPoint, this.myChart.homeZoomLevel, true) this.myChart.zoomToGeoPoint(this.myChart.homeGeoPoint, this.myChart.homeZoomLevel, true)
} }
}, },