diff --git a/core/core-frontend/package.json b/core/core-frontend/package.json index 90a12fe687..dc6233168c 100644 --- a/core/core-frontend/package.json +++ b/core/core-frontend/package.json @@ -21,6 +21,7 @@ "@codemirror/lang-sql": "^6.4.0", "@npkg/tinymce-plugins": "^0.0.7", "@tinymce/tinymce-vue": "^5.1.0", + "@turf/centroid": "^7.0.0", "@videojs-player/vue": "^1.0.0", "@vueuse/core": "^9.13.0", "ace-builds": "^1.15.3", 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 5bc9e3f96f..050b56e31c 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 @@ -28,6 +28,7 @@ import { DOM } from '@antv/l7-utils' import { Scene } from '@antv/l7-scene' import { type IZoomControlOption } from '@antv/l7-component' import { PositionType } from '@antv/l7-core' +import { centroid } from '@turf/centroid' export function getPadding(chart: Chart): number[] { if (chart.drill) { @@ -890,8 +891,13 @@ export function configL7Tooltip(chart: Chart): TooltipOptions { export function handleGeoJson(geoJson: FeatureCollection, nameMapping?: Record) { geoJson.features.forEach(item => { - if (!item.properties['centroid'] && item.properties['center']) { - item.properties['centroid'] = item.properties['center'] + if (!item.properties['centroid']) { + if (item.properties['center']) { + item.properties['centroid'] = item.properties['center'] + } else { + const tmp = centroid(item.geometry) + item.properties['centroid'] = tmp.geometry.coordinates + } } let name = item.properties['name'] if (nameMapping?.[name]) {