|
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
|
|
|
|