@@ -28,8 +28,6 @@ const MapPane = (props: {
2828
2929 const element = selection ? elementLookup [ selection ] : null ;
3030
31- console . log ( element , 'SELECTION' ) ;
32-
3331 return (
3432 < div
3533 className = { cn (
@@ -56,7 +54,7 @@ export const VenueMap = () => {
5654
5755 const isHoveredOrSelected = hoveredElement || selectedElement ;
5856
59- const panzoomInstance = usePanzoom ( 'venue-map' ) ;
57+ const { panzoomInstance, panAndZoomLevels } = usePanzoom ( 'venue-map' ) ;
6058
6159 useEffect ( ( ) => {
6260 // Wait for next frame to ensure SVG is fully rendered
@@ -130,10 +128,46 @@ export const VenueMap = () => {
130128 id : string ,
131129 event : React . MouseEvent < SVGElement >
132130 ) => {
133- console . log ( 'SVG element clicked:' , id ) ;
131+ // console.log('SVG element clicked:', id);
134132 if ( elementLookup [ id ] ) {
135133 setSelectedElement ( selectedElement === id ? null : id ) ;
136- console . log ( 'Element position data:' , elementLookup [ id ] ) ;
134+
135+ // Center on and zoom to the selected element
136+ if ( panzoomInstance ) {
137+ const targetZoom = 2 ; // Fixed zoom level
138+ const element = elementLookup [ id ] ;
139+
140+ // Get container dimensions
141+ const container = document . getElementById ( 'venue-map' ) ;
142+ if ( container ) {
143+ const containerRect = container . getBoundingClientRect ( ) ;
144+
145+ // Calculate the pan position to center the element
146+ // We need to account for the current zoom level and calculate where to pan
147+ const centerX = containerRect . width / 2 ;
148+ const centerY = containerRect . height / 2 ;
149+
150+ // Calculate the offset needed to center the element
151+ // const panX = centerX - element.centerX * targetZoom;
152+ // const panY = centerY - element.centerY * targetZoom;
153+
154+ // First reset zoom to target level, then pan to center
155+ panzoomInstance . smoothZoomAbs ( centerX , centerY , targetZoom ) ;
156+ // panzoomInstance.smoothMoveTo(centerX, centerY);
157+
158+ // console.log(panzoomInstance, 'panzoom instance');
159+ console . log ( element , 'element' ) ;
160+ console . log ( panAndZoomLevels , 'pan and zoom levels' ) ;
161+
162+ // After zoom completes, pan to center the element
163+ // setTimeout(() => {
164+ // panzoomInstance.moveTo(panX, panY);
165+ // }, 300); // Adjust timing based on your zoom animation duration
166+ }
167+ }
168+
169+ // console.log(elementLookup[id], 'element lookup');
170+ // console.log('Element position data:', elementLookup[id]);
137171 }
138172 } ;
139173
0 commit comments