将周边分析的配置文件放在hook下

This commit is contained in:
2026-06-24 17:16:25 +08:00
parent bb49275f88
commit ef11dbcc58
3 changed files with 166 additions and 56 deletions
+20 -19
View File
@@ -1,7 +1,7 @@
import { ref, reactive, onUnmounted, watch, computed } from 'vue';
import { useStatusStore } from '@/stores/useStatusStore';
import { useLoadingResourceStore } from '@/stores/useLoadingResourceStore';
import { RESOURCE_CONFIGS, AROUND_ANALYSIS_CONSTANTS } from '@/config/aroundAnalysisConfig';
import { useAroundAnalysisConfig } from './useAroundAnalysisConfig';
import type { PointResource, PointResourceCategory, AnalysisButtonConfig, AroundAnalysisState } from '@/types/common/useAroundAnalysisType';
import { CesiumUtilsSingleton } from '@/utils/cesium/CesiumUtils';
import { isCategoryVisible, loadAllPointData, calculateDistance } from '@/utils/aroundAnalysisUtils';
@@ -21,6 +21,7 @@ import { useMarkerManager } from './useMarkerManager';
*/
export const useAroundAnalysis = (): AroundAnalysisState => {
const statusStore = useStatusStore();
const { resourceConfigs, MIN_FLY_HEIGHT, FLY_HEIGHT_MULTIPLIER, FLY_DURATION } = useAroundAnalysisConfig();
// ==================== 响应式状态 ====================
const selectedButtonIndex = ref<number>(-1);
@@ -31,7 +32,7 @@ export const useAroundAnalysis = (): AroundAnalysisState => {
const showPulsePointList = ref(false);
const searchState = ref('');
const canSearch = computed(() => {
return RESOURCE_CONFIGS.some(config => isCategoryVisible(config.category, config.forcedType));
return resourceConfigs.value.some(config => isCategoryVisible(config.category, config.forcedType));
});
let clickHandler: ScreenSpaceEventHandler | null = null;
@@ -48,7 +49,7 @@ export const useAroundAnalysis = (): AroundAnalysisState => {
const centerLon = cartographic.longitude * (180 / Math.PI);
const centerLat = cartographic.latitude * (180 / Math.PI);
const allPoints = loadAllPointData(RESOURCE_CONFIGS);
const allPoints = loadAllPointData(resourceConfigs.value);
const radiusMeters = radiusKm * 1000;
const filteredPoints = allPoints.filter(point => {
@@ -125,20 +126,20 @@ export const useAroundAnalysis = (): AroundAnalysisState => {
const calculateDialogPosition = (clickPosition: Cartesian2) => {
const { innerWidth: screenWidth, innerHeight: screenHeight } = window;
const { DIALOG_WIDTH, DIALOG_HEIGHT, DIALOG_PADDING, DIALOG_OFFSET } = AROUND_ANALYSIS_CONSTANTS;
const { DIALOG_WIDTH: dialogWidth, DIALOG_HEIGHT: dialogHeight, DIALOG_PADDING: dialogPadding, DIALOG_OFFSET: dialogOffset } = useAroundAnalysisConfig().getConstants();
let x = clickPosition.x + DIALOG_OFFSET;
let y = clickPosition.y + DIALOG_OFFSET;
let x = clickPosition.x + dialogOffset;
let y = clickPosition.y + dialogOffset;
if (x + DIALOG_WIDTH > screenWidth - DIALOG_PADDING) {
x = clickPosition.x - DIALOG_WIDTH - DIALOG_OFFSET;
if (x + dialogWidth > screenWidth - dialogPadding) {
x = clickPosition.x - dialogWidth - dialogOffset;
}
if (y + DIALOG_HEIGHT > screenHeight - DIALOG_PADDING) {
y = clickPosition.y - DIALOG_HEIGHT - DIALOG_OFFSET;
if (y + dialogHeight > screenHeight - dialogPadding) {
y = clickPosition.y - dialogHeight - dialogOffset;
}
dialogPosition.x = Math.max(DIALOG_PADDING, Math.min(x, screenWidth - DIALOG_WIDTH - DIALOG_PADDING));
dialogPosition.y = Math.max(DIALOG_PADDING, Math.min(y, screenHeight - DIALOG_HEIGHT - DIALOG_PADDING));
dialogPosition.x = Math.max(dialogPadding, Math.min(x, screenWidth - dialogWidth - dialogPadding));
dialogPosition.y = Math.max(dialogPadding, Math.min(y, screenHeight - dialogHeight - dialogPadding));
};
// ==================== 事件处理 ====================
@@ -160,8 +161,8 @@ export const useAroundAnalysis = (): AroundAnalysisState => {
const longitude = cartographic.longitude * (180 / Math.PI);
const latitude = cartographic.latitude * (180 / Math.PI);
const flyHeight = Math.max(radius.value * AROUND_ANALYSIS_CONSTANTS.FLY_HEIGHT_MULTIPLIER, AROUND_ANALYSIS_CONSTANTS.MIN_FLY_HEIGHT);
CesiumUtilsSingleton.flyToTarget([longitude, latitude, flyHeight], AROUND_ANALYSIS_CONSTANTS.FLY_DURATION);
const flyHeight = Math.max(radius.value * FLY_HEIGHT_MULTIPLIER, MIN_FLY_HEIGHT);
CesiumUtilsSingleton.flyToTarget([longitude, latitude, flyHeight], FLY_DURATION);
showAreaDialog.value = false;
removeMapClickHandler();
@@ -212,10 +213,10 @@ export const useAroundAnalysis = (): AroundAnalysisState => {
const centerX = window.innerWidth / 2;
const centerY = window.innerHeight / 2;
const { DIALOG_WIDTH, DIALOG_HEIGHT, DIALOG_PADDING, DIALOG_OFFSET } = AROUND_ANALYSIS_CONSTANTS;
const { DIALOG_WIDTH: dialogWidth, DIALOG_HEIGHT: dialogHeight, DIALOG_PADDING: dialogPadding, DIALOG_OFFSET: dialogOffset } = useAroundAnalysisConfig().getConstants();
dialogPosition.x = Math.max(DIALOG_PADDING, Math.min(centerX + DIALOG_OFFSET, window.innerWidth - DIALOG_WIDTH - DIALOG_PADDING));
dialogPosition.y = Math.max(DIALOG_PADDING, Math.min(centerY + DIALOG_OFFSET, window.innerHeight - DIALOG_HEIGHT - DIALOG_PADDING));
dialogPosition.x = Math.max(dialogPadding, Math.min(centerX + dialogOffset, window.innerWidth - dialogWidth - dialogPadding));
dialogPosition.y = Math.max(dialogPadding, Math.min(centerY + dialogOffset, window.innerHeight - dialogHeight - dialogPadding));
};
// ==================== 搜索功能 ====================
@@ -226,10 +227,10 @@ export const useAroundAnalysis = (): AroundAnalysisState => {
}
const lowerQuery = queryString.toLowerCase();
const allResources = loadAllPointData(RESOURCE_CONFIGS);
const allResources = loadAllPointData(resourceConfigs.value);
const filteredResults = allResources.filter(item => {
const config = RESOURCE_CONFIGS.find(c => c.category === item.category);
const config = resourceConfigs.value.find(c => c.category === item.category);
let isVisible = false;
if (config) {