-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from MartinGerritsen/feature/puntos-recogidas-map
feat(Map) adding pickup points to map
- Loading branch information
Showing
5 changed files
with
184 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { MapPin } from 'lucide-react'; | ||
|
||
const PickupPoint = ({ point }) => { | ||
return ( | ||
<div className="bg-white p-4 rounded-lg shadow-lg border-l-4 border-blue-500"> | ||
<div className="flex flex-col sm:flex-row justify-between items-start gap-2 mb-4"> | ||
<div> | ||
<h3 className="text-lg font-bold text-blue-600 break-words">{point.name}</h3> | ||
<div className="flex items-start gap-2 text-gray-600 mt-1"> | ||
<MapPin className="h-4 w-4 flex-shrink-0 mt-1" /> | ||
<a | ||
href={`https://maps.google.com/?q=${point.location}`} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className="text-sm break-words text-blue-500 underline" | ||
> | ||
{point.location} | ||
</a> | ||
</div> | ||
</div> | ||
<div> | ||
<span className={`px-3 py-1 rounded-full text-sm font-medium whitespace-nowrap mr-2 bg-purple-300`}> | ||
Referencia: {point.id} | ||
</span> | ||
<span className="px-3 py-1 rounded-full bg-blue-100 text-blue-800 text-sm font-medium whitespace-nowrap"> | ||
{point.status === 'active' ? 'Activo' : 'Inactivo'} | ||
</span> | ||
</div> | ||
</div> | ||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 text-sm mt-4"> | ||
<div className="break-words"> | ||
<span className="font-semibold">Ciudad:</span> {point.city} | ||
</div> | ||
{point.contact_name && ( | ||
<div className="break-words"> | ||
<span className="font-semibold">Responsable:</span> {point.contact_name} | ||
</div> | ||
)} | ||
{point.contact_phone && ( | ||
<div className="break-words"> | ||
<span className="font-semibold">Teléfono:</span> {point.contact_phone} | ||
</div> | ||
)} | ||
{point.accepted_items && ( | ||
<div className="col-span-1 sm:col-span-2 break-words"> | ||
<span className="font-semibold">Acepta:</span>{' '} | ||
{Array.isArray(point.accepted_items) ? point.accepted_items.join(', ') : point.accepted_items} | ||
</div> | ||
)} | ||
{point.urgent_needs && ( | ||
<div className="col-span-1 sm:col-span-2"> | ||
<span className="font-semibold">Necesidades urgentes:</span> | ||
<p className="text-gray-700 mt-1 break-words">{point.urgent_needs}</p> | ||
</div> | ||
)} | ||
{point.schedule && ( | ||
<div className="col-span-1 sm:col-span-2"> | ||
<span className="font-semibold">Horario:</span> | ||
<p className="text-gray-700 mt-1 break-words">{point.schedule}</p> | ||
</div> | ||
)} | ||
{point.additional_info && ( | ||
<div className="col-span-1 sm:col-span-2 bg-gray-50 p-3 rounded"> | ||
<span className="font-semibold">Información adicional:</span> | ||
<p className="text-gray-700 mt-1 break-words"> | ||
{typeof point.additional_info === 'string' | ||
? point.additional_info | ||
: JSON.stringify(point.additional_info)} | ||
</p> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PickupPoint; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { FC, useEffect, useRef } from 'react'; | ||
import maplibregl from 'maplibre-gl'; | ||
import 'maplibre-gl/dist/maplibre-gl.css'; | ||
|
||
const urgencyToColor = { | ||
alta: '#ef4444', //text-red-500 | ||
media: '#f59e0b', //text-amber-500 | ||
baja: '#10b981', //text-emerald-500 | ||
}; | ||
|
||
type MapProps = { | ||
center?: [number, number]; | ||
zoom?: number; | ||
markers?: { | ||
coordinates: [number, number]; | ||
urgency: 'alta' | 'media' | 'baja'; | ||
descriptionHTML: string; | ||
width: number; | ||
}[]; | ||
}; | ||
|
||
const Map: FC<MapProps> = ({ center = [0, 0], zoom = 2, markers = [] }) => { | ||
const mapContainerRef = useRef<HTMLDivElement | null>(null); | ||
const mapRef = useRef<maplibregl.Map | null>(null); | ||
const markerRefs = useRef<maplibregl.Marker[]>([]); | ||
|
||
useEffect(() => { | ||
if (!mapRef.current) { | ||
mapRef.current = new maplibregl.Map({ | ||
container: mapContainerRef.current!, | ||
style: 'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json', | ||
center: center, | ||
zoom: zoom, | ||
}); | ||
mapRef.current.addControl(new maplibregl.NavigationControl(), 'top-right'); | ||
} else { | ||
// Update center and zoom when props change | ||
mapRef.current.setCenter(center); | ||
mapRef.current.setZoom(zoom); | ||
} | ||
|
||
// Clear existing markers | ||
markerRefs.current.forEach((marker) => marker.remove()); | ||
markerRefs.current = []; | ||
|
||
// Add new markers | ||
markers.forEach((markerData) => { | ||
const marker = new maplibregl.Marker({ | ||
color: urgencyToColor[markerData.urgency], | ||
}) | ||
.setLngLat(markerData.coordinates) | ||
.setPopup( | ||
new maplibregl.Popup({ | ||
className: 'map-popup', | ||
maxWidth: `${markerData.width}px`, | ||
anchor: 'left', | ||
}).setHTML(markerData.descriptionHTML) | ||
) | ||
.addTo(mapRef.current!); | ||
|
||
markerRefs.current.push(marker); | ||
}); | ||
|
||
// Clean up function to remove markers only | ||
return () => { | ||
markerRefs.current.forEach((marker) => marker.remove()); | ||
markerRefs.current = []; | ||
}; | ||
}, [center, zoom, markers]); | ||
|
||
return <div ref={mapContainerRef} style={{ width: '100%', height: '75vh' }} />; | ||
}; | ||
|
||
export default Map; |