diff --git a/frontend/__tests__/unit/pages/Home.test.tsx b/frontend/__tests__/unit/pages/Home.test.tsx index 24aa1d9e42..40d7be542c 100644 --- a/frontend/__tests__/unit/pages/Home.test.tsx +++ b/frontend/__tests__/unit/pages/Home.test.tsx @@ -114,7 +114,7 @@ describe('Home', () => { render() await waitFor(() => { - expect(screen.getByText('OWASP Chapters Nearby')).toBeInTheDocument() + expect(screen.getByText('OWASP Chapters Worldwide')).toBeInTheDocument() }) }) diff --git a/frontend/src/components/CardDetailsPage.tsx b/frontend/src/components/CardDetailsPage.tsx index b8200f6b45..3bfb4243e6 100644 --- a/frontend/src/components/CardDetailsPage.tsx +++ b/frontend/src/components/CardDetailsPage.tsx @@ -67,6 +67,7 @@ const DetailsCard = ({
{ const mapRef = useRef(null) + const markerClusterRef = useRef(null) - const normalizedData = useMemo(() => { + const chapters = useMemo(() => { return geoLocData.map((chapter) => ({ lat: '_geoloc' in chapter ? chapter._geoloc.lat : chapter.geoLocation.lat, lng: '_geoloc' in chapter ? chapter._geoloc.lng : chapter.geoLocation.lng, @@ -24,14 +27,13 @@ const ChapterMap = ({ })) }, [geoLocData]) - //for reference: https://leafletjs.com/reference.html#map-example useEffect(() => { if (!mapRef.current) { mapRef.current = L.map('chapter-map', { - worldCopyJump: false, // Prevents the map from wrapping around the world + worldCopyJump: false, maxBounds: [ - [-90, -180], // Southwest corner of the map bounds (latitude, longitude) - [90, 180], // Northeast corner of the map bounds (latitude, longitude) + [-90, -180], + [90, 180], ], maxBoundsViscosity: 1.0, }).setView([20, 0], 2) @@ -43,7 +45,6 @@ const ChapterMap = ({ } const map = mapRef.current - // Remove previous markers map.eachLayer((layer) => { if (layer instanceof L.Marker || layer instanceof L.LayerGroup) { @@ -51,21 +52,21 @@ const ChapterMap = ({ } }) + // Create a new marker cluster group const markerClusterGroup = L.markerClusterGroup() const bounds: [number, number][] = [] - normalizedData.forEach((chapter) => { + markerClusterRef.current = markerClusterGroup + chapters.forEach((chapter) => { const markerIcon = new L.Icon({ - iconAnchor: [12, 41], // Anchor point + iconAnchor: [12, 41], iconRetinaUrl: '/img/marker-icon-2x.png', - iconSize: [25, 41], // Default size for Leaflet markers + iconSize: [25, 41], iconUrl: '/img/marker-icon.png', - popupAnchor: [1, -34], // Popup position relative to marker - shadowSize: [41, 41], // Shadow size + popupAnchor: [1, -34], + shadowSize: [41, 41], shadowUrl: '/img/marker-shadow.png', }) - const marker = L.marker([chapter.lat, chapter.lng], { - icon: markerIcon, - }) + const marker = L.marker([chapter.lat, chapter.lng], { icon: markerIcon }) const popup = L.popup() const popupContent = document.createElement('div') popupContent.className = 'popup-content' @@ -81,12 +82,19 @@ const ChapterMap = ({ map.addLayer(markerClusterGroup) - if (bounds.length > 0) { - map.fitBounds(bounds as L.LatLngBoundsExpression, { maxZoom: 10 }) + if (showLocal) { + const maxNearestChapters = 5 + const localChapters = chapters.slice(0, maxNearestChapters - 1) + const localBounds = L.latLngBounds(localChapters.map((ch) => [ch.lat, ch.lng])) + const firstChapter = chapters[0] + + const maxZoom = 7 + map.setView([firstChapter.lat, firstChapter.lng], maxZoom) + map.fitBounds(localBounds, { maxZoom: maxZoom }) } - }, [normalizedData]) + }, [chapters, showLocal]) - return
+ return
} export default ChapterMap diff --git a/frontend/src/pages/Chapters.tsx b/frontend/src/pages/Chapters.tsx index 1ddc36948f..58b6195cce 100644 --- a/frontend/src/pages/Chapters.tsx +++ b/frontend/src/pages/Chapters.tsx @@ -92,6 +92,7 @@ const ChaptersPage = () => { {chapters.length > 0 && ( )} diff --git a/frontend/src/pages/Home.tsx b/frontend/src/pages/Home.tsx index 4b2282cb76..07a264223a 100644 --- a/frontend/src/pages/Home.tsx +++ b/frontend/src/pages/Home.tsx @@ -55,7 +55,7 @@ export default function Home() { indexName: 'chapters', query: '', currentPage: 1, - hitsPerPage: 25, + hitsPerPage: 1000, } const data: AlgoliaResponseType = await fetchAlgoliaData( searchParams.indexName, @@ -205,14 +205,15 @@ export default function Home() {
-
-

OWASP Chapters Nearby

+

OWASP Chapters Worldwide

+
{