Skip to content

Commit

Permalink
first version of legends
Browse files Browse the repository at this point in the history
  • Loading branch information
kauevestena committed Sep 16, 2024
1 parent 6f04d81 commit 654d000
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 13 deletions.
Binary file added assets/map_symbols/lit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map_symbols/smoothness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map_symbols/surface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map_symbols/tactile_paving.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map_symbols/traffic_calming.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map_symbols/wheelchair.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,10 @@ def create_folder_if_not_exists(folderpath):
if not os.path.exists(folderpath):
os.makedirs(folderpath)

def create_folderlist(folderlist):
for folder in folderlist:
create_folder_if_not_exists(folder)

def remove_if_exists(pathfile):
if os.path.exists(pathfile):
os.remove(pathfile)
Expand Down
14 changes: 8 additions & 6 deletions modules_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@
inner_div_class_ref = 'media__body'
outer_div_class_ref = 'media'
img_css_class_ref = 'media_image responsive'
assets_base_path = f'{codebase_homepage}assets/homepage/'
assets_base_path = f'{codebase_homepage}assets/'
assets_homepage_path = f'{codebase_homepage}assets/homepage/'
assets_map_symbols_path = f'{codebase_homepage}assets/map_symbols/'

modules_metadata = {
'webmap': {
'url' : f'{node_homepage_url}map.html',
'img_src' : f"{assets_base_path}oswm_webmap_img.png",
'img_src' : f"{assets_homepage_path}oswm_webmap_img.png",
'text' : 'Webmap'
},
'routing': {
'url' : STREAMLIT_URL,
'img_src' : f"{assets_base_path}oswm_route_img.png",
'url' : 'https://kauevestena.github.io/opensidewalkmap_beta/routing.html',
'img_src' : f"{assets_homepage_path}oswm_route_img.png",
'text' : 'Optimized Routing'
},
'dashboard': {
'url' : f'{node_homepage_url}statistics/index.html',
'img_src' : f"{assets_base_path}oswm_statistics_img.png",
'img_src' : f"{assets_homepage_path}oswm_statistics_img.png",
'text' : 'Dashboard'
},
'data_quality': {
'url' : f'{node_homepage_url}quality_check/oswm_qc_main.html',
'img_src' : f"{assets_base_path}oswm_quality_check_img.png",
'img_src' : f"{assets_homepage_path}oswm_quality_check_img.png",
'text' : 'Data Quality Tool'
},
}
Expand Down
2 changes: 1 addition & 1 deletion webmap/create_webmap_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
color_dict = get_color_dict(attribute,attribute_layers.get(attribute,'sidewalks'))
color_schema = create_maplibre_color_schema(color_dict,attribute,different_else_color.get(attribute,'gray'))

params['styles'][attribute] = create_simple_map_style(interest_attributes[attribute],color_schema,generate_shadow_layers=False)
params['styles'][attribute] = create_simple_map_style(interest_attributes[attribute],color_schema,color_dict,attribute)

# reading the base html
webmap_html = file_as_string(webmap_base_path)
Expand Down
20 changes: 17 additions & 3 deletions webmap/standalone_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,26 @@ def add_element(self, element_type, label, **kwargs):
"""
if element_type == 'line':
self.add_line(label=label, **kwargs)
elif element_type == 'marker':
elif element_type == 'marker' or element_type == 'circle':
self.add_marker(label=label, **kwargs)
elif element_type == 'patch':
elif element_type == 'patch' or element_type == 'fill':
self.add_patch(label=label, **kwargs)
else:
raise ValueError(f"Unknown element type: {element_type}. Supported types are 'line', 'marker', and 'patch'.")
raise ValueError(f"Unknown element type: {element_type}. Supported types are 'line', 'marker'/'circle', and 'patch'/'fill'.")

def add_elements(self, elements):
"""
Add multiple custom elements to the legend.
Parameters:
elements (list): A list of tuples containing the element type and its parameters.
"""
for element_type, kwargs in elements:
self.add_element(element_type, **kwargs)

def __hash__(self) -> int:
# enable hashing of the object, example: legend = StandaloneLegend(); hash(legend)
return hash((self.legend_elements, self.legend_labels))

def export(self, filename='legend.png'):
# Export the legend to an image file
Expand Down
23 changes: 20 additions & 3 deletions webmap/webmap_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from functions import *
from copy import deepcopy

from standalone_legend import *

MAP_DATA_LAYERS = [l for l in paths_dict['map_layers']]

# webmap stuff:
Expand All @@ -12,6 +14,9 @@
webmap_base_path = 'oswm_codebase/webmap/webmap_base.html'
webmap_path = 'map.html'

assets_path = 'oswm_codebase/assets/'
map_symbols_assets_path = os.path.join(assets_path, 'map_symbols')

# mapping geometry types to maplibre style
map_geom_type_mapping = {
'Polygon':'fill',
Expand Down Expand Up @@ -238,7 +243,7 @@ def create_base_style(sources=MAP_SOURCES,name='Footway Categories'):

return style_dict

def create_simple_map_style(name,color_schema,sources=MAP_SOURCES,generate_shadow_layers=False):
def create_simple_map_style(name,color_schema,color_dict,filename,sources=MAP_SOURCES,generate_shadow_layers=False):

style_dict = deepcopy(mapstyle_basedict)

Expand Down Expand Up @@ -277,7 +282,17 @@ def create_simple_map_style(name,color_schema,sources=MAP_SOURCES,generate_shado


style_dict['layers'].append(layer_dict)


# now generating the map symbols
# TODO: check the hashing, otherwise no need to re-run
style_legend = StandaloneLegend()

for key in color_dict:
style_legend.add_line(label=key, color=color_dict[key])

style_legend.add_line(label='other', color=color_schema[-1])

style_legend.export(os.path.join(map_symbols_assets_path,f'{filename}.png'))

return style_dict

Expand Down Expand Up @@ -358,4 +373,6 @@ def create_crossings_kerbs_style(sources=MAP_SOURCES,name='Crossings and Kerbs',


return style_dict


# call just once:
create_folderlist([map_symbols_assets_path])

0 comments on commit 654d000

Please sign in to comment.