Skip to content

Commit

Permalink
center map for neuburg students (#353)
Browse files Browse the repository at this point in the history
* fix typo

* Center map for neuburg students

* 🚸 improve map centering

* 🔇 remove fetchMode log

* ⚰️ remove debug code

* ♻️ improve faculty extraction

---------

Co-authored-by:
Philipp Opheys <[email protected]>
Robert Eggl <[email protected]>
  • Loading branch information
ElmarLienerth authored Oct 31, 2023
1 parent e052d73 commit a67a29b
Show file tree
Hide file tree
Showing 14 changed files with 238 additions and 135 deletions.
33 changes: 25 additions & 8 deletions rogue-thi-app/components/RoomMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useRouter } from 'next/router'

import Form from 'react-bootstrap/Form'

import { AttributionControl, CircleMarker, FeatureGroup, LayerGroup, LayersControl, MapContainer, Polygon, Popup, TileLayer } from 'react-leaflet'
import { AttributionControl, CircleMarker, FeatureGroup, LayerGroup, LayersControl, MapContainer, Polygon, Popup, TileLayer, useMap } from 'react-leaflet'

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faLinux } from '@fortawesome/free-brands-svg-icons'
Expand Down Expand Up @@ -43,7 +43,8 @@ const FLOOR_ORDER = [
'1',
'EG'
]
const DEFAULT_CENTER = [48.76630, 11.43330]
const INGOLSTADT_CENTER = [48.76630, 11.43330]
const NEUBURG_CENTER = [48.73227, 11.17261]

const SPECIAL_COLORS = [...new Set(Object.values(SPECIAL_ROOMS).map(x => x.color))]

Expand All @@ -55,12 +56,13 @@ export default function RoomMap ({ highlight, roomData }) {
const router = useRouter()
const searchField = useRef()
const location = useLocation()
const userKind = useUserKind()
const { userKind, userFaculty } = useUserKind()
const [searchText, setSearchText] = useState(highlight || '')
const [availableRooms, setAvailableRooms] = useState(null)

const { t, i18n } = useTranslation(['rooms', 'api-translations'])

const mapCenter = userFaculty && userFaculty === 'Nachhaltige Infrastruktur' ? NEUBURG_CENTER : INGOLSTADT_CENTER
/**
* WILL BE USED WITH NEW TILE SERVICE
const systemDark = window.matchMedia('(prefers-color-scheme: dark)').matches
Expand Down Expand Up @@ -109,7 +111,7 @@ export default function RoomMap ({ highlight, roomData }) {
*/
const [filteredRooms, center] = useMemo(() => {
if (!searchText) {
return [allRooms, DEFAULT_CENTER]
return [allRooms, mapCenter]
}

const cleanedText = searchText.toUpperCase().trim()
Expand All @@ -126,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] : DEFAULT_CENTER
const filteredCenter = count > 0 ? [lon / count, lat / count] : mapCenter

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

useEffect(() => {
async function load () {
Expand Down Expand Up @@ -258,6 +266,14 @@ export default function RoomMap ({ highlight, roomData }) {
)
}

const Recenter = ({ position }) => {
const map = useMap()
useEffect(() => {
map.setView(position)
}, [map, position])
return null
}

return (
<>
<Form className={styles.searchForm} onSubmit={e => unfocus(e)}>
Expand Down Expand Up @@ -299,9 +315,10 @@ export default function RoomMap ({ highlight, roomData }) {
// https://github.com/Leaflet/Leaflet/issues/3184
tap={false}
>
<Recenter position={center} />

<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
2 changes: 1 addition & 1 deletion rogue-thi-app/components/cards/ExamsCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function ExamsCard () {
const router = useRouter()
const time = useTime()
const [exams, setExams] = useState(null)
const userKind = useUserKind()
const { userKind } = useUserKind()

useEffect(() => {
async function load () {
Expand Down
2 changes: 1 addition & 1 deletion rogue-thi-app/components/cards/RoomCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useTranslation } from 'next-i18next'
export default function RoomCard () {
const router = useRouter()
const [filterResults, setFilterResults] = useState(null)
const userKind = useUserKind()
const { userKind } = useUserKind()
const { t } = useTranslation('dashboard')

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion rogue-thi-app/components/page/AppTabbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { i18n } from 'next-i18next'
*/
export default function AppTabbar () {
const router = useRouter()
const userKind = useUserKind()
const { userKind } = useUserKind()

return (
<>
Expand Down
269 changes: 162 additions & 107 deletions rogue-thi-app/data/course-short-names.json
Original file line number Diff line number Diff line change
@@ -1,108 +1,163 @@
{
"Business School": [
"AM",
"BW",
"BZ",
"DB",
"EDB",
"FC",
"GBM",
"HM",
"IG",
"LSM",
"MPS",
"MV",
"RCM",
"RM",
"SB",
"SR"
],

"Elektro- und Informationstechnik": [
"AR",
"AU",
"AVE",
"BEE",
"EI",
"EM",
"ES",
"IA",
"MT",
"ROB"
],

"Institut für Akademische Weiterbildung": [
"AC",
"BB",
"BDB",
"BE",
"BF",
"BG",
"BI",
"BL",
"BM",
"BP",
"BT",
"CM",
"DBM",
"EF",
"GM",
"HR",
"IB",
"IBI",
"IM",
"INC",
"INT",
"LE",
"MIM",
"MiS",
"SBE",
"SM",
"WD"
],

"Informatik": [
"CAI",
"CLS",
"FF",
"IF",
"IK",
"IW",
"KI",
"UX",
"UXM"
],

"Maschinenbau": [
"EE",
"EEE",
"ESY",
"ET",
"FT",
"ING",
"LT",
"MB",
"MFT",
"ML",
"MLT",
"MRE",
"MS",
"MTE",
"MWT",
"NUM",
"TE",
"TT"
],

"Wirtschaftsingenieurwesen": [
"AP",
"EG",
"EGM",
"GFT",
"MWI",
"TB",
"TD",
"WI",
"WIB"
]
}
"_source": {
"courses": "https://outlook.thi.de/ groups search",
"poKey": "https://www.thi.de/hochschule/ueber-uns/hochschulorganisation/stabsstelle-recht/",
"date": "2023-10-30"
},
"Business School": {
"poKey": "satzungen-business-school",
"courses": [
"AM",
"BW",
"BZ",
"DB",
"EDB",
"FC",
"GBM",
"GBU",
"HM",
"IG",
"LSM",
"MPS",
"MV",
"RCE",
"RCM",
"RM",
"SB",
"SR"
]
},
"Elektro- und Informationstechnik": {
"poKey": "satzungen-fakultaet-elektro-und-informationstechnik",
"courses": [
"AI",
"AR",
"AU",
"AVE",
"BEE",
"BME",
"EI",
"EM",
"ES",
"IA",
"MT",
"PAT",
"ROB"
]
},
"Institut für Akademische Weiterbildung": {
"poKey": "satzungen-studienfakultaet-iaw",
"courses": [
"AC",
"AKI",
"BB",
"BDB",
"BE",
"BF",
"BG",
"BI",
"BL",
"BM",
"BNP",
"BP",
"BT",
"CM",
"DBM",
"EF",
"GE",
"GEM",
"GM",
"GMM",
"HR",
"IB",
"IBI",
"IBU",
"IM",
"INC",
"INT",
"LE",
"MIM",
"MiS",
"SBE",
"SC",
"SM",
"SSM",
"UN",
"WD"
]
},
"Informatik": {
"poKey": "satzungen-fakultaet-informatik",
"courses": [
"BE",
"BMI",
"CAI",
"CLS",
"CSE",
"CSI",
"FF",
"IF",
"IK",
"IW",
"KI",
"UX",
"UXM"
]
},
"Maschinenbau": {
"poKey": "satzungen-fakultaet-maschinenbau",
"courses": [
"AP",
"BIO",
"DL",
"EE",
"EEE",
"ESY",
"ET",
"FT",
"ING",
"LT",
"MB",
"MFT",
"ML",
"MLT",
"MRE",
"MTE",
"MWT",
"MS",
"MTE",
"MWT",
"NUM",
"TE",
"TT",
"WI",
"WTW"
]
},
"Nachhaltige Infrastruktur": {
"poKey": "satzungen-fakultaet-nachhaltige-infrastruktur",
"courses": [
"NB",
"NUM",
"SCE",
"WIB"
]
},
"Wirtschaftsingenieurwesen": {
"poKey": "satzungen-fakultaet-wirtschaftsingenieurwesen",
"courses": [
"AP",
"DES",
"DL",
"DS",
"EG",
"EGM",
"GFT",
"MWI",
"TB",
"TD",
"WI",
"WIB"
]
}
}
Loading

0 comments on commit a67a29b

Please sign in to comment.