-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Map zoom_control variable to also allow string to set position #1884
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -150,8 +150,8 @@ class Map(JSCSSMixin, MacroElement): | |||||||||
Forces Leaflet to not use hardware-accelerated CSS 3D | ||||||||||
transforms for positioning (which may cause glitches in some | ||||||||||
rare environments) even if they're supported. | ||||||||||
zoom_control : bool, default True | ||||||||||
Display zoom controls on the map. | ||||||||||
zoom_control : bool or position string, default True | ||||||||||
Display zoom controls on the map, eventually specifying its position. | ||||||||||
**kwargs | ||||||||||
Additional keyword arguments are passed to Leaflets Map class: | ||||||||||
https://leafletjs.com/reference.html#map | ||||||||||
|
@@ -210,6 +210,10 @@ class Map(JSCSSMixin, MacroElement): | |||||||||
L.control.scale().addTo({{ this.get_name() }}); | ||||||||||
{%- endif %} | ||||||||||
|
||||||||||
{%- if this.zoom_control_position %} | ||||||||||
L.control.zoom( { position: {{ this.zoom_control|tojson }} } ).addTo({{ this.get_name() }}); | ||||||||||
{%- endif %} | ||||||||||
|
||||||||||
{% if this.objects_to_stay_in_front %} | ||||||||||
function objects_in_front() { | ||||||||||
{%- for obj in this.objects_to_stay_in_front %} | ||||||||||
|
@@ -252,7 +256,7 @@ def __init__( | |||||||||
no_touch: bool = False, | ||||||||||
disable_3d: bool = False, | ||||||||||
png_enabled: bool = False, | ||||||||||
zoom_control: bool = True, | ||||||||||
zoom_control: Union[bool, str] = True, | ||||||||||
**kwargs: TypeJsonValue, | ||||||||||
): | ||||||||||
super().__init__() | ||||||||||
|
@@ -284,10 +288,17 @@ def __init__( | |||||||||
self.crs = crs | ||||||||||
self.control_scale = control_scale | ||||||||||
|
||||||||||
# Zoom control position specified ? | ||||||||||
if isinstance(zoom_control, str): | ||||||||||
self.zoom_control_position = True | ||||||||||
self.zoom_control = zoom_control | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe useful to add a check here for valid values? Now if a users makes an error, they just get a grey screen. For example something like:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had considered introducing a check on valid position values but looking at various plugins I could not find such a check so I thought it was considered as unnecessary ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand, this code base grew quite organically over time, so it's not always consistent. Thanks for putting it in! |
||||||||||
else: | ||||||||||
self.zoom_control_position = False | ||||||||||
|
||||||||||
self.options = parse_options( | ||||||||||
max_bounds=max_bounds_array, | ||||||||||
zoom=zoom_start, | ||||||||||
zoom_control=zoom_control, | ||||||||||
zoom_control=False if self.zoom_control_position else zoom_control, | ||||||||||
prefer_canvas=prefer_canvas, | ||||||||||
**kwargs, | ||||||||||
) | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.