MainMap.jsx 1.3 KB
Newer Older
1
import React, { useMemo } from "react";
2

3
import uuid from "uuid/v4";
4
import BaseMap from "./BaseMap";
5

6
import "./map.scss";
7
import UniversityService from "../../services/data/UniversityService";
Florent Chehab's avatar
Florent Chehab committed
8
import { useSelectedUniversities } from "../../hooks/wrappers/useSelectedUniversities";
9
10

const MAIN_MAP_ID = uuid();
11
12

/**
13
 * Main map of the application (map tab)
14
 */
15
function MainMap() {
Florent Chehab's avatar
Florent Chehab committed
16
  const [listUnivSel] = useSelectedUniversities();
17

18
  const univSelection = useMemo(() => {
19
    const out = [];
20
    const universities = UniversityService.getUniversities();
Alexandre Lanceart's avatar
Alexandre Lanceart committed
21

22
23
    universities.forEach(university => {
      const univ = UniversityService.getUniversityById(university.id);
Florent Chehab's avatar
Florent Chehab committed
24

25
      if (univ) {
26
        out.push({
Florent Chehab's avatar
Florent Chehab committed
27
28
          univName: univ.name,
          univLogoUrl: univ.logo,
29
30
          cityName: univ.city,
          countryName: univ.country,
Gautier D's avatar
Gautier D committed
31
32
          main_campus_lat: parseFloat(univ.main_campus_lat),
          main_campus_lon: parseFloat(univ.main_campus_lon),
Florent Chehab's avatar
Florent Chehab committed
33
          univId: univ.id,
34
35
36
          selected:
            listUnivSel === null ||
            (listUnivSel.length > 0 && listUnivSel.indexOf(univ.id) > -1)
Florent Chehab's avatar
Florent Chehab committed
37
        });
Florent Chehab's avatar
Florent Chehab committed
38
      }
39
    });
Florent Chehab's avatar
Florent Chehab committed
40

41
    return out;
Florent Chehab's avatar
Florent Chehab committed
42
  }, [listUnivSel]);
43

44
  // create all the markers
45
  return <BaseMap id={MAIN_MAP_ID} universities={univSelection} />;
46
}
47

48
MainMap.propTypes = {};
49

50
export default MainMap;