-
Notifications
You must be signed in to change notification settings - Fork 0
/
topspotmap.py
76 lines (68 loc) · 3.04 KB
/
topspotmap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from kivy_garden.mapview import MapView
from kivy.clock import Clock
from kivymd.app import MDApp
from spotmarker import SpotMarker
from kivy.utils import platform
class TopSpotMap(MapView):
getting_spots_timer = None
spot_names = []
def start_getting_spots_in_fov(self):
# After one second, get the spots in the field of view
try:
self.getting_spots_timer.cancel()
except:
pass
self.getting_spots_timer = Clock.schedule_once(
self.get_spots_in_fov, 0.5)
def get_spots_in_fov(self, *args):
min_lat, min_lon, max_lat, max_lon = self.get_bbox()
app = MDApp.get_running_app()
sql_statement = f"SELECT * FROM skatespots WHERE x > {min_lon} AND x < {max_lon} AND y > {min_lat} AND y < {max_lat}"
app.cursor.execute(sql_statement)
spots = app.cursor.fetchall()
print('[' + '\x1b[1;35;40m' + 'INFO' + '\x1b[0m' +
' ] [Mapview ] ' + "Seeing: " + '\x1b[1;35;40m' + f"{self.get_bbox()}" +
'\x1b[0m')
print('[' + '\x1b[1;35;40m' + 'INFO' + '\x1b[0m' +
' ] [Mapview ] ' + "Spots in FOV: " + '\x1b[1;35;40m' + f"{len(spots)}" +
'\x1b[0m')
for spot in spots:
name = spot[1]
if name in self.spot_names:
pass
else:
self.add_spot(spot)
# update gps coordinates on screen
if platform == "android" or platform == "ios":
coordinate_label = MDApp.get_running_app().root.ids.coordinate_label
gps_blinker = MDApp.get_running_app().root.ids.mapview.ids.blinker
coordinate_label.text = f"GPS Coordinates:\nlat: {round(gps_blinker.lat, 4)}\nlon: {round(gps_blinker.lon, 4)}\nSpots in FOV: {len(spots)}"
else:
# update gps coordinates on screen
coordinate_label = MDApp.get_running_app().root.ids.coordinate_label
coordinate_label.text = f"GPS Coordinates:\nlat: {round((min_lat+max_lat)/2, 4)}\nlon: {round((min_lon+max_lon)/2, 4)}\nSpots in FOV: {len(spots)}"
def add_spot(self, spot):
print('[' + '\x1b[1;34;40m' + 'INFO' + '\x1b[0m' +
' ] [Mapview ] ' + "Creating Marker for: " +
'\x1b[1;34;40m' + f"{spot[1]}" + '\x1b[0m' + f" @ {spot[3]}, {spot[2]}")
# set color for marker
if spot[14] == "Skatepark":
marker_source = "lib/map_marker2_32x32.png"
elif spot[14] == "Plaza":
marker_source = "lib/map_marker3_32x32.png"
elif spot[14] == "Stairs":
marker_source = "lib/map_marker9_32x32.png"
else:
marker_source = "lib/map_marker_32x32.png"
# init marker for spots
lat, lon = spot[3], spot[2]
marker = SpotMarker()
marker.lat = lat
marker.lon = lon
marker.source = marker_source
marker.spot_data = spot
# add marker to map
self.add_widget(marker)
# register added markers
name = spot[1]
self.spot_names.append(name)