leaflet_documentation.py 1.0 KB

12345678910111213141516171819202122232425262728
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.leaflet)
  4. def main_demo() -> None:
  5. m = ui.leaflet(location=(51.505, -0.09))
  6. ui.label().bind_text_from(m, 'location', lambda location: f'Location: {location[0]:.3f}, {location[1]:.3f}')
  7. ui.label().bind_text_from(m, 'zoom', lambda zoom: f'Zoom: {zoom}')
  8. with ui.grid(columns=2):
  9. ui.button('London', on_click=lambda: m.set_location((51.505, -0.090)))
  10. ui.button('Berlin', on_click=lambda: m.set_location((52.520, 13.405)))
  11. ui.button(icon='zoom_in', on_click=lambda: m.set_zoom(m.zoom + 1))
  12. ui.button(icon='zoom_out', on_click=lambda: m.set_zoom(m.zoom - 1))
  13. @doc.demo('Layers and markers', '''
  14. The following demo shows how to add custom layers and markers to a map.
  15. ''')
  16. def layers_and_markers() -> None:
  17. m = ui.leaflet(location=(51.505, -0.090))
  18. m.tile_layer(url_template=r'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png')
  19. ui.button(icon='add_location', on_click=lambda: m.marker(location=m.location))
  20. doc.reference(ui.leaflet)