@@ -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 ) ;
94
+ const mapContainer = useMemo ( ( ) => mapRef . current ?. getContainer ( ) , [ mapRef . current ] ) ;
93
95
94
96
const pathGeometry = useMemo (
95
97
( ) => geometry || pathProperties ?. geometry ,
96
98
[ pathProperties , geometry ]
97
99
) ;
98
100
99
- const mapViewport = useMemo (
100
- ( ) =>
101
- isReadOnly && pathGeometry ? computeBBoxViewport ( bbox ( pathGeometry ) , viewport ) : viewport ,
102
- [ isReadOnly , pathGeometry , viewport ]
103
- ) ;
101
+ const mapViewport = useMemo ( ( ) => {
102
+ if ( isReadOnly && pathGeometry ) {
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 , mapContainer ] ) ;
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,14 @@ const Map = ({
214
219
type : 'LineString' ,
215
220
} ;
216
221
if ( points . coordinates . length > 2 ) {
217
- const newViewport = computeBBoxViewport ( bbox ( points ) , mapViewport ) ;
222
+ const newViewport = computeBBoxViewport ( bbox ( points ) , mapViewport , {
223
+ width : mapContainer ?. clientWidth ,
224
+ height : mapContainer ?. clientHeight ,
225
+ padding : 60 ,
226
+ } ) ;
218
227
dispatch ( updateViewport ( newViewport ) ) ;
219
228
}
220
- } , [ pathGeometry , simulationPathSteps ] ) ;
229
+ } , [ pathGeometry , simulationPathSteps , mapContainer ] ) ;
221
230
222
231
return (
223
232
< >
0 commit comments