leaflet.py 715 B

1234567891011121314151617181920
  1. from pathlib import Path
  2. from typing import Tuple
  3. from nicegui import ui
  4. from nicegui.dependencies import register_vue_component
  5. from nicegui.element import Element
  6. register_vue_component('leaflet', Path(__file__).parent / 'leaflet.js')
  7. class leaflet(Element):
  8. def __init__(self) -> None:
  9. super().__init__('leaflet')
  10. self.use_component('leaflet')
  11. ui.add_head_html('<link href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" rel="stylesheet"/>')
  12. ui.add_head_html('<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"></script>')
  13. def set_location(self, location: Tuple[float, float]) -> None:
  14. self.run_method('set_location', location[0], location[1])