11import { useEffect , useMemo , useRef , useState } from 'react'
22
3- import type { CompareItem , Target } from './api'
3+ import type { CompareItem , InterestingTarget , Target } from './api'
44import { DISABLE_GOOGLE_MAPS } from './config'
55import { loadGoogleMaps } from './googleMaps'
66
@@ -17,6 +17,7 @@ type Props = {
1717 target : Target | null
1818 initialCenter : { lat : number ; lng : number } | null
1919 items : CompareItem [ ]
20+ interestingTargets : InterestingTarget [ ]
2021 selectedListingId : string | null
2122 onSelectListingId : ( id : string ) => void
2223 isPickingTarget : boolean
@@ -56,7 +57,14 @@ const LAPTOP_PIN_SVG = `
5657</svg>
5758` . trim ( )
5859
59- function markerIcon ( kind : 'target' | 'listing' , opts ?: { selected ?: boolean } ) {
60+ const INTERESTING_PIN_SVG = `
61+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
62+ <circle cx="12" cy="12" r="10" fill="#16a34a" stroke="rgba(255,255,255,0.95)" stroke-width="2" />
63+ <path d="M12 6.8l1.6 3.2 3.5.5-2.5 2.4.6 3.4L12 14.7l-3.2 1.7.6-3.4-2.5-2.4 3.5-.5L12 6.8Z" fill="none" stroke="#ffffff" stroke-width="1.5" stroke-linejoin="round" />
64+ </svg>
65+ ` . trim ( )
66+
67+ function markerIcon ( kind : 'target' | 'listing' | 'interesting' , opts ?: { selected ?: boolean } ) {
6068 const selected = opts ?. selected ?? false
6169 if ( kind === 'target' ) {
6270 return {
@@ -65,6 +73,13 @@ function markerIcon(kind: 'target' | 'listing', opts?: { selected?: boolean }) {
6573 anchor : new google . maps . Point ( 20 , 20 ) ,
6674 }
6775 }
76+ if ( kind === 'interesting' ) {
77+ return {
78+ url : svgUrl ( INTERESTING_PIN_SVG ) ,
79+ scaledSize : new google . maps . Size ( 30 , 30 ) ,
80+ anchor : new google . maps . Point ( 15 , 15 ) ,
81+ }
82+ }
6883 const size = selected ? 34 : 30
6984 return {
7085 url : svgUrl ( selected ? HOUSE_PIN_SVG_SELECTED : HOUSE_PIN_SVG ) ,
@@ -77,6 +92,7 @@ export default function MapView({
7792 target,
7893 initialCenter,
7994 items,
95+ interestingTargets,
8096 selectedListingId,
8197 onSelectListingId,
8298 isPickingTarget,
@@ -118,8 +134,14 @@ export default function MapView({
118134 lat : target . lat ,
119135 } ,
120136 ]
121- return [ ...targetPoint , ...listingPoints ]
122- } , [ items , target ] )
137+ const interestingPoints = interestingTargets . map ( ( it ) => ( {
138+ id : it . id ,
139+ kind : 'interesting' as const ,
140+ lng : it . lng ,
141+ lat : it . lat ,
142+ } ) )
143+ return [ ...targetPoint , ...interestingPoints , ...listingPoints ]
144+ } , [ interestingTargets , items , target ] )
123145
124146 useEffect ( ( ) => {
125147 if ( ! containerRef . current ) return
@@ -191,7 +213,7 @@ export default function MapView({
191213 position : { lat : p . lat , lng : p . lng } ,
192214 icon : markerIcon ( p . kind , { selected : isSelected } ) ,
193215 clickable : p . kind === 'listing' && ! isPickingTarget ,
194- zIndex : p . kind === 'target' ? 3 : isSelected ? 2 : 1 ,
216+ zIndex : p . kind === 'target' ? 3 : p . kind === 'interesting' ? 2 : isSelected ? 2 : 1 ,
195217 } )
196218 if ( p . kind === 'listing' && ! isPickingTarget ) {
197219 marker . addListener ( 'click' , ( ) => onSelectListingId ( p . id ) )
0 commit comments