main.py 708 B

12345678910111213141516171819202122
  1. #!/usr/bin/env python3
  2. from leaflet import leaflet # this module wraps the JavaScript lib leafletjs.com into an easy-to-use NiceGUI element
  3. from nicegui import Client, ui
  4. locations = {
  5. (52.5200, 13.4049): 'Berlin',
  6. (40.7306, -74.0060): 'New York',
  7. (39.9042, 116.4074): 'Beijing',
  8. (35.6895, 139.6917): 'Tokyo',
  9. }
  10. @ui.page('/')
  11. async def main_page(client: Client):
  12. map = leaflet().classes('w-full h-96')
  13. selection = ui.select(locations, on_change=lambda e: map.set_location(e.value)).classes('w-40')
  14. await client.connected() # wait for websocket connection
  15. selection.set_value(next(iter(locations))) # trigger map.set_location with first location in selection
  16. ui.run()