From 7635213630830c4cbb9ff6ada69ba9b5c8a35d42 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Thu, 03 Apr 2025 11:05:34 +0800
Subject: [PATCH] feat: 地图居中点调整
---
src/views/Home/useMapAggregation/useMapAggregation.js | 24 ++++++++----------------
1 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/src/views/Home/useMapAggregation/useMapAggregation.js b/src/views/Home/useMapAggregation/useMapAggregation.js
index 1e4f0b2..c3f6248 100644
--- a/src/views/Home/useMapAggregation/useMapAggregation.js
+++ b/src/views/Home/useMapAggregation/useMapAggregation.js
@@ -50,7 +50,7 @@
// 确定缩放比例
const determineScaling = () => {
- console.log('确定缩放比例');
+ // console.log('确定缩放比例');
if (!viewer) return;
let height = viewer.camera.positionCartographic.height;
// 根据高度展示对应的 gJson
@@ -61,9 +61,9 @@
active = item.name;
removeEntities();
removeLabel();
+ renderOutline(item);
if (!item.gJson && !item.splashedList?.length) return;
item.gJson ? aggregation(item) : splashed(item);
- renderOutline(item);
break;
}
}
@@ -169,14 +169,10 @@
scalingJudgment[0].gJson = null;
scalingJudgment[0].splashedList = splashedList;
active = null;
- // 轮廓
- const outlineGJson = await getOutLine(jsonPathPre, hierarchy);
- scalingJudgment.forEach(item => item.show && (item.outline = outlineGJson));
// 省
if (hierarchy.length === 1) {
const gJson1 = await getFiler(`${defaultDir}${jsonPath}/indexDistrict.json`);
const gJson2 = await getFiler(`${defaultDir}${jsonPath}/index.json`);
-
scalingJudgment[1].gJson = {
...gJson1,
features: gJson1.features.map(item => {
@@ -184,10 +180,7 @@
return { ...item, data: {...findData,type: type + 'Aggregation'} }
}),
};
- console.log(injectData(gJson2, list));
scalingJudgment[2].gJson = injectData(gJson2, list);
- const { lng, lat } = getCenterPoint(gJson2.features.map(item => item.properties.center));
- flyTo({ longitude: lng, latitude: lat }, 0, scalingJudgment[2].height);
}
// 市
if (hierarchy.length === 2) {
@@ -195,8 +188,6 @@
scalingJudgment[2].show = false;
const gJson1 = await getFiler(`${defaultDir}${jsonPath}/index.json`);
scalingJudgment[1].gJson = injectData(gJson1, list);
- const center = getCenterPoint(gJson1.features.map(item => item.properties.center));
- flyTo({ longitude: center.lng, latitude: center.lat }, 0, scalingJudgment[1].height);
}
// 区县
if (hierarchy.length === 3) {
@@ -204,11 +195,12 @@
scalingJudgment[1].show = false;
scalingJudgment[2].gJson = null;
scalingJudgment[2].show = false;
- const outlineGJson = await getOutLine(jsonPathPre, hierarchy);
- const center = outlineGJson.features[0].properties.center;
- flyTo({ longitude: center[0], latitude: center[1] }, 0, scalingJudgment[0].height);
}
- determineScaling()
+ // 轮廓
+ const outlineGJson = await getOutLine(jsonPathPre, hierarchy);
+ scalingJudgment.forEach(item => item.show && (item.outline = outlineGJson));
+ const [longitude,latitude] = outlineGJson.features[0].properties.centroid
+ flyTo({ longitude, latitude }, 0, scalingJudgment[(hierarchy.length-3) * (-1)].height);
};
watch(
@@ -287,7 +279,7 @@
// const {lng,lat} = getCenterPoint(item1.geometry.coordinates[0][0])
return {
name: item1.properties.name,
- position: item1.properties.center,
+ position: item1.properties.centroid,
data: item1.data,
id: item1.region_code,
}
--
Gitblit v1.9.3