main.py 590 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env python3
  2. from nicegui import ui
  3. import leaflet
  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. selection = None
  11. @ui.page('/', on_page_ready=lambda: selection.set_value(next(iter(locations))))
  12. def main_page():
  13. # NOTE we need to use the on_page_ready event to make sure the page is loaded before we execute javascript
  14. global selection
  15. map = leaflet.map()
  16. selection = ui.select(locations, on_change=map.set_location).style('width: 10em')
  17. ui.run()