@@ -156,6 +156,22 @@ const normalizePolygon = (
156156 return { type : "Polygon" , coordinates : [ closed ] } ;
157157} ;
158158
159+ const polygonFromPoint = (
160+ coordinate : Coordinates ,
161+ span = 0.00001 ,
162+ ) : Extract < FloorFeature [ "geometry" ] , { type : "Polygon" } > => ( {
163+ type : "Polygon" ,
164+ coordinates : [
165+ [
166+ [ coordinate [ 0 ] - span , coordinate [ 1 ] - span ] ,
167+ [ coordinate [ 0 ] + span , coordinate [ 1 ] - span ] ,
168+ [ coordinate [ 0 ] + span , coordinate [ 1 ] + span ] ,
169+ [ coordinate [ 0 ] - span , coordinate [ 1 ] + span ] ,
170+ [ coordinate [ 0 ] - span , coordinate [ 1 ] - span ] ,
171+ ] ,
172+ ] ,
173+ } ) ;
174+
159175const normalizeLine = (
160176 geometry : FloorFeature [ "geometry" ] ,
161177) : Extract < FloorFeature [ "geometry" ] , { type : "LineString" } > | undefined => {
@@ -342,6 +358,15 @@ const readRelationshipReference = (
342358 return undefined ;
343359} ;
344360
361+ const readRelationshipReferences = (
362+ value : unknown ,
363+ ) : Array < { id : string ; feature_type ?: string } > =>
364+ Array . isArray ( value )
365+ ? value
366+ . map ( ( entry ) => readRelationshipReference ( entry ) )
367+ . filter ( ( entry ) : entry is { id : string ; feature_type ?: string } => Boolean ( entry ) )
368+ : [ ] ;
369+
345370type BuildInput = {
346371 building : Building ;
347372 floors : Floor [ ] ;
@@ -581,25 +606,29 @@ export const buildImdfArchivePayload = ({
581606 ( typeof feature . properties . intermediary_id === "string"
582607 ? { id : feature . properties . intermediary_id }
583608 : undefined ) ;
609+ const intermediaryRefsFromArray = readRelationshipReferences ( feature . properties . intermediary ) ;
584610 const destinationRef =
585611 readRelationshipReference ( feature . properties . destination ) ??
586612 ( typeof feature . properties . destination_id === "string"
587613 ? { id : feature . properties . destination_id }
588614 : undefined ) ;
589615 const resolvedOriginId = relation ?. origin ?. featureId ?? originRef ?. id ;
590- const resolvedIntermediaryId = relation ?. intermediary ?. featureId ?? intermediaryRef ?. id ;
616+ const resolvedIntermediaryIds =
617+ relation ?. intermediary ?. map ( ( entry ) => entry . featureId ) . filter ( ( entry ) => Boolean ( entry ) ) ??
618+ ( intermediaryRefsFromArray . length > 0
619+ ? intermediaryRefsFromArray . map ( ( entry ) => entry . id )
620+ : intermediaryRef ?. id
621+ ? [ intermediaryRef . id ]
622+ : [ ] ) ;
591623 const resolvedDestinationId = relation ?. destination ?. featureId ?? destinationRef ?. id ;
592624 if ( mappedType === "relationship" ) {
625+ if ( baseProperties [ "category" ] === undefined ) {
626+ baseProperties [ "category" ] = "contains" ;
627+ }
593628 const resolvedOriginType =
594629 originRef ?. feature_type ??
595630 ( resolvedOriginId ? resolvedTypeByFeatureId . get ( resolvedOriginId ) : undefined ) ??
596631 "unit" ;
597- const resolvedIntermediaryType =
598- intermediaryRef ?. feature_type ??
599- ( resolvedIntermediaryId
600- ? resolvedTypeByFeatureId . get ( resolvedIntermediaryId )
601- : undefined ) ??
602- "unit" ;
603632 const resolvedDestinationType =
604633 destinationRef ?. feature_type ??
605634 ( resolvedDestinationId ? resolvedTypeByFeatureId . get ( resolvedDestinationId ) : undefined ) ??
@@ -610,12 +639,14 @@ export const buildImdfArchivePayload = ({
610639 feature_type : resolvedOriginType ,
611640 } ;
612641 }
613- if ( resolvedIntermediaryId ) {
614- baseProperties [ "intermediary" ] = {
615- id :
616- featureUuidById . get ( resolvedIntermediaryId ) ?? resolveImdfUuid ( resolvedIntermediaryId ) ,
617- feature_type : resolvedIntermediaryType ,
618- } ;
642+ if ( resolvedIntermediaryIds . length > 0 ) {
643+ baseProperties [ "intermediary" ] = resolvedIntermediaryIds . map ( ( intermediaryId ) => ( {
644+ id : featureUuidById . get ( intermediaryId ) ?? resolveImdfUuid ( intermediaryId ) ,
645+ feature_type :
646+ intermediaryRefsFromArray . find ( ( entry ) => entry . id === intermediaryId ) ?. feature_type ??
647+ resolvedTypeByFeatureId . get ( intermediaryId ) ??
648+ "unit" ,
649+ } ) ) ;
619650 }
620651 if ( resolvedDestinationId ) {
621652 baseProperties [ "destination" ] = {
@@ -636,9 +667,10 @@ export const buildImdfArchivePayload = ({
636667 baseProperties [ "origin_id" ] =
637668 featureUuidById . get ( resolvedOriginId ) ?? resolveImdfUuid ( resolvedOriginId ) ;
638669 }
639- if ( resolvedIntermediaryId ) {
670+ if ( resolvedIntermediaryIds [ 0 ] ) {
671+ const intermediaryId = resolvedIntermediaryIds [ 0 ] ;
640672 baseProperties [ "intermediary_id" ] =
641- featureUuidById . get ( resolvedIntermediaryId ) ?? resolveImdfUuid ( resolvedIntermediaryId ) ;
673+ featureUuidById . get ( intermediaryId ) ?? resolveImdfUuid ( intermediaryId ) ;
642674 }
643675 if ( resolvedDestinationId ) {
644676 baseProperties [ "destination_id" ] =
@@ -663,7 +695,11 @@ export const buildImdfArchivePayload = ({
663695
664696 let geometry : FloorFeature [ "geometry" ] | null = null ;
665697 if ( spec . geometryType === "Polygon" ) {
666- const normalized = normalizePolygon ( feature . geometry ) ;
698+ const normalized =
699+ normalizePolygon ( feature . geometry ) ??
700+ ( ( mappedType === "fixture" || mappedType === "kiosk" ) && feature . geometry . type === "Point"
701+ ? polygonFromPoint ( feature . geometry . coordinates )
702+ : undefined ) ;
667703 if ( ! normalized ) {
668704 warnings . push ( `Feature ${ feature . id } skipped: invalid polygon geometry for ${ mappedType } .` ) ;
669705 continue ;
0 commit comments