mirror of
https://github.com/dataease/dataease.git
synced 2025-02-25 03:52:59 +08:00
fix(图表): 修复自定义地图重置效果异常 #13938
This commit is contained in:
parent
764138952f
commit
fcc34f43a3
@ -430,7 +430,9 @@ export class BubbleMap extends L7PlotChartView<ChoroplethOptions, Choropleth> {
|
|||||||
return obj
|
return obj
|
||||||
}, {})
|
}, {})
|
||||||
//处理label
|
//处理label
|
||||||
options.label = false
|
options.label = {
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
if (label.show) {
|
if (label.show) {
|
||||||
const geoJsonMap = geoJson.features.reduce((p, n) => {
|
const geoJsonMap = geoJson.features.reduce((p, n) => {
|
||||||
if (n.properties['adcode']) {
|
if (n.properties['adcode']) {
|
||||||
|
@ -129,6 +129,7 @@ export class FlowMap extends L7ChartView<Scene, L7Config> {
|
|||||||
mapRendering(container)
|
mapRendering(container)
|
||||||
scene.once('loaded', () => {
|
scene.once('loaded', () => {
|
||||||
mapRendered(container)
|
mapRendered(container)
|
||||||
|
this.configZoomButton(chart, scene)
|
||||||
})
|
})
|
||||||
if (xAxis?.length < 2 || xAxisExt?.length < 2) {
|
if (xAxis?.length < 2 || xAxisExt?.length < 2) {
|
||||||
return new L7Wrapper(scene, undefined)
|
return new L7Wrapper(scene, undefined)
|
||||||
@ -140,7 +141,6 @@ export class FlowMap extends L7ChartView<Scene, L7Config> {
|
|||||||
configList[0].once('inited', () => {
|
configList[0].once('inited', () => {
|
||||||
mapRendered(container)
|
mapRendered(container)
|
||||||
})
|
})
|
||||||
this.configZoomButton(chart, scene)
|
|
||||||
return new L7Wrapper(scene, configList)
|
return new L7Wrapper(scene, configList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +110,7 @@ export class HeatMap extends L7ChartView<Scene, L7Config> {
|
|||||||
mapRendering(container)
|
mapRendering(container)
|
||||||
scene.once('loaded', () => {
|
scene.once('loaded', () => {
|
||||||
mapRendered(container)
|
mapRendered(container)
|
||||||
|
this.configZoomButton(chart, scene)
|
||||||
})
|
})
|
||||||
if (xAxis?.length < 2 || yAxis?.length < 1) {
|
if (xAxis?.length < 2 || yAxis?.length < 1) {
|
||||||
return new L7Wrapper(scene, undefined)
|
return new L7Wrapper(scene, undefined)
|
||||||
@ -138,7 +139,6 @@ export class HeatMap extends L7ChartView<Scene, L7Config> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.configZoomButton(chart, scene)
|
|
||||||
return new L7Wrapper(scene, config)
|
return new L7Wrapper(scene, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,9 +209,7 @@ export class Map extends L7PlotChartView<ChoroplethOptions, Choropleth> {
|
|||||||
const { Choropleth } = await import('@antv/l7plot/dist/esm/plots/choropleth')
|
const { Choropleth } = await import('@antv/l7plot/dist/esm/plots/choropleth')
|
||||||
const view = new Choropleth(container, options)
|
const view = new Choropleth(container, options)
|
||||||
// 完成地图渲染后配置缩放按钮,为了能够获取到默认的缩放比例
|
// 完成地图渲染后配置缩放按钮,为了能够获取到默认的缩放比例
|
||||||
view.on('loaded', () => {
|
|
||||||
this.configZoomButton(chart, view)
|
this.configZoomButton(chart, view)
|
||||||
})
|
|
||||||
mapRendering(container)
|
mapRendering(container)
|
||||||
view.once('loaded', () => {
|
view.once('loaded', () => {
|
||||||
mapRendered(container)
|
mapRendered(container)
|
||||||
@ -499,7 +497,9 @@ export class Map extends L7PlotChartView<ChoroplethOptions, Choropleth> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
//处理label
|
//处理label
|
||||||
options.label = false
|
options.label = {
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
if (label.show) {
|
if (label.show) {
|
||||||
const labelLocation = []
|
const labelLocation = []
|
||||||
customSubArea.forEach(area => {
|
customSubArea.forEach(area => {
|
||||||
|
@ -154,6 +154,7 @@ export class SymbolicMap extends L7ChartView<Scene, L7Config> {
|
|||||||
mapRendering(container)
|
mapRendering(container)
|
||||||
scene.once('loaded', () => {
|
scene.once('loaded', () => {
|
||||||
mapRendered(container)
|
mapRendered(container)
|
||||||
|
this.configZoomButton(chart, scene)
|
||||||
})
|
})
|
||||||
if (xAxis?.length < 2) {
|
if (xAxis?.length < 2) {
|
||||||
return new L7Wrapper(scene, undefined)
|
return new L7Wrapper(scene, undefined)
|
||||||
@ -166,7 +167,6 @@ export class SymbolicMap extends L7ChartView<Scene, L7Config> {
|
|||||||
scene.addPopup(tooltipLayer)
|
scene.addPopup(tooltipLayer)
|
||||||
}
|
}
|
||||||
this.buildLabel(chart, configList)
|
this.buildLabel(chart, configList)
|
||||||
this.configZoomButton(chart, scene)
|
|
||||||
symbolicLayer.on('inited', ev => {
|
symbolicLayer.on('inited', ev => {
|
||||||
chart.container = container
|
chart.container = container
|
||||||
configCarouselTooltip(chart, symbolicLayer, symbolicLayer.sourceOption.data, scene)
|
configCarouselTooltip(chart, symbolicLayer, symbolicLayer.sourceOption.data, scene)
|
||||||
|
@ -1185,33 +1185,49 @@ export class CustomZoom extends Zoom {
|
|||||||
} as IZoomControlOption
|
} as IZoomControlOption
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export function configL7Zoom(chart: Chart, plot: L7Plot<PlotOptions> | Scene) {
|
export function configL7Zoom(chart: Chart, scene: Scene) {
|
||||||
const { basicStyle } = parseJson(chart.customAttr)
|
const { basicStyle } = parseJson(chart.customAttr)
|
||||||
const plotScene = plot instanceof Scene ? plot : plot.scene
|
const zoomOption = scene?.getControlByName('zoom')
|
||||||
const zoomOption = plotScene?.getControlByName('zoom')
|
|
||||||
if (zoomOption) {
|
if (zoomOption) {
|
||||||
plotScene.removeControl(zoomOption)
|
scene.removeControl(zoomOption)
|
||||||
}
|
}
|
||||||
if (shouldHideZoom(basicStyle)) {
|
if (shouldHideZoom(basicStyle)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!plotScene?.getControlByName('zoom')) {
|
if (!scene?.getControlByName('zoom')) {
|
||||||
let initZoom = basicStyle.autoFit === false ? basicStyle.zoomLevel : 2.5
|
scene.map.on('complete', () => {
|
||||||
let center = getCenter(basicStyle)
|
const initZoom = basicStyle.autoFit === false ? basicStyle.zoomLevel : scene.getZoom()
|
||||||
if (['map', 'bubble-map'].includes(chart.type)) {
|
const center =
|
||||||
initZoom = plotScene.getZoom()
|
basicStyle.autoFit === false
|
||||||
center = plotScene.getCenter()
|
? [basicStyle.mapCenter.longitude, basicStyle.mapCenter.latitude]
|
||||||
}
|
: [scene.map.getCenter().lng, scene.map.getCenter().lat]
|
||||||
const newZoomOptions = {
|
const newZoomOptions = {
|
||||||
initZoom: initZoom,
|
initZoom: initZoom,
|
||||||
center: center,
|
center: center,
|
||||||
buttonColor: basicStyle.zoomButtonColor,
|
buttonColor: basicStyle.zoomButtonColor,
|
||||||
buttonBackground: basicStyle.zoomBackground
|
buttonBackground: basicStyle.zoomBackground
|
||||||
} as any
|
} as any
|
||||||
addCustomZoom(plotScene, newZoomOptions)
|
scene.addControl(new CustomZoom(newZoomOptions))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function configL7PlotZoom(chart: Chart, plot: L7Plot<PlotOptions>) {
|
||||||
|
const { basicStyle } = parseJson(chart.customAttr)
|
||||||
|
if (shouldHideZoom(basicStyle)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
plot.once('loaded', () => {
|
||||||
|
const zoomOptions = {
|
||||||
|
initZoom: plot.scene.getZoom(),
|
||||||
|
center: plot.scene.getCenter(),
|
||||||
|
buttonColor: basicStyle.zoomButtonColor,
|
||||||
|
buttonBackground: basicStyle.zoomBackground
|
||||||
|
} as any
|
||||||
|
plot.scene.addControl(new CustomZoom(zoomOptions))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function setStyle(elements: HTMLElement[], styleProp: string, value) {
|
function setStyle(elements: HTMLElement[], styleProp: string, value) {
|
||||||
elements.forEach(e => {
|
elements.forEach(e => {
|
||||||
e.style[styleProp] = value
|
e.style[styleProp] = value
|
||||||
@ -1243,30 +1259,6 @@ function shouldHideZoom(basicStyle: any): boolean {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取地图中心点
|
|
||||||
* @param basicStyle
|
|
||||||
*/
|
|
||||||
function getCenter(basicStyle: any): [number, number] {
|
|
||||||
let center: [number, number] = [
|
|
||||||
DEFAULT_BASIC_STYLE.mapCenter.longitude,
|
|
||||||
DEFAULT_BASIC_STYLE.mapCenter.latitude
|
|
||||||
]
|
|
||||||
if (basicStyle.autoFit === false) {
|
|
||||||
center = [basicStyle.mapCenter.longitude, basicStyle.mapCenter.latitude]
|
|
||||||
}
|
|
||||||
return center
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加自定义缩放控件
|
|
||||||
* @param plotScene
|
|
||||||
* @param newZoomOptions
|
|
||||||
*/
|
|
||||||
function addCustomZoom(plotScene: Scene, newZoomOptions: any): void {
|
|
||||||
plotScene.addControl(new CustomZoom(newZoomOptions))
|
|
||||||
}
|
|
||||||
|
|
||||||
const G2_TOOLTIP_WRAPPER = 'g2-tooltip-wrapper'
|
const G2_TOOLTIP_WRAPPER = 'g2-tooltip-wrapper'
|
||||||
export function getTooltipContainer(id) {
|
export function getTooltipContainer(id) {
|
||||||
let wrapperDom = document.getElementById(G2_TOOLTIP_WRAPPER)
|
let wrapperDom = document.getElementById(G2_TOOLTIP_WRAPPER)
|
||||||
|
@ -5,9 +5,9 @@ import type { Plot as L7Plot } from '@antv/l7plot/dist/esm/core/plot'
|
|||||||
import {
|
import {
|
||||||
configL7Label,
|
configL7Label,
|
||||||
configL7Legend,
|
configL7Legend,
|
||||||
|
configL7PlotZoom,
|
||||||
configL7Style,
|
configL7Style,
|
||||||
configL7Tooltip,
|
configL7Tooltip
|
||||||
configL7Zoom
|
|
||||||
} from '@/views/chart/components/js/panel/common/common_antv'
|
} from '@/views/chart/components/js/panel/common/common_antv'
|
||||||
import {
|
import {
|
||||||
AntVAbstractChartView,
|
AntVAbstractChartView,
|
||||||
@ -85,7 +85,7 @@ export abstract class L7PlotChartView<
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected configZoomButton(chart: Chart, plot: P) {
|
protected configZoomButton(chart: Chart, plot: P) {
|
||||||
configL7Zoom(chart, plot)
|
configL7PlotZoom(chart, plot)
|
||||||
}
|
}
|
||||||
protected constructor(name: string, defaultData?: any[]) {
|
protected constructor(name: string, defaultData?: any[]) {
|
||||||
super(ChartLibraryType.L7_PLOT, name)
|
super(ChartLibraryType.L7_PLOT, name)
|
||||||
|
Loading…
Reference in New Issue
Block a user