fix(图表): 修复缩放地图按钮无法显示隐藏以及配置无效的问题

This commit is contained in:
jianneng-fit2cloud 2024-11-05 14:34:04 +08:00
parent a92d6daf1a
commit 466ab5281f

View File

@ -1,5 +1,6 @@
import { hexColorToRGBA, parseJson } from '../../util' import { hexColorToRGBA, parseJson } from '../../util'
import { import {
DEFAULT_BASIC_STYLE,
DEFAULT_XAXIS_STYLE, DEFAULT_XAXIS_STYLE,
DEFAULT_YAXIS_EXT_STYLE, DEFAULT_YAXIS_EXT_STYLE,
DEFAULT_YAXIS_STYLE DEFAULT_YAXIS_STYLE
@ -1139,22 +1140,23 @@ export class CustomZoom extends Zoom {
} }
export function configL7Zoom(chart: Chart, plot: L7Plot<PlotOptions> | Scene) { export function configL7Zoom(chart: Chart, plot: L7Plot<PlotOptions> | Scene) {
const { basicStyle } = parseJson(chart.customAttr) const { basicStyle } = parseJson(chart.customAttr)
if ( const plotScene = plot instanceof Scene ? plot : plot.scene
(basicStyle.suspension === false && basicStyle.showZoom === undefined) || const zoomOption = plotScene?.getControlByName('zoom')
basicStyle.showZoom === false if (zoomOption) {
) { plotScene.removeControl(zoomOption)
}
if (shouldHideZoom(basicStyle)) {
return return
} }
const plotScene = plot instanceof Scene ? plot : plot.scene if (!plotScene?.getControlByName('zoom')) {
plot.once('loaded', () => { const newZoomOptions = {
const zoomOptions = { initZoom: basicStyle.autoFit === false ? basicStyle.zoomLevel : 2.5,
initZoom: plotScene.getZoom(), center: getCenter(basicStyle),
center: plotScene.getCenter(),
buttonColor: basicStyle.zoomButtonColor, buttonColor: basicStyle.zoomButtonColor,
buttonBackground: basicStyle.zoomBackground buttonBackground: basicStyle.zoomBackground
} as any } as any
plotScene.addControl(new CustomZoom(zoomOptions)) addCustomZoom(plotScene, newZoomOptions)
}) }
} }
function setStyle(elements: HTMLElement[], styleProp: string, value) { function setStyle(elements: HTMLElement[], styleProp: string, value) {
@ -1176,3 +1178,35 @@ export function mapRendered(dom: HTMLElement | string) {
} }
dom.classList.add('de-map-rendered') dom.classList.add('de-map-rendered')
} }
/**
* 隐藏缩放控件
* @param basicStyle
*/
function shouldHideZoom(basicStyle: any): boolean {
return (
(basicStyle.suspension === false && basicStyle.showZoom === undefined) ||
basicStyle.showZoom === false
)
}
/**
* 获取地图中心点
* @param basicStyle
*/
function getCenter(basicStyle: any): [number, number] {
let center = [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))
}