def create_route(data): path = data.get('points', []) geo = GeoJSON() for i, _ in enumerate(path[:-1]): if path[i + 1] is None: path[i + 1] = path[i] elif path[i] is not None: route, _ = router.find_route(path[i], path[i + 1]) if route: start, end = route[0], route[-1] geo.add_point(lon=start[0], lat=start[1], props={ 'title': path[i]['tags'].get('name', path[i]['id']) }) geo.add_point(lon=end[0], lat=end[1], props={ 'title': path[i + 1]['tags'].get( 'name', path[i + 1]['id']) }) geo.add_line_string(route, {"style": {"color": next(color)}}) return geo.data
def main(start, end, coords, coorde): router = Router('./map.osm') print('Would you like to search by name or by coordinates?') print('(1) Name') print('(2) Coordinates') index = click.prompt('', type=int) start_point, end_point = None, None if index == 1: if not start: start = click.prompt('What is your starting point?') start_point = router.find_point_by_name_cli(start) if not start_point: return print('Starting point not set') if not end: end = click.prompt('What is your destination?') end_point = router.find_point_by_name_cli(end) if not end_point: return print('Destination not set') elif index == 2: if not coords: coords = get_float_tuple('What is your starting point? [format="lat lon"]') start_point = router.find_point_by_coords(dict(lat=coords[0], lon=coords[1])) if not coorde: coorde = get_float_tuple('What is your destination? [format="lat lon"]').split(' ') end_point = router.find_point_by_coords(dict(lat=coorde[1], lon=coorde[1])) else: print('Invalid input') return route, _ = router.find_route(start_point, end_point) if route: print("Route found") geo = GeoJSON() geo.add_line_string(route) geo.add_point(lon=route[0][0], lat=route[0][1], props={ "title": "Start" }) geo.add_point(lon=route[-1][0], lat=route[-1][1], props={ "title": "End" }) js_file = '' with open('./map.template.js',encoding='utf-8') as f: js_file = Template(f.read()).safe_substitute(geojson=geo.data) f.close() with open('./map_client/index.js', 'w', encoding='utf-8') as f: f.write(js_file) f.close() webbrowser.open_new_tab(Path('./map_client/index.html').resolve().as_uri())