main.py 645 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env python3
  2. from nicegui import ui
  3. import leaflet
  4. @ui.page('/')
  5. def main_page():
  6. map = leaflet.map()
  7. locations = {
  8. (52.5200, 13.4049): 'Berlin',
  9. (40.7306, -74.0060): 'New York',
  10. (39.9042, 116.4074): 'Beijing',
  11. (35.6895, 139.6917): 'Tokyo',
  12. }
  13. selection = ui.select(locations, on_change=map.set_location).style('width: 10em')
  14. yield # all code below is executed after page is ready
  15. default_location = next(iter(locations))
  16. # this will trigger the map.set_location event; which is js and must be run after page is ready
  17. selection.set_value(default_location)
  18. ui.run()