main.py 679 B

12345678910111213141516171819202122232425
  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. locations = {
  6. (52.5200, 13.4049): 'Berlin',
  7. (40.7306, -74.0060): 'New York',
  8. (39.9042, 116.4074): 'Beijing',
  9. (35.6895, 139.6917): 'Tokyo',
  10. }
  11. selection = None
  12. @ui.page('/', on_page_ready=lambda: selection.set_value(next(iter(locations))))
  13. def main_page():
  14. # NOTE we need to use the on_page_ready event to make sure the page is loaded before we execute javascript
  15. global selection
  16. map = leaflet.map()
  17. selection = ui.select(locations, on_change=map.set_location).style('width: 10em')
  18. ui.run()