mirror of
https://github.com/dataease/dataease.git
synced 2025-02-24 19:42:56 +08:00
Merge pull request #11391 from dataease/pr@dev-v2@chart-bubble-map-style
style(图表): 气泡地图的触发事件优化,由原来的区域触发改为气泡触发
This commit is contained in:
commit
aeaf6290be
@ -1,11 +1,7 @@
|
|||||||
import {useI18n} from '@/hooks/web/useI18n'
|
import {useI18n} from '@/hooks/web/useI18n'
|
||||||
import {
|
import {L7PlotChartView, L7PlotDrawOptions} from '@/views/chart/components/js/panel/types/impl/l7plot'
|
||||||
L7PlotChartView,
|
|
||||||
L7PlotDrawOptions
|
|
||||||
} from '@/views/chart/components/js/panel/types/impl/l7plot'
|
|
||||||
import {Choropleth, ChoroplethOptions} from '@antv/l7plot/dist/esm/plots/choropleth'
|
import {Choropleth, ChoroplethOptions} from '@antv/l7plot/dist/esm/plots/choropleth'
|
||||||
import { DotLayer, IPlotLayer } from '@antv/l7plot'
|
import {Dot, DotOptions, IPlotLayer} from '@antv/l7plot'
|
||||||
import { DotLayerOptions } from '@antv/l7plot/dist/esm/layers/dot-layer/types'
|
|
||||||
import {
|
import {
|
||||||
MAP_AXIS_TYPE,
|
MAP_AXIS_TYPE,
|
||||||
MAP_EDITOR_PROPERTY,
|
MAP_EDITOR_PROPERTY,
|
||||||
@ -15,12 +11,9 @@ import {
|
|||||||
import {flow, getGeoJsonFile, hexColorToRGBA, parseJson} from '@/views/chart/components/js/util'
|
import {flow, getGeoJsonFile, hexColorToRGBA, parseJson} from '@/views/chart/components/js/util'
|
||||||
import {cloneDeep} from 'lodash-es'
|
import {cloneDeep} from 'lodash-es'
|
||||||
import {FeatureCollection} from '@antv/l7plot/dist/esm/plots/choropleth/types'
|
import {FeatureCollection} from '@antv/l7plot/dist/esm/plots/choropleth/types'
|
||||||
import {
|
import {handleGeoJson, mapRendered, mapRendering} from '@/views/chart/components/js/panel/common/common_antv'
|
||||||
handleGeoJson,
|
|
||||||
mapRendered,
|
|
||||||
mapRendering
|
|
||||||
} from '@/views/chart/components/js/panel/common/common_antv'
|
|
||||||
import {valueFormatter} from '@/views/chart/components/js/formatter'
|
import {valueFormatter} from '@/views/chart/components/js/formatter'
|
||||||
|
import {deepCopy} from '@/utils/utils'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
@ -91,9 +84,6 @@ export class BubbleMap extends L7PlotChartView<ChoroplethOptions, Choropleth> {
|
|||||||
textAnchor: 'center'
|
textAnchor: 'center'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
state: {
|
|
||||||
active: { stroke: 'green', lineWidth: 1 }
|
|
||||||
},
|
|
||||||
tooltip: {},
|
tooltip: {},
|
||||||
legend: false,
|
legend: false,
|
||||||
// 禁用线上地图数据
|
// 禁用线上地图数据
|
||||||
@ -101,24 +91,33 @@ export class BubbleMap extends L7PlotChartView<ChoroplethOptions, Choropleth> {
|
|||||||
}
|
}
|
||||||
const context = { drawOption, geoJson }
|
const context = { drawOption, geoJson }
|
||||||
options = this.setupOptions(chart, options, context)
|
options = this.setupOptions(chart, options, context)
|
||||||
|
|
||||||
|
const tooltip = deepCopy(options.tooltip)
|
||||||
|
options = { ...options, tooltip: false }
|
||||||
const view = new Choropleth(container, options)
|
const view = new Choropleth(container, options)
|
||||||
const dotLayer = this.getDotLayer(chart, geoJson, drawOption)
|
const dotLayer = this.getDotLayer(chart, geoJson, drawOption)
|
||||||
|
dotLayer.options = { ...dotLayer.options, tooltip }
|
||||||
this.configZoomButton(chart, view)
|
this.configZoomButton(chart, view)
|
||||||
mapRendering(container)
|
mapRendering(container)
|
||||||
view.once('loaded', () => {
|
view.once('loaded', () => {
|
||||||
view.addLayer(dotLayer)
|
// 修改地图鼠标样式为默认
|
||||||
|
view.scene.map._canvasContainer.lastElementChild.style.cursor = 'default'
|
||||||
|
dotLayer.addToScene(view.scene)
|
||||||
dotLayer.once('add', () => {
|
dotLayer.once('add', () => {
|
||||||
mapRendered(container)
|
mapRendered(container)
|
||||||
})
|
})
|
||||||
view.scene.map['keyboard'].disable()
|
view.scene.map['keyboard'].disable()
|
||||||
view.on('fillAreaLayer:click', (ev: MapMouseEvent) => {
|
dotLayer.on('dotLayer:click', (ev: MapMouseEvent) => {
|
||||||
const data = ev.feature.properties
|
const data = ev.feature.properties
|
||||||
|
const adcode = view.currentDistrictData.features.find(
|
||||||
|
i => i.properties.name === ev.feature.properties.name
|
||||||
|
)?.properties.adcode
|
||||||
action({
|
action({
|
||||||
x: ev.x,
|
x: ev.x,
|
||||||
y: ev.y,
|
y: ev.y,
|
||||||
data: {
|
data: {
|
||||||
data,
|
data,
|
||||||
extra: { adcode: data.adcode }
|
extra: { adcode: adcode }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -132,24 +131,26 @@ export class BubbleMap extends L7PlotChartView<ChoroplethOptions, Choropleth> {
|
|||||||
drawOption: L7PlotDrawOptions<Choropleth>
|
drawOption: L7PlotDrawOptions<Choropleth>
|
||||||
): IPlotLayer {
|
): IPlotLayer {
|
||||||
const areaMap = chart.data?.data?.reduce((obj, value) => {
|
const areaMap = chart.data?.data?.reduce((obj, value) => {
|
||||||
obj[value['field']] = value.value
|
obj[value['field']] = { value: value.value, data: value }
|
||||||
return obj
|
return obj
|
||||||
}, {})
|
}, {})
|
||||||
const dotData = []
|
const dotData = []
|
||||||
geoJson.features.forEach(item => {
|
geoJson.features.forEach(item => {
|
||||||
const name = item.properties['name']
|
const name = item.properties['name']
|
||||||
if (areaMap?.[name]) {
|
if (areaMap?.[name]?.value) {
|
||||||
dotData.push({
|
dotData.push({
|
||||||
x: item.properties['centroid'][0],
|
x: item.properties['centroid'][0],
|
||||||
y: item.properties['centroid'][1],
|
y: item.properties['centroid'][1],
|
||||||
size: areaMap[name]
|
size: areaMap[name].value,
|
||||||
|
properties: areaMap[name].data,
|
||||||
|
name: name
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const { basicStyle } = parseJson(chart.customAttr)
|
const { basicStyle } = parseJson(chart.customAttr)
|
||||||
const { bubbleCfg } = parseJson(chart.senior)
|
const { bubbleCfg } = parseJson(chart.senior)
|
||||||
const { offsetHeight, offsetWidth } = document.getElementById(drawOption.container)
|
const { offsetHeight, offsetWidth } = document.getElementById(drawOption.container)
|
||||||
const options: DotLayerOptions = {
|
const options: DotOptions = {
|
||||||
source: {
|
source: {
|
||||||
data: dotData,
|
data: dotData,
|
||||||
parser: {
|
parser: {
|
||||||
@ -172,10 +173,11 @@ export class BubbleMap extends L7PlotChartView<ChoroplethOptions, Choropleth> {
|
|||||||
},
|
},
|
||||||
state: {
|
state: {
|
||||||
active: true
|
active: true
|
||||||
}
|
},
|
||||||
|
tooltip: {}
|
||||||
}
|
}
|
||||||
if (bubbleCfg && bubbleCfg.enable) {
|
if (bubbleCfg && bubbleCfg.enable) {
|
||||||
return new DotLayer({
|
return new Dot({
|
||||||
...options,
|
...options,
|
||||||
size: {
|
size: {
|
||||||
field: 'size',
|
field: 'size',
|
||||||
@ -188,7 +190,7 @@ export class BubbleMap extends L7PlotChartView<ChoroplethOptions, Choropleth> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return new DotLayer(options)
|
return new Dot(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
private configBasicStyle(
|
private configBasicStyle(
|
||||||
|
Loading…
Reference in New Issue
Block a user