Skip to content

Commit

Permalink
🚸 improve map centering
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildmodeOne committed Oct 29, 2023
1 parent 9ee2dc2 commit e745a12
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions rogue-thi-app/components/RoomMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,24 @@ export default function RoomMap ({ highlight, roomData }) {
const roomOnlySearcher = room => getProp(room, 'Raum').startsWith(cleanedText)
const filtered = allRooms.filter(/^[A-Z](G|[0-9E]\.)?\d*$/.test(cleanedText) ? roomOnlySearcher : fullTextSearcher)

// this doesn't affect the search results itself, but ensures that the map is centered on the correct campus
const showNeuburg = userFaculty === 'Nachhaltige Infrastruktur' || cleanedText.includes('N')
const campusRooms = filtered.filter(x => x.properties.Raum.includes('N') === showNeuburg)

const centerRooms = campusRooms.length > 0 ? campusRooms : filtered

let lon = 0
let lat = 0
let count = 0
filtered.forEach(x => {
centerRooms.forEach(x => {
lon += x.coordinates[0][0]
lat += x.coordinates[0][1]
count += 1
})
const filteredCenter = count > 0 ? [lon / count, lat / count] : mapCenter

return [filtered, filteredCenter]
}, [searchText, allRooms, mapCenter])
}, [searchText, allRooms, mapCenter, userFaculty])

useEffect(() => {
async function load () {
Expand Down Expand Up @@ -313,7 +319,6 @@ export default function RoomMap ({ highlight, roomData }) {

<TileLayer
attribution={t('rooms.map.attribution')}
// url={`https://tiles-eu.stadiamaps.com/tiles/alidade_smooth${isDark() ? '_dark' : ''}/{z}/{x}/{y}{r}.png`}
url="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
maxNativeZoom={19}
maxZoom={21}
Expand Down
1 change: 1 addition & 0 deletions rogue-thi-app/lib/hooks/user-kind.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function useUserKind () {

useEffect(() => {
async function loadFaculty () {
// return 'Nachhaltige Infrastruktur'
return await API.getFaculty()
}

Expand Down

0 comments on commit e745a12

Please sign in to comment.