From 466ab5281f5d00554d55c50089b0b835410d838b Mon Sep 17 00:00:00 2001 From: jianneng-fit2cloud Date: Tue, 5 Nov 2024 14:34:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=BC=A9=E6=94=BE=E5=9C=B0=E5=9B=BE=E6=8C=89=E9=92=AE=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=98=BE=E7=A4=BA=E9=9A=90=E8=97=8F=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/js/panel/common/common_antv.ts | 56 +++++++++++++++---- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/common/common_antv.ts b/core/core-frontend/src/views/chart/components/js/panel/common/common_antv.ts index 4c15473bdf..ac879b5c3c 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/common/common_antv.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/common/common_antv.ts @@ -1,5 +1,6 @@ import { hexColorToRGBA, parseJson } from '../../util' import { + DEFAULT_BASIC_STYLE, DEFAULT_XAXIS_STYLE, DEFAULT_YAXIS_EXT_STYLE, DEFAULT_YAXIS_STYLE @@ -1139,22 +1140,23 @@ export class CustomZoom extends Zoom { } export function configL7Zoom(chart: Chart, plot: L7Plot | Scene) { const { basicStyle } = parseJson(chart.customAttr) - if ( - (basicStyle.suspension === false && basicStyle.showZoom === undefined) || - basicStyle.showZoom === false - ) { + const plotScene = plot instanceof Scene ? plot : plot.scene + const zoomOption = plotScene?.getControlByName('zoom') + if (zoomOption) { + plotScene.removeControl(zoomOption) + } + if (shouldHideZoom(basicStyle)) { return } - const plotScene = plot instanceof Scene ? plot : plot.scene - plot.once('loaded', () => { - const zoomOptions = { - initZoom: plotScene.getZoom(), - center: plotScene.getCenter(), + if (!plotScene?.getControlByName('zoom')) { + const newZoomOptions = { + initZoom: basicStyle.autoFit === false ? basicStyle.zoomLevel : 2.5, + center: getCenter(basicStyle), buttonColor: basicStyle.zoomButtonColor, buttonBackground: basicStyle.zoomBackground } as any - plotScene.addControl(new CustomZoom(zoomOptions)) - }) + addCustomZoom(plotScene, newZoomOptions) + } } function setStyle(elements: HTMLElement[], styleProp: string, value) { @@ -1176,3 +1178,35 @@ export function mapRendered(dom: HTMLElement | string) { } 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)) +}