Plot recent packets on map.
This commit is contained in:
78
api_app.py
78
api_app.py
@ -113,12 +113,31 @@ def index():
|
||||
station['time_ago'] = timeago.format(station['last_heard_unix'], datetime.datetime.now())
|
||||
|
||||
|
||||
# Map stuff
|
||||
frames_locs = list(filter(lambda x: x['latitude'] != None, frames))
|
||||
# Make a GeoJSON
|
||||
geojs = json.dumps({
|
||||
"type": "FeatureCollection",
|
||||
"features":[
|
||||
{
|
||||
"type":"Feature",
|
||||
"geometry": {
|
||||
"type":"Point",
|
||||
"coordinates":[frame['longitude'], frame['latitude']],
|
||||
},
|
||||
"properties":frame,
|
||||
|
||||
} for frame in frames_locs
|
||||
]
|
||||
})
|
||||
|
||||
return render_template('index.html',
|
||||
station_call = config['Settings']['station_call'],
|
||||
station_lat = config['Settings']['station_lat'],
|
||||
station_lon = config['Settings']['station_lon'],
|
||||
frames = frames,
|
||||
stations = stations)
|
||||
stations = stations,
|
||||
geojs = geojs)
|
||||
|
||||
@api_app.route('/map')
|
||||
def map():
|
||||
@ -126,31 +145,50 @@ def map():
|
||||
# Get the default list of frames from the API
|
||||
frames = json.loads(requests.get(config['Settings']['base_url']+"/packets").text)['data']
|
||||
|
||||
# Make markers for all the frames
|
||||
id_counter = 0
|
||||
markers = ''
|
||||
marker_ids = []
|
||||
for frame in frames:
|
||||
if frame['latitude'] != None:
|
||||
# Create unique ID for each marker
|
||||
idd = 'frame' + str(id_counter)
|
||||
id_counter += 1
|
||||
frames_locs = list(filter(lambda x: x['latitude'] != None, frames))
|
||||
|
||||
# Create each marker
|
||||
markers += "var {idd} = L.marker([{latitude}, {longitude}]);\
|
||||
{idd}.addTo(map).bindTooltip('{from_ssid}', permanent=true).openTooltip();".format(idd=idd, latitude=frame['latitude'],\
|
||||
longitude=frame['longitude'],
|
||||
from_ssid=frame['from'],
|
||||
created=frame['created'])
|
||||
# Try to make a list of markers for Leaflet, but not working
|
||||
marker_ids.append(idd)
|
||||
# Make a GeoJSON
|
||||
geojs = json.dumps({
|
||||
"type": "FeatureCollection",
|
||||
"features":[
|
||||
{
|
||||
"type":"Feature",
|
||||
"geometry": {
|
||||
"type":"Point",
|
||||
"coordinates":[frame['longitude'], frame['latitude']],
|
||||
},
|
||||
"properties":frame,
|
||||
|
||||
} for frame in frames_locs
|
||||
]
|
||||
})
|
||||
|
||||
# Make markers for all the frames
|
||||
# id_counter = 0
|
||||
# markers = ''
|
||||
# marker_ids = []
|
||||
# for frame in frames:
|
||||
# if frame['latitude'] != None:
|
||||
# # Create unique ID for each marker
|
||||
# idd = 'frame' + str(id_counter)
|
||||
# id_counter += 1
|
||||
|
||||
# # Create each marker
|
||||
# markers += "var {idd} = L.marker([{latitude}, {longitude}]);\
|
||||
# {idd}.addTo(map).bindTooltip('{from_ssid}', permanent=true).openTooltip();".format(idd=idd, latitude=frame['latitude'],\
|
||||
# longitude=frame['longitude'],
|
||||
# from_ssid=frame['from'],
|
||||
# created=frame['created'])
|
||||
# # Try to make a list of markers for Leaflet, but not working
|
||||
# marker_ids.append(idd)
|
||||
|
||||
|
||||
return render_template('map.html',
|
||||
station_lat = config['Settings']['station_lat'],
|
||||
station_lon = config['Settings']['station_lon'],
|
||||
markers = markers,
|
||||
marker_ids = marker_ids)
|
||||
station_call = config['Settings']['station_call'],
|
||||
#markers = markers,
|
||||
geojs = geojs)
|
||||
|
||||
class Packets(Resource):
|
||||
def get(self):
|
||||
|
Reference in New Issue
Block a user