fix: 补充地图注释
This commit is contained in:
@@ -6,7 +6,6 @@ export const storageKey = {
|
|||||||
i18n: 'cn-i18n',
|
i18n: 'cn-i18n',
|
||||||
languages: 'cn-languages',
|
languages: 'cn-languages',
|
||||||
language: 'cn-language',
|
language: 'cn-language',
|
||||||
timezone: 'cn-timezone',
|
|
||||||
theme: 'cn-theme',
|
theme: 'cn-theme',
|
||||||
dateFormat: 'cn-date-format',
|
dateFormat: 'cn-date-format',
|
||||||
timezoneOffset: 'cn-timezone-offset',
|
timezoneOffset: 'cn-timezone-offset',
|
||||||
|
|||||||
@@ -158,16 +158,18 @@ export default {
|
|||||||
unitConvert,
|
unitConvert,
|
||||||
initMap (id) {
|
initMap (id) {
|
||||||
try {
|
try {
|
||||||
|
// 初始化插件
|
||||||
const chart = am4Core.create(id, am4Maps.MapChart)
|
const chart = am4Core.create(id, am4Maps.MapChart)
|
||||||
chart.geodata = getGeoData(storageKey.iso36112WorldLow)
|
chart.geodata = getGeoData(storageKey.iso36112WorldLow)
|
||||||
chart.projection = new am4Maps.projections.Miller()
|
chart.projection = new am4Maps.projections.Miller()
|
||||||
this.myChart = shallowRef(chart)
|
this.myChart = shallowRef(chart)
|
||||||
|
// 初始化多边形series(即地图series)
|
||||||
this.polygonSeries = shallowRef(this.polygonSeriesFactory())
|
this.polygonSeries = shallowRef(this.polygonSeriesFactory())
|
||||||
|
// 如果是散点地图,再初始化散点series。DNS dashboard的地图是散点地图
|
||||||
if (this.isMapPoint) {
|
if (this.isMapPoint) {
|
||||||
this.worldImageSeries = shallowRef(this.imageSeriesFactory())
|
this.worldImageSeries = shallowRef(this.imageSeriesFactory())
|
||||||
}
|
}
|
||||||
|
// 渲染
|
||||||
this.loadAm4ChartMap(this.polygonSeries, this.worldImageSeries)
|
this.loadAm4ChartMap(this.polygonSeries, this.worldImageSeries)
|
||||||
|
|
||||||
// 地图点击事件
|
// 地图点击事件
|
||||||
@@ -242,12 +244,14 @@ export default {
|
|||||||
},
|
},
|
||||||
imageSeriesFactory (dataField) {
|
imageSeriesFactory (dataField) {
|
||||||
const vm = this
|
const vm = this
|
||||||
|
// emcharts实例中增加地图图案series(用来在地图上画圆点、方块、连线等)
|
||||||
const imageSeries = this.myChart.series.push(new am4Maps.MapImageSeries())
|
const imageSeries = this.myChart.series.push(new am4Maps.MapImageSeries())
|
||||||
|
// 指定接口数据中哪个字段名代表数值
|
||||||
imageSeries.dataFields.value = dataField || 'count'
|
imageSeries.dataFields.value = dataField || 'count'
|
||||||
|
// 取出图案的默认模板,用来接下来做自定义更改
|
||||||
const imageTemplate = imageSeries.mapImages.template
|
const imageTemplate = imageSeries.mapImages.template
|
||||||
imageTemplate.nonScaling = true
|
imageTemplate.nonScaling = true
|
||||||
|
// 通过地区ID来获取经纬度,设置后无需自己提供经纬度
|
||||||
imageTemplate.adapter.add('latitude', function (latitude, target) {
|
imageTemplate.adapter.add('latitude', function (latitude, target) {
|
||||||
const polygon = vm.polygonSeries.getPolygonById(target.dataItem.dataContext.id)
|
const polygon = vm.polygonSeries.getPolygonById(target.dataItem.dataContext.id)
|
||||||
if (polygon) {
|
if (polygon) {
|
||||||
@@ -255,7 +259,6 @@ export default {
|
|||||||
}
|
}
|
||||||
return latitude
|
return latitude
|
||||||
})
|
})
|
||||||
|
|
||||||
imageTemplate.adapter.add('longitude', function (longitude, target) {
|
imageTemplate.adapter.add('longitude', function (longitude, target) {
|
||||||
const polygon = vm.polygonSeries.getPolygonById(target.dataItem.dataContext.id)
|
const polygon = vm.polygonSeries.getPolygonById(target.dataItem.dataContext.id)
|
||||||
if (polygon) {
|
if (polygon) {
|
||||||
@@ -264,6 +267,7 @@ export default {
|
|||||||
return longitude
|
return longitude
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 设置图案样式
|
||||||
const circle = imageTemplate.createChild(am4Core.Circle)
|
const circle = imageTemplate.createChild(am4Core.Circle)
|
||||||
circle.propertyFields.fill = 'color'
|
circle.propertyFields.fill = 'color'
|
||||||
circle.propertyFields.stroke = 'border'
|
circle.propertyFields.stroke = 'border'
|
||||||
@@ -317,6 +321,7 @@ export default {
|
|||||||
const sorted = seriesData.sort((a, b) => b.value - a.value)
|
const sorted = seriesData.sort((a, b) => b.value - a.value)
|
||||||
const allZero = this.$_.isEmpty(sorted) || Number(sorted[0].value) === 0
|
const allZero = this.$_.isEmpty(sorted) || Number(sorted[0].value) === 0
|
||||||
|
|
||||||
|
// 左下角热力图
|
||||||
polygonSeries.heatRules.push({
|
polygonSeries.heatRules.push({
|
||||||
property: 'fill',
|
property: 'fill',
|
||||||
target: polygonSeries.mapPolygons.template,
|
target: polygonSeries.mapPolygons.template,
|
||||||
@@ -335,6 +340,7 @@ export default {
|
|||||||
heatLegend.marginLeft = 15
|
heatLegend.marginLeft = 15
|
||||||
heatLegend.valign = 'bottom'
|
heatLegend.valign = 'bottom'
|
||||||
|
|
||||||
|
// 计算热力图的最大值最小值
|
||||||
const minRange = heatLegend.valueAxis.axisRanges.create()
|
const minRange = heatLegend.valueAxis.axisRanges.create()
|
||||||
minRange.value = heatLegend.minValue
|
minRange.value = heatLegend.minValue
|
||||||
minRange.label.text = minRange.value === 0 ? 0 : unitConvert(heatLegend.minValue, chartParams.unitType).join(' ')
|
minRange.label.text = minRange.value === 0 ? 0 : unitConvert(heatLegend.minValue, chartParams.unitType).join(' ')
|
||||||
|
|||||||
Reference in New Issue
Block a user