调整点位搜索初始空间点位来源
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
lyf
2026-07-05 23:55:20 +08:00
parent a71994d490
commit b99ae572da
5 changed files with 218 additions and 21 deletions

View File

@@ -48,11 +48,66 @@ const hallCategory: MuseumCategory = {
iconType: 'exhibition_hall'
}
const hallEntranceCategory: MuseumCategory = {
id: 'exhibition_hall_entrance',
label: '展厅出入口',
iconType: 'hall_entrance'
}
const hallEntranceCategory: MuseumCategory = {
id: 'exhibition_hall_entrance',
label: '展厅出入口',
iconType: 'hall_entrance'
}
const spaceCategory: MuseumCategory = {
id: 'space_point',
label: '空间点位',
iconType: 'space'
}
const spaceCategoryBySgsType: Record<string, MuseumCategory> = {
exhibition_hall: hallCategory,
theater: {
id: 'space_theater',
label: '剧场空间',
iconType: 'theater'
},
education_activity: {
id: 'space_education_activity',
label: '教育活动空间',
iconType: 'education_activity'
},
ramp: {
id: 'space_ramp',
label: '空间坡道',
iconType: 'ramp'
},
public_area: {
id: 'space_public_area',
label: '公共空间',
iconType: 'public_area'
},
service_space: {
id: 'space_service',
label: '服务空间',
iconType: 'service_space'
},
commercial: {
id: 'space_commercial',
label: '商业空间',
iconType: 'commercial'
},
parking: {
id: 'space_parking',
label: '停车空间',
iconType: 'parking'
},
plaza: {
id: 'space_plaza',
label: '广场空间',
iconType: 'plaza'
},
room: {
id: 'space_room',
label: '房间空间',
iconType: 'room'
}
}
const categoryBySgsType: Record<string, MuseumCategory & { accessible?: boolean }> = {
poi: {
@@ -278,6 +333,11 @@ interface SgsHallPoiBuildOptions {
const sgsSpaceCenterConfidence = 'backend-sgs-sdk-space-center'
const sgsSpaceBoundaryCenterConfidence = 'backend-sgs-sdk-space-boundary-center'
const sgsHallEntranceConfidence = 'backend-sgs-sdk-hall-entrance'
const normalizeTypeId = (value?: string | null) => normalizedText(value)
.toLowerCase()
.replace(/[^a-z0-9_-]+/g, '_')
.replace(/^_+|_+$/g, '')
const hasExhibitionKeyword = (value?: string | null) => (
exhibitionHallKeywords.some((keyword) => normalizedText(value).includes(keyword))
@@ -294,7 +354,7 @@ const searchableSpaceText = (space: SgsSpacePayload) => [
const parseBoundaryWktCenter = (
boundaryWkt?: string | null,
fallbackY?: number
fallbackY = 0
): [number, number, number] | undefined => {
const matches = [...(boundaryWkt || '').matchAll(/(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g)]
const points = matches
@@ -573,19 +633,75 @@ const findMatchedHallSpace = (
return rankedMatches[0]?.space
}
const floorLabelForSgs = (
floorId: string,
floors: SgsSdkFloorSummaryPayload[],
floorCode?: string | null,
const floorLabelForSgs = (
floorId: string,
floors: SgsSdkFloorSummaryPayload[],
floorCode?: string | null,
floorName?: string | null
) => {
const matchedFloor = floors.find((floor) => stringifyId(floor.floorId) === floorId || floor.floorCode === floorCode)
return formatSgsFloorLabel(
matchedFloor?.floorCode || floorCode,
matchedFloor?.floorName || floorName
)
}
)
}
const categoryForSgsSpace = (space: SgsSpacePayload): MuseumCategory => {
const normalizedType = normalizeTypeId(space.type)
if (normalizedType && spaceCategoryBySgsType[normalizedType]) {
return spaceCategoryBySgsType[normalizedType]
}
const typeLabel = normalizedText(space.type)
if (typeLabel) {
return {
id: `space_${normalizedType || 'point'}`,
label: typeLabel,
iconType: normalizedType || spaceCategory.iconType
}
}
return spaceCategory
}
export const toMuseumSpacePointFromSgs = (
space: SgsSpacePayload,
floors: SgsSdkFloorSummaryPayload[],
fallbackFloorId: string,
options: SgsHallPoiBuildOptions = {}
): MuseumPoi | null => {
const spaceId = stringifyId(space.id)
const floorId = stringifyId(space.floorId) || fallbackFloorId
const name = normalizedText(space.name)
const spacePosition = normalizeSpacePosition(space, options.fallbackY)
if (!spaceId || !name || !spacePosition) return null
const category = categoryForSgsSpace(space)
return {
id: `space-${spaceId}`,
name,
floorId,
floorLabel: floorLabelForSgs(floorId, floors),
primaryCategory: category,
categories: [
category
],
positionGltf: spacePosition.position,
sourceObjectName: space.sourceNodeName || undefined,
sourceConfidence: spacePosition.sourceConfidence,
navigationReadiness: '位置预览',
accessible: false,
kind: 'space',
hallId: category.id === hallCategory.id ? spaceId : undefined,
hallName: category.id === hallCategory.id ? name : undefined,
spaceId,
sourceSpaceId: spaceId
}
}
const createHallEntrance = (
place: SgsNavigablePlacePayload,
floors: SgsSdkFloorSummaryPayload[],