@@ -7,11 +7,11 @@ interface Marker {
77 lat : number ;
88 lng : number ;
99 title : string ;
10+ organisationSlug : string ; // ✅ must match field used in ServiceCard
1011 icon ?: string ;
1112 organisation ?: string ;
1213 serviceName ?: string ;
1314 distanceKm ?: number ;
14- link ?: string ;
1515}
1616
1717interface Props {
@@ -52,7 +52,17 @@ export default function GoogleMap({ center, markers, zoom }: Props) {
5252 const newMarkers : google . maps . Marker [ ] = [ ] ;
5353
5454 markers . forEach ( ( markerData ) => {
55- const { lat, lng, title, icon, organisation, serviceName, distanceKm, link } = markerData ;
55+ const {
56+ id,
57+ lat,
58+ lng,
59+ title,
60+ icon,
61+ organisation,
62+ serviceName,
63+ distanceKm,
64+ organisationSlug, // ✅ corrected
65+ } = markerData ;
5666
5767 const gMarker = new google . maps . Marker ( {
5868 position : { lat, lng } ,
@@ -61,29 +71,39 @@ export default function GoogleMap({ center, markers, zoom }: Props) {
6171 icon : icon || undefined ,
6272 } ) ;
6373
64- if ( link ) {
65- gMarker . addListener ( 'click' , ( ) => {
66- window . location . href = link ;
67- } ) ;
68- } else {
69- const htmlContent = `
70- <div style="font-size:14px;max-width:220px;">
71- <strong>${ organisation ? `<a href="/organisation-slug" target="_blank" rel="noopener noreferrer">${ organisation } </a>` : 'Unknown Organisation' } </strong><br/>
72- ${ serviceName ?? 'Unnamed service' } <br/>
73- ${ distanceKm ?. toFixed ( 1 ) ?? '?' } km away
74- </div>
75- ` ;
76-
77- const infoWindow = new google . maps . InfoWindow ( { content : htmlContent } ) ;
78-
79- gMarker . addListener ( 'click' , ( ) => {
80- if ( infoWindowRef . current ) {
81- infoWindowRef . current . close ( ) ;
74+ const destination = `/find-help/organisation/${ organisationSlug } ` ;
75+ const infoId = `info-${ id } ` ;
76+
77+ const htmlContent = `
78+ <div
79+ id="${ infoId } "
80+ style="font-size:14px;max-width:220px;cursor:pointer;padding:4px;"
81+ >
82+ <strong style="color:#0b9b75;">${ organisation ?? 'Unknown Organisation' } </strong><br/>
83+ ${ serviceName ?? 'Unnamed service' } <br/>
84+ ${ distanceKm ?. toFixed ( 1 ) ?? '?' } km away
85+ </div>
86+ ` ;
87+
88+ const infoWindow = new google . maps . InfoWindow ( { content : htmlContent } ) ;
89+
90+ gMarker . addListener ( 'click' , ( ) => {
91+ if ( infoWindowRef . current ) {
92+ infoWindowRef . current . close ( ) ;
93+ }
94+
95+ infoWindowRef . current = infoWindow ;
96+ infoWindow . open ( map , gMarker ) ;
97+
98+ google . maps . event . addListenerOnce ( infoWindow , 'domready' , ( ) => {
99+ const el = document . getElementById ( infoId ) ;
100+ if ( el ) {
101+ el . addEventListener ( 'click' , ( ) => {
102+ window . location . href = destination ;
103+ } ) ;
82104 }
83- infoWindowRef . current = infoWindow ;
84- infoWindow . open ( map , gMarker ) ;
85105 } ) ;
86- }
106+ } ) ;
87107
88108 newMarkers . push ( gMarker ) ;
89109 } ) ;
0 commit comments