#import geemap
# Map = geemap.Map()
# Map
import ipywidgets as widgets
widget_width = "250px"
padding = "0px 0px 0px 5px" # upper, right, bottom, left
icon: https://fontawesome.com/v4.7.0/icons/ #we can check from this website which fonts are available
toolbar_button = widgets.ToggleButton(
value=False,
tooltip="Toolbar",
icon="camera",
#layout=widgets.Layout(width="28px", height="28px", padding=padding), #if we remove this line we get a larger background
)
toolbar_button
toolbar_button = widgets.ToggleButton(
value=False,
tooltip="Toolbar",
icon="gear",
layout=widgets.Layout(width="28px", height="28px", padding=padding), #if we remove this line we get a larger backgro
)
toolbar_button
import ipyleaflet
#adding widget crontol from pcalss 12b
control = ipyleaflet.WidgetControl(widget = toolbar_button, position = 'topright')
m = ipyleaflet.Map(center=[40, -100], zoom =4)
m
m.add_control(control) #see how the icon is displlayed on the toip map --This is the way how leafmap was constructed
import leafmap
m2 = leafmap.Map()
m2
# toolbar_button.layout.width = "28px"
toolbar_button.value #if selected the button added is goint o return true
False
close_button = widgets.ToggleButton(
value=False,
tooltip="Close the tool",
icon="times",
button_style="primary",
layout=widgets.Layout(height="28px", width="28px", padding=padding),
)
close_button
close_button = widgets.ToggleButton(
value=False,
tooltip="Close the tool",
icon="times",
button_style="danger", #styles from https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20Styling.html
layout=widgets.Layout(height="28px", width="28px", padding=padding),
)
close_button
#if you click in one type of icon all of them get selected they are connected
widgets.HBox([close_button, toolbar_button]) #horizontal box makes a list with location
widgets.VBox([close_button, toolbar_button]) #horizontal box makes a list with location
#suing children to reduce a menu to change things dinamically
box = widgets.HBox()
box.children = [close_button, toolbar_button]
box
box.children =[toolbar_button]
box
checkbox = widgets.Checkbox(
description="Checkbox",
indent=False,
layout=widgets.Layout(padding=padding, width=widget_width),
)
checkbox
#widgets. hit tab and you will be able to see alll widgets
checkbox.value #always each widget has a value
False
widgets.Checkbox() #this is a class inside the parethesis hit shift+tab to see the documentation
dropdown = widgets.Dropdown(
options=["Option 1", "Option 2", "Option 3"],
value=None, #to allow show eevrything unselected if you remove the line the first will be selected
description="Dropdown:",
layout=widgets.Layout(width=widget_width, padding=padding),
style={"description_width": "initial"},#MEANS YOU DONT HAVE SPACE TO TEH LEFT OF THE WIDGET
)
dropdown
int_slider = widgets.IntSlider(
min=1,
max=100,
description="Int Slider: ",
readout=True,
continuous_update=True,
layout=widgets.Layout(width=widget_width, padding=padding),
style={"description_width": "initial"},
)
int_slider
#we can add and step
int_slider = widgets.IntSlider(
min=0,
max=100,
step= 5,
description="Int Slider: ",
readout=True,
continuous_update=True,
layout=widgets.Layout(width=widget_width, padding=padding),
style={"description_width": "initial"},
)
int_slider
float_slider = widgets.FloatSlider(
min=1,
max=100,
description="Float Slider: ",
readout=True, #to enable values on the slider
continuous_update=True,
layout=widgets.Layout(width=widget_width, padding=padding),
style={"description_width": "initial"},
)
float_slider
color = widgets.ColorPicker(
concise=False, #if we put to true the hegx colour is not shown
description="Color:",
value="white",
style={"description_width": "initial"},
layout=widgets.Layout(width=widget_width, padding=padding),
)
color
#example of bad documentaion
color.value
'white'
text = widgets.Text(
value="",
description="Textbox:",
placeholder="Enter sth.",
style={"description_width": "initial"},
layout=widgets.Layout(width=widget_width, padding=padding),
)
text
textarea = widgets.Textarea(
# value='https://google.com', if you add this by default therewill be atext so in oder to seeyour place holder we need to rmeove the text first
placeholder="Placeholder", #enter teh value you want
layout=widgets.Layout(width=widget_width),
)
textarea
buttons = widgets.ToggleButtons(
value=None, #To select sth by default example a basemap
options=["Apply", "Reset", "Close"],
tooltips=["Apply the algorithm", "Reset", "Close"],
button_style="primary",
)
buttons.style.button_width = "50px"
buttons
buttons.value
Most powerful widget we can display images abutton widgets anything in there¶
output = widgets.Output(layout=widgets.Layout(width=widget_width, padding=padding))
with output:
output.clear_output()
print("Running ...")
output
output.clear_output()
#if this is run this sends again the output to the widget with the new mewssage
with output:
#output.clear_output() #without the clear output will create a result for each iteration
print("Running. Plase wait")
output
with output:
output.clear_output()
print("Running ...")#this line of code will display the buttons
display(buttons)
output
with output:
output.clear_output()
print("Running ...")#this line of code will display the buttons
display(buttons)
display(checkbox)
output
#we can add an step¶
int_slider = widgets.IntSlider( min=0, max=100, step= 5, description="Int Slider: ", readout=True, continuous_update=True, layout=widgets.Layout(width=widget_width, padding=padding), style={"description_width": "initial"}, ) int_slider#we can add and step
int_slider = widgets.IntSlider( min=0, max=100, step= 5, description="Int Slider: ", readout=True, continuous_update=True, layout=widgets.Layout(width=widget_width, padding=padding), style={"description_width": "initial"}, ) int_sliderHow to put everything together
#we can add and step
int_slider = widgets.IntSlider(
value = 4, #default
min=1,
max=24,
step= 1,
description="Zoom: ",
readout=True,
continuous_update=True,
layout=widgets.Layout(width=widget_width, padding=padding),
style={"description_width": "initial"},
)
int_slider
toolbar_widget = widgets.VBox()
toolbar_widget.children = [
widgets.HBox([close_button, toolbar_button]), #nested box to add more columns
checkbox,
int_slider,
float_slider,
dropdown,
text,
color,
textarea,
buttons,
output,
]
toolbar_widget
control1 = ipyleaflet.WidgetControl(widget=toolbar_widget, position ='topright')
m =ipyleaflet.Map(center=[40, -100], zoom=4)
m.add_control(control1)
m
Lets make it interactive - how to link with map¶
#lets analize this behaviour map has anttribute called zooom
m.zoom=3 #This changes alll associated maps
We need to link the attribute with the intslider
widgets.jslink((m, 'zoom'), (int_slider, 'value'))
Link(source=(Map(center=[40, -100], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title'…
m #now zoom controls are usable
lets add this possiblity atttribute
int_slider = widgets.IntSlider(
value = 4, #default
min=1,
max=25,
step= 1,
description="Zoom: ",
readout=True,
continuous_update=True,
layout=widgets.Layout(width=widget_width, padding=padding),
style={"description_width": "initial"},
)
int_slider
toolbar_widget = widgets.VBox()
toolbar_widget.children = [
widgets.HBox([close_button, toolbar_button]), #nested box to add more columns
checkbox,
int_slider,
float_slider,
dropdown,
text,
color,
textarea,
buttons,
output,
]
toolbar_widget
m =ipyleaflet.Map(center=[40, -100], zoom=4, scroll_wheel_zoom=True)
m.add_control(control1)
widgets.jslink((m, 'zoom'), (int_slider, 'value'))
Link(source=(Map(center=[40, -100], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title'…
m
m.center
[40, -100]
widgets.jslink((m, "center") , (text, 'value')) #adding the center attribute to the textbox
Link(source=(Map(center=[40, -100], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title'…
Adding multiple maps¶
out = widgets.Output()
with out:
display(m)
#Adding by running this cell many times we get as many maps synchronized
box =widgets.HBox()
box.children = [m,m,m]
box
#def remove_widget()