Skip to content

Commit

Permalink
fixes set_zoom_level and adds draw_path example
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Aug 17, 2023
1 parent 76fe857 commit 913a8e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nicesrt/leaflet.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
this.marker = L.marker(this.target);
this.marker.addTo(this.map);
},
set_zoom(zoom_level) {
set_zoom_level(zoom_level) {
this.map.setZoom(zoom_level);
},
draw_path(path) {
Expand Down
4 changes: 2 additions & 2 deletions nicesrt/leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def set_location(self, location: Tuple[float, float], zoom_level:int=9) -> None:
lat,lon=location
self.run_method('set_location',lat,lon,zoom_level)

def set_zoom(self,zoom_level:int):
self.run_method("set_zoom",zoom_level)
def set_zoom_level(self,zoom_level:int):
self.run_method("set_zoom_level",zoom_level)

def draw_path(self, path: List[Tuple[float, float]]) -> None:
"""Draw a path on the map based on list of lat-long tuples."""
Expand Down
13 changes: 12 additions & 1 deletion nicesrt/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self):
self.locations = {
(48.486375, 8.375567): 'Baiersbronn',
(52.5200, 13.4049): 'Berlin',
(52.37487,9.74168): 'Hannover',
(40.7306, -74.0060): 'New York',
(39.9042, 116.4074): 'Beijing',
(35.6895, 139.6917): 'Tokyo',
Expand All @@ -42,8 +43,17 @@ async def main_page(client: Client):

def on_change_zoom_level(self,_ce):
self.zoom_level=_ce.value
self.map.set_zoom(self.zoom_level)
self.map.set_zoom_level(self.zoom_level)
pass

async def draw_path(self,_ce):
"""
"""
with self.map as geo_map:
locs=list(self.locations.keys())
path=[locs[1],locs[2]]
geo_map.draw_path(path)


async def show_map(self,client:Client):
self.map = leaflet().classes('w-full h-96')
Expand All @@ -52,6 +62,7 @@ async def show_map(self,client:Client):
await client.connected() # wait for websocket connection
selection.set_value(next(iter(self.locations))) # trigger map.set_location with first location in selection
zoom_selection.set_value(self.zoom_level)
ui.button("Path",on_click=self.draw_path)

def run(self):
ui.run(title="map example",reload=False)
Expand Down

0 comments on commit 913a8e1

Please sign in to comment.