main.py 733 B

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