Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e33a663
added
Yashgupta9330 Mar 4, 2025
20423b2
undo
Yashgupta9330 Mar 4, 2025
a9f6f15
fixed
Yashgupta9330 Mar 4, 2025
078359f
Merge branch 'main' into chapters3
Yashgupta9330 Mar 4, 2025
5bec21e
Merge branch 'main' into chapters3
Yashgupta9330 Mar 4, 2025
554ea25
Merge branch 'main' into chapters3
Yashgupta9330 Mar 5, 2025
44f1e68
Merge branch 'main' into chapters3
Yashgupta9330 Mar 5, 2025
c117eed
fixed
Yashgupta9330 Mar 5, 2025
18d706d
fixed
Yashgupta9330 Mar 5, 2025
cfd2ba0
fixed
Yashgupta9330 Mar 5, 2025
588b6d3
fixed
Yashgupta9330 Mar 5, 2025
57ba179
fixed
Yashgupta9330 Mar 5, 2025
5506cd2
fixed
Yashgupta9330 Mar 5, 2025
7512537
Merge branch 'OWASP:main' into chapters3
Yashgupta9330 Mar 5, 2025
94cbe84
fixed
Yashgupta9330 Mar 5, 2025
e4b6235
Merge branch 'main' into chapters3
Yashgupta9330 Mar 5, 2025
b624ad5
pulled
Yashgupta9330 Mar 5, 2025
19bafd6
fixed
Yashgupta9330 Mar 5, 2025
10c13bf
fixed
Yashgupta9330 Mar 5, 2025
7e05dce
fixed
Yashgupta9330 Mar 5, 2025
b12b9e8
fixed
Yashgupta9330 Mar 5, 2025
3ad5ebd
Merge branch 'main' into chapters3
Yashgupta9330 Mar 6, 2025
1153df0
Merge branch 'main' into chapters3
Yashgupta9330 Mar 6, 2025
44d0dc4
Merge branch 'main' into chapters3
Yashgupta9330 Mar 7, 2025
5ddf29b
fixed
Yashgupta9330 Mar 7, 2025
259f9a6
fixed
Yashgupta9330 Mar 7, 2025
79c6947
Merge branch 'main' into chapters3
Yashgupta9330 Mar 7, 2025
2906b11
fixed spacing
Yashgupta9330 Mar 7, 2025
be6a43a
Merge branch 'main' into chapters3
Yashgupta9330 Mar 7, 2025
cf99a17
Merge branch 'main' into chapters3
Yashgupta9330 Mar 8, 2025
0d21b0e
Merge branch 'main' into chapters3
kasya Mar 9, 2025
7e771d3
Merge branch 'main' into chapters3
Yashgupta9330 Mar 9, 2025
5132dba
Update dependencies
arkid15r Mar 10, 2025
426d54d
Issue resolved : #1068 Correction to overflow of name in usercard (#…
KaranNegi20Feb Mar 10, 2025
ac33cf3
Update dependencies
arkid15r Mar 10, 2025
079044d
Fixed issue #1035 Correct redirection and Links have valid URLs. (#1071)
KaranNegi20Feb Mar 11, 2025
817dfa6
🔍 Integrate Event Search from GraphQL (#1064)
rishyym0927 Mar 11, 2025
fc55505
Update CI/CD
arkid15r Mar 11, 2025
946fd76
Update dependencies
arkid15r Mar 11, 2025
9ecb739
Update dependencies
arkid15r Mar 11, 2025
4fe3e89
Update code
arkid15r Mar 11, 2025
ff8d3c4
Merge branch 'main' into chapters3
arkid15r Mar 11, 2025
3e5e00b
Update code
arkid15r Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 54 additions & 17 deletions frontend/src/components/ChapterMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const ChapterMap = ({
style: React.CSSProperties
}) => {
const mapRef = useRef<L.Map | null>(null)
const markerClusterRef = useRef<L.MarkerClusterGroup | null>(null)

const normalizedData = useMemo(() => {
return geoLocData.map((chapter) => ({
Expand All @@ -24,48 +25,60 @@ 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)

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors',
className: 'map-tiles',
}).addTo(mapRef.current)
}

const map = mapRef.current

// Remove previous markers
map.eachLayer((layer) => {
if (layer instanceof L.Marker || layer instanceof L.LayerGroup) {
map.removeLayer(layer)
}
})

// Create a new marker cluster group
const markerClusterGroup = L.markerClusterGroup()
const bounds: [number, number][] = []
normalizedData.forEach((chapter) => {
markerClusterRef.current = markerClusterGroup

// Validate and filter out invalid coordinates
const validChapters = normalizedData.filter(
(chapter) =>
chapter.lat !== null &&
chapter.lng !== null &&
!isNaN(chapter.lat) &&
!isNaN(chapter.lng) &&
chapter.lat >= -90 &&
chapter.lat <= 90 &&
chapter.lng >= -180 &&
chapter.lng <= 180
)

// Create markers for all chapters
validChapters.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'
Expand All @@ -81,12 +94,36 @@ const ChapterMap = ({

map.addLayer(markerClusterGroup)

if (bounds.length > 0) {
map.fitBounds(bounds as L.LatLngBoundsExpression, { maxZoom: 10 })
// Determine map view based on 6th index (index 5)
try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate a bit more on the logic in this block? I think it works, but I'm just not sure what's going on.
Why do we set view to a sixth chapter? Why not 1st for example? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose the sixth location as the reference point for the default zoom because the data is sorted in a way where the sixth location provides a good central point to cover the surrounding five locations on the map. Zooming to this position ensures that all five prior locations are visible while still maintaining an optimal view of the area. Using the first index would focus too much on a single location, potentially causing some of the other important locations to be out of the initial zoom view.

if (validChapters.length >= 6) {
// Specifically target the 6th chapter (index 5)
const sixthChapter = validChapters[5]

// Take the first 6 chapters for bounds
const localChapters = validChapters.slice(0, 6)
const latLngs = localChapters.map((ch) => [ch.lat, ch.lng])
const localBounds = L.latLngBounds(latLngs)

// Set view to 6th chapter and fit bounds of first 6
map.setView([sixthChapter.lat, sixthChapter.lng], 6)
map.fitBounds(localBounds, { maxZoom: 10 })
} else if (validChapters.length > 0) {
// Fallback if fewer than 6 chapters
const firstChapter = validChapters[0]
map.setView([firstChapter.lat, firstChapter.lng], 6)
} else if (bounds.length > 0) {
map.fitBounds(bounds)
} else {
map.setView([20, 0], 2)
}
} catch (error) {
console.error('Error setting map view:', error)
map.setView([20, 0], 2)
}
}, [normalizedData])

return <div id="chapter-map" className="rounded-lg dark:bg-[#212529]" style={style} />
return <div id="chapter-map" style={style} />
}

export default ChapterMap
8 changes: 7 additions & 1 deletion frontend/src/pages/Chapters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import SearchPageLayout from 'components/SearchPageLayout'

const ChaptersPage = () => {
const [geoLocData, setGeoLocData] = useState<ChapterTypeAlgolia[]>([])


const {
items: chapters,
isLoaded,
Expand All @@ -27,6 +29,7 @@ const ChaptersPage = () => {
pageTitle: 'OWASP Chapters',
})


useEffect(() => {
const fetchData = async () => {
const searchParams = {
Expand All @@ -35,14 +38,17 @@ const ChaptersPage = () => {
currentPage: 1,
hitsPerPage: 1000,
}

const data: AlgoliaResponseType<ChapterTypeAlgolia> = await fetchAlgoliaData(
searchParams.indexName,
searchParams.query,
searchParams.currentPage,
searchParams.hitsPerPage
searchParams.hitsPerPage,
)

setGeoLocData(data.hits)
}

fetchData()
}, [])

Expand Down
Loading