I'm using react-map-gl to render a map showing differents locations with markers.
When clicking on this markers it shows a popup with all the details from this location.
I'd like when I click on the popup that is redirects me to the page of the location.
My code for the markers and popup :
return (
<ReactMapGL
{...viewport}
mapboxApiAccessToken={mapboxKey}
onViewportChange={(viewport) => {
setViewport(viewport);
}}
mapStyle="mapbox://styles/medhisavarybouge/cki8vpz0l0iee1aoiw7r69bwr"
>
{router.pathname === "/pdrs/[slug]" &&
data.map((location) => {
const { id, latitude, longitude } = location;
return (
<Marker key={id} latitude={latitude} longitude={longitude}>
{/* si on supprime le bouton l'image de s'affiche pas sur la map*/}
<button></button>
<Image src="/images/map-pin.svg" alt="" width={40} height={40} />
</Marker>
);
})}
{router.pathname === "/points-de-rencontre-sportive" &&
data.map((pdrs) => {
const { id, latitude, longitude } = pdrs;
return (
<Marker key={id} latitude={latitude} longitude={longitude}>
<button
className={style.markerBtn}
onClick={(event) => {
event.preventDefault();
setSelectedPDRS(pdrs);
}}
>
<Image
src="/images/map-pin.svg"
alt=""
width={40}
height={40}
/>
</button>
</Marker>
);
})}
{selectedPDRS && (
<Popup
latitude={selectedPDRS.latitude}
longitude={selectedPDRS.longitude}
onClose={() => {
setSelectedPDRS(null);
}}
closeButton={true}
closeOnclick={false}
captureClick={true}
>
<div
className={style.selectedPDRS}
onMouseDown={() => {
router.push(`/pdrs/${selectedPDRS.slug}`);
}}
>
<Image
src={imageUrl}
alt={selectedPDRS.micro_activity_name}
width={100}
height={100}
/>
<div className={style.selectedPDRSdetails}>
<div className={style.selectedPDRStitle}>
<h4>
{selectedPDRS.installation_name}
</h4>
<span>
{selectedPDRS.name)}
</span>
<span>
{selectedPDRS.micro_activity_name)}
</span>
</div>
<div className={style.selectedPDRSdate}>
{selectedPDRS.start_date &&
selectedPDRS.start_date +
" - " +
selectedPDRS.duration +
" - " +
selectedPDRS.access_type}
</div>
<div className={style.selectedPDRSbadge}>
{badge[selectedPDRS.category]}
</div>
</div>
</div>
</Popup>
)}
</ReactMapGL>
);
I had to put a onMouseDown on my popup div so that the redirection works.
With an onclick it doesn't work. The popup just closed.
The problem is for the responsive.
I think the onClick is the same as touching the phone screen but the onMouseDown does not do anything on phone so the users can't be redirect to the page.
How can I make the popup redirection work with a onClick ?
