Passed
Push — development ( 2f9cbb...cdc56b )
by Peter
09:24 queued 15s
created

frontend/src/helpers/map/renders.tsx   A

Complexity

Total Complexity 5
Complexity/F 0

Size

Lines of Code 60
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 56
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 5
mnd 5
bc 5
fnc 0
bpm 0
cpm 0
noi 0
1
import { Popup, Marker, Polygon, Tooltip} from 'react-leaflet';
2
import { Scooter, Zone } from './leaflet-types'
3
import { LatLngTuple } from 'leaflet';
4
import { iconStation } from '../config';
5
import { giveMarkerPin } from '../config';
6
7
const zoneColors = (zoneType: string) => {
8
    switch(zoneType) {
9
        case "speed":
10
            return {color :"purple"}
11
        case "parking":
12
            return {color :"green"}
13
        case "charging":
14
            return {color :"blue"}
15
        default:
16
            return {color :"red"}
17
    }
18
}
19
20
const renderScooterMarkers = (scooterData: Scooter[])=>   (
21
    scooterData?.map((scooter, index) => (
22
    <Marker key={index} icon={giveMarkerPin(index)} position={[scooter.latitude, scooter.longitude]}>
23
        <Popup>
24
            <p className="my-0 py-0">id: {scooter.id}</p>
25
            <p className="my-0 py-0">batteryLevel: {scooter.batteryLevel}</p>
26
            <p className="my-0 py-0">status: {scooter.status}</p>
27
            <p className="my-0 py-0">longitude: {scooter.longitude}</p>
28
            <p className="my-0 py-0">latitude: {scooter.latitude}</p>
29
            <p className="my-0 py-0">updatedAt: {scooter.updatedAt}</p>
30
            <p className="my-0 py-0">createdAt: {scooter.createdAt}</p>
31
        </Popup>
32
    </Marker>))
33
    );
34
35
const renderStationMarkers  = (stationPositions: LatLngTuple[]) =>  (
36
    stationPositions?.map((position, index) => (
37
    <Marker key={index} position={position} icon={iconStation}>
38
        <Popup>
39
        { position }
40
        </Popup>
41
    </Marker>))
42
    );
43
44
const renderPolygons = ( zoneData: Zone[] ) =>  (
45
    zoneData?.map((zone, index) => (
46
        <Polygon pathOptions={zoneColors(zone.type)} positions={zone.polygon.map(point => [point.lat, point.lng])} key={index}>
47
            <Tooltip direction="bottom" offset={[0, 20]} opacity={1} >
48
                <p>Name: {zone.name}</p>
49
                <p>Id: {zone.id}</p>
50
                <p>Type: {zone.type}</p>
51
                { zone.bikes && <p>Number of bikes: {zone.bikes?.length} </p> }
52
53
                <p></p>
54
            </Tooltip>
55
        </Polygon>
56
    ))
57
);
58
59
export { renderScooterMarkers, renderStationMarkers, renderPolygons }
60