@@ -90,17 +90,24 @@ const Map = ({
90
90
const infraID = useInfraID ( ) ;
91
91
const terrain3DExaggeration = useSelector ( getTerrain3DExaggeration ) ;
92
92
const { viewport, mapSearchMarker, mapStyle, showOSM, layersSettings } = useSelector ( getMap ) ;
93
+ const mapRef = useRef < MapRef | null > ( null ) ;
93
94
94
95
const pathGeometry = useMemo (
95
96
( ) => geometry || pathProperties ?. geometry ,
96
97
[ pathProperties , geometry ]
97
98
) ;
98
99
99
- const mapViewport = useMemo (
100
- ( ) =>
101
- isReadOnly && pathGeometry ? computeBBoxViewport ( bbox ( pathGeometry ) , viewport ) : viewport ,
102
- [ isReadOnly , pathGeometry , viewport ]
103
- ) ;
100
+ const mapViewport = useMemo ( ( ) => {
101
+ if ( isReadOnly && pathGeometry ) {
102
+ const mapContainer = mapRef . current ?. getContainer ( ) ;
103
+ return computeBBoxViewport ( bbox ( pathGeometry ) , viewport , {
104
+ width : mapContainer ?. clientWidth ,
105
+ height : mapContainer ?. clientHeight ,
106
+ padding : 60 ,
107
+ } ) ;
108
+ }
109
+ return viewport ;
110
+ } , [ isReadOnly , pathGeometry , viewport , mapRef ] ) ;
104
111
105
112
const [ mapIsLoaded , setMapIsLoaded ] = useState ( false ) ;
106
113
@@ -112,8 +119,6 @@ const Map = ({
112
119
[ dispatch ]
113
120
) ;
114
121
115
- const mapRef = useRef < MapRef | null > ( null ) ;
116
-
117
122
const scaleControlStyle = {
118
123
left : 20 ,
119
124
bottom : 20 ,
@@ -214,10 +219,15 @@ const Map = ({
214
219
type : 'LineString' ,
215
220
} ;
216
221
if ( points . coordinates . length > 2 ) {
217
- const newViewport = computeBBoxViewport ( bbox ( points ) , mapViewport ) ;
222
+ const mapContainer = mapRef . current ?. getContainer ( ) ;
223
+ const newViewport = computeBBoxViewport ( bbox ( points ) , mapViewport , {
224
+ width : mapContainer ?. clientWidth ,
225
+ height : mapContainer ?. clientHeight ,
226
+ padding : 60 ,
227
+ } ) ;
218
228
dispatch ( updateViewport ( newViewport ) ) ;
219
229
}
220
- } , [ pathGeometry , simulationPathSteps ] ) ;
230
+ } , [ pathGeometry , simulationPathSteps , mapRef ] ) ;
221
231
222
232
return (
223
233
< >
0 commit comments