Skip to content

Commit

Permalink
Added handle-draw function opengeos#2
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed May 25, 2021
1 parent 1d1f4f2 commit 5001349
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions leafmap/leafmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def __init__(self, **kwargs):
self.tool_output_ctrl = None
self.layer_control = None
self.draw_control = None
self.user_roi = None
self.user_rois = None
self.draw_features = []

if "height" not in kwargs:
self.layout.height = "600px"
Expand Down Expand Up @@ -68,6 +71,19 @@ def __init__(self, **kwargs):
self.add_control(draw_control)
self.draw_control = draw_control

def handle_draw(target, action, geo_json):
self.user_roi = geo_json
if action == "deleted" and len(self.draw_features) > 0:
self.draw_features.remove(geo_json)
else:
self.draw_features.append(geo_json)
self.user_rois = {
"type": "FeatureCollection",
"features": self.draw_features,
}

draw_control.on_draw(handle_draw)

if "measure_control" not in kwargs:
kwargs["measure_control"] = True
if kwargs["measure_control"]:
Expand Down
3 changes: 3 additions & 0 deletions leafmap/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ def tool_callback(change):
elif tool_name == "eraser":
if m.draw_control is not None:
m.draw_control.clear()
m.user_roi = None
m.user_rois = None
m.draw_features = []
elif tool_name == "whitebox":
import whiteboxgui.whiteboxgui as wbt

Expand Down

0 comments on commit 5001349

Please sign in to comment.