@ -28,10 +28,21 @@ export const MapPage = (): JSX.Element => {
const allNodes = Array . from ( nodes . values ( ) ) ;
const allNodes = Array . from ( nodes . values ( ) ) ;
const getBBox = ( ) = > {
const getBBox = ( ) = > {
if ( ! map ) return ;
const nodesWithPosition = allNodes . filter (
const nodesWithPosition = allNodes . filter (
( node ) = > node . position ? . latitudeI
( node ) = > node . position ? . latitudeI
) ;
) ;
if ( ! nodesWithPosition . length ) return ;
if ( ! nodesWithPosition . length ) return ;
if ( nodesWithPosition . length === 1 ) {
map . easeTo ( {
zoom : 12 ,
center : [
( nodesWithPosition [ 0 ] . position ? . longitudeI ? ? 0 ) / 1 e7 ,
( nodesWithPosition [ 0 ] . position ? . latitudeI ? ? 0 ) / 1 e7
]
} ) ;
return ;
}
const line = lineString (
const line = lineString (
nodesWithPosition . map ( ( n ) = > [
nodesWithPosition . map ( ( n ) = > [
( n . position ? . latitudeI ? ? 0 ) / 1 e7 ,
( n . position ? . latitudeI ? ? 0 ) / 1 e7 ,
@ -39,22 +50,14 @@ export const MapPage = (): JSX.Element => {
] )
] )
) ;
) ;
const bounds = bbox ( line ) ;
const bounds = bbox ( line ) ;
const center = map ? . cameraForBounds (
const center = map . cameraForBounds (
[
[
[ bounds [ 1 ] , bounds [ 0 ] ] ,
[ bounds [ 1 ] , bounds [ 0 ] ] ,
[ bounds [ 3 ] , bounds [ 2 ] ]
[ bounds [ 3 ] , bounds [ 2 ] ]
] ,
] ,
{ padding : { top : 10 , bottom : 10 , left : 10 , right : 10 } }
{ padding : { top : 10 , bottom : 10 , left : 10 , right : 10 } }
) ;
) ;
if ( center ) map ? . easeTo ( center ) ;
if ( center ) map . easeTo ( center ) ;
else if ( nodesWithPosition . length === 1 )
map ? . easeTo ( {
zoom : 12 ,
center : [
( nodesWithPosition [ 0 ] . position ? . longitudeI ? ? 0 ) / 1 e7 ,
( nodesWithPosition [ 0 ] . position ? . latitudeI ? ? 0 ) / 1 e7
]
} ) ;
} ;
} ;
useEffect ( ( ) = > {
useEffect ( ( ) = > {
@ -63,6 +66,12 @@ export const MapPage = (): JSX.Element => {
} ) ;
} ) ;
} , [ map , zoom ] ) ;
} , [ map , zoom ] ) ;
useEffect ( ( ) = > {
if ( map ) {
getBBox ( ) ;
}
} , [ map ] ) ;
return (
return (
< >
< >
< Sidebar >
< Sidebar >