Skip to content
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

UI elements should be removed from layout static #1631

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cartoframes/viz/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,14 @@ def map_index(self, map_index):
"""Set session"""
self._map_index = map_index

def reset_legends(self, parent_map):
if parent_map.layer_selector:
def reset_ui(self, parent_map):
if parent_map.is_static:
# Remove legends/widgets if the map is static
self.legends = []
self.widgets = []
self.legends_info = []
self.widgets_info = []
elif parent_map.layer_selector:
if self.style.default_legend:
self.style.default_legend.set_title('')
self.legends = self._init_legends(self.legends, self.default_legend, '')
Expand Down
17 changes: 8 additions & 9 deletions cartoframes/viz/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _get_publication_html(self):
viz_map.layer_defs = []

for layer in layers:
layer.reset_legends(self._maps[layer.map_index])
layer.reset_ui(self._maps[layer.map_index])
layer_def = layer._get_layer_def()
self._maps[layer.map_index].layer_defs.append(layer_def)

Expand Down Expand Up @@ -233,21 +233,20 @@ def _init_layout(maps, is_static, viewport):
for layer in viz.layers:
layer.map_index = map_index

map_settings = _get_map_settings(viz, is_static, viewport, map_index)
map_settings = _get_map_settings(viz, is_static, viewport)

layout.append(map_settings)

return layout


def _get_map_settings(viz, is_static, viewport, map_index):
map_settings = viz.get_content()
def _get_map_settings(viz, is_static, viewport):
viz.viewport = _get_viewport(viz.viewport, viewport)
viz.camera = _get_camera(viz.viewport)
viz.is_static = _get_is_static(viz.is_static, is_static)

map_settings['viewport'] = _get_viewport(map_settings['viewport'], viewport)
map_settings['camera'] = _get_camera(map_settings['viewport'])
map_settings['is_static'] = _get_is_static(map_settings['is_static'], is_static)

return map_settings
viz._reload_layers()
return viz.get_content()


def _get_viewport(map_settings_viewport, layout_viewport):
Expand Down
10 changes: 7 additions & 3 deletions cartoframes/viz/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ def __init__(self,
self.title = title
self.description = description
self.show_info = show_info
self.is_static = is_static
self.layers = _init_layers(layers, self)
self.layer_defs = _get_layer_defs(self.layers)
self.bounds = _get_bounds(bounds, self.layers)
self.theme = _get_theme(theme, basemap)
self.is_static = is_static

self.token = get_token(basemap)
self.basecolor = get_basecolor(basemap)
Expand Down Expand Up @@ -273,6 +273,10 @@ def _get_publication_html(self, name):

return html_map.html

def _reload_layers(self):
self.layers = _init_layers(self.layers, self)
self.layer_defs = _get_layer_defs(self.layers)


def _get_publisher(credentials):
return KuvizPublisher(credentials)
Expand All @@ -289,11 +293,11 @@ def _init_layers(layers, parent_map):
if layers is None:
return []
if not isinstance(layers, collections.Iterable):
layers.reset_legends(parent_map)
layers.reset_ui(parent_map)
return [layers]
else:
for layer in layers:
layer.reset_legends(parent_map)
layer.reset_ui(parent_map)
return layers


Expand Down