('carto')
const formatCurrency = (value: number) => {
return new Intl.NumberFormat('en-CA', {
style: 'currency',
currency: 'CAD',
minimumFractionDigits: 0,
maximumFractionDigits: 0,
}).format(value)
}
const getMarkerColor = (status: string) => {
switch (status) {
case 'active':
return '#10B981' // green
case 'pending':
return '#F59E0B' // orange
case 'sold':
return '#EF4444' // red
default:
return '#3B82F6' // blue
}
}
const createCustomIcon = (property: any) => {
const color = getMarkerColor(property.status)
const priceText = formatCurrency(property.price).replace('CAD', '').trim()
return L.divIcon({
html: `
${priceText}
`,
className: 'custom-property-marker',
iconSize: [120, 30],
iconAnchor: [60, 30]
})
}
useEffect(() => {
if (!mapContainerRef.current || mapRef.current) return
// Initialize the map
mapRef.current = L.map(mapContainerRef.current).setView([56.1304, -96.0000], 4)
// Add selected tile provider
const provider = tileProviders[currentTileProvider]
tileLayerRef.current = L.tileLayer(provider.url, {
attribution: provider.attribution,
subdomains: 'abcd',
maxZoom: 19
}).addTo(mapRef.current)
// Add property markers
sampleProperties.forEach(property => {
const marker = L.marker(property.coordinates, {
icon: createCustomIcon(property)
}).addTo(mapRef.current!)
marker.on('click', () => {
onPropertySelect(property)
// Fly to the clicked property
mapRef.current?.setView(property.coordinates, 12, { animate: true })
})
markersRef.current.push(marker)
})
// Cleanup function
return () => {
if (mapRef.current) {
mapRef.current.remove()
mapRef.current = null
}
markersRef.current = []
}
}, [onPropertySelect, currentTileProvider])
// Handle tile provider changes
useEffect(() => {
if (!mapRef.current || !tileLayerRef.current) return
// Remove current tile layer
mapRef.current.removeLayer(tileLayerRef.current)
// Add new tile layer
const provider = tileProviders[currentTileProvider]
tileLayerRef.current = L.tileLayer(provider.url, {
attribution: provider.attribution,
subdomains: 'abcd',
maxZoom: 19
}).addTo(mapRef.current)
}, [currentTileProvider])
// Update marker styles when selectedProperty changes
useEffect(() => {
markersRef.current.forEach((marker, index) => {
const property = sampleProperties[index]
const isSelected = selectedProperty?.id === property.id
const icon = createCustomIcon(property)
if (isSelected) {
// Make selected marker larger and add pulse effect
icon.options.html = icon.options.html?.replace(
'box-shadow: 0 2px 4px rgba(0,0,0,0.2);',
'box-shadow: 0 2px 4px rgba(0,0,0,0.2), 0 0 0 4px rgba(59, 130, 246, 0.3); transform: scale(1.1);'
)
}
marker.setIcon(icon)
})
}, [selectedProperty])
const flyToProperty = (coordinates: [number, number]) => {
if (mapRef.current) {
mapRef.current.setView(coordinates, 12, { animate: true })
}
}
const resetView = () => {
if (mapRef.current) {
mapRef.current.setView([56.1304, -96.0000], 4, { animate: true })
}
}
return (
<>
{/* Map Style Selector */}
>
)
}