diff --git a/app/(tabs)/map.tsx b/app/(tabs)/map.tsx index 899afe3..94dfae8 100644 --- a/app/(tabs)/map.tsx +++ b/app/(tabs)/map.tsx @@ -25,6 +25,7 @@ export default function MapScreen() { const [ typesSet, setTypesSet ] = useState( false ); const [ coordinates, setCoordinates ] = useState( [] ); const [ markers, setMarkers ] = useState( [] ); + const [ activeCalloutId, setActiveCalloutId ] = useState( null ); // Load session useEffect( () => { @@ -38,6 +39,8 @@ export default function MapScreen() { // Load markers and types const loadMarkers = () => { + handleCloseAllCallouts(); + mapRef.current?.getVisibleBounds().then( (bounds) => { Request .post( 'locations', { @@ -70,6 +73,8 @@ export default function MapScreen() { // Enable/disable type const toggleSwitch = (index: any) => { + handleCloseAllCallouts(); + const newData = types.map( (item: any, key: any) => key === index ? { ...item, isEnabled: !item.isEnabled } : item ); @@ -97,6 +102,15 @@ export default function MapScreen() { } ); } + const handleCalloutPress = (id: any) => { + console.log('set active', id); + setActiveCalloutId( id ); + }; + + const handleCloseAllCallouts = () => { + setActiveCalloutId( null ); + }; + return ( @@ -128,12 +142,25 @@ export default function MapScreen() { key={marker.id.toString()} id={marker.id.toString()} coordinate={marker.coordinate} + onSelected={() => handleCalloutPress( marker.id )} > - - - {marker.description + ' - ' + marker.street} - - + <> + + + + + {/*{activeCalloutId === marker.id && (*/} + {/* */} + {/* */} + {/* {marker.description + ' - ' + marker.street}*/} + {/* */} + {/* */} + {/*)}*/} + ) )}