@@ -204,7 +204,7 @@ export default function DriveBCMap(props) {
204204 const [ clickedFeature , setClickedFeature ] = useState ( ) ;
205205 const [ staleLinkMessage , setStaleLinkMessage ] = useState ( ) ;
206206 const clickedFeatureRef = useRef ( ) ;
207- const updateClickedFeature = feature => {
207+ const updateClickedFeature = ( feature , center = true ) => {
208208 // Remove highlight from feature on click
209209 if ( feature && feature instanceof Feature && feature . get ( 'highlight' ) ) {
210210 // Remove highlight from feature
@@ -218,7 +218,10 @@ export default function DriveBCMap(props) {
218218
219219 clickedFeatureRef . current = feature ;
220220 setClickedFeature ( feature ) ;
221- updatePosition ( feature ) ;
221+
222+ if ( center ) {
223+ updatePosition ( feature ) ;
224+ }
222225 } ;
223226
224227 const handleSetShowRouteObjs = ( value ) => {
@@ -373,11 +376,24 @@ export default function DriveBCMap(props) {
373376 geometry = feature . getProperties ( ) . altFeature . getGeometry ( ) ; // use the point feature's geometry
374377 }
375378
376- if ( mousePointXClicked < 390 ) {
379+ // Center if panel from bottom or clicked within 390px from left of the screen
380+ if ( mousePointXClicked < 390 || smallScreen ) {
377381 const zoom = mapView . current . getZoom ( ) ;
378382 const coords = geometry . flatCoordinates ;
379- if ( smallScreen ) {
380- setZoomPanAnchored ( mapRef , mapView , zoom , coords ) ;
383+ const mapWidth = mapRef . current ?. getSize ( ) ?. [ 0 ] ?? 0 ;
384+
385+ // Use anchored pan if panel from bottom or screen smaller than 1000px
386+ const shouldUseAnchoredPan = mapWidth < 1000 || smallScreen ;
387+
388+ // Center on top half of the screen, if panel open from bottom
389+ const anchorYFraction = ! viewportLargeScreen || isCamDetail ? 0.25 : 0.5 ;
390+
391+ // Center on right side of screen minus 390px panel, if panel open from left
392+ const anchorXFraction = anchorYFraction !== 0.25 ? ( ( ( mapWidth - 390 ) / 2 ) + 390 ) / mapWidth : 0.5 ;
393+
394+ if ( shouldUseAnchoredPan ) {
395+ setZoomPanAnchored ( mapRef , mapView , zoom , coords , anchorXFraction , anchorYFraction ) ;
396+
381397 } else {
382398 setZoomPan ( mapView , zoom , coords ) ;
383399 }
0 commit comments