Skip to content

Commit

Permalink
more symbols, some black styling
Browse files Browse the repository at this point in the history
  • Loading branch information
kauevestena committed Sep 17, 2024
1 parent 809846b commit 5099374
Show file tree
Hide file tree
Showing 12 changed files with 944 additions and 848 deletions.
Binary file added assets/map_symbols/footway_categories.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 modified 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 modified 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 modified 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 modified 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 modified 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 modified 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.
810 changes: 375 additions & 435 deletions constants.py

Large diffs are not rendered by default.

448 changes: 273 additions & 175 deletions functions.py

Large diffs are not rendered by default.

50 changes: 27 additions & 23 deletions webmap/create_webmap_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# create a --development flag:
parser = argparse.ArgumentParser()
parser.add_argument('--development', action='store_true')
parser.add_argument("--development", action="store_true")
args = parser.parse_args()

in_dev = args.development
Expand All @@ -12,16 +12,16 @@
params = read_json(webmap_params_original_path)

# then override and fill in with the stuff:
params['data_layers'] = MAP_DATA_LAYERS
params["data_layers"] = MAP_DATA_LAYERS

# the layers that by type:
params['layer_types'] = layer_type_groups
params["layer_types"] = layer_type_groups

# boundaries:
params['bounds'] = get_boundaries_bbox()
params["bounds"] = get_boundaries_bbox()

# updating the node's url:
params['node_url'] = node_homepage_url
params["node_url"] = node_homepage_url

# # generating the "sources" and layernames:
params.update(get_sources(only_urls=True))
Expand All @@ -30,46 +30,50 @@
# very temporary:
# params['sources'] = MAP_SOURCES

params['styles'] = {
"footway_categories" : create_base_style(),
'crossings_and_kerbs' : create_crossings_kerbs_style()
params["styles"] = {
"footway_categories": create_base_style(),
"crossings_and_kerbs": create_crossings_kerbs_style(),
}

interest_attributes = {
# key is raw attribute name, value is label (human readable)
"surface" : "Surface",
"smoothness" : "Smoothness",
"tactile_paving" : "Tactile Paving",
'lit' : "Lighting",
'traffic_calming' : "Traffic Calming",
"wheelchair" : 'wheelchair=* tag',
"surface": "Surface",
"smoothness": "Smoothness",
"tactile_paving": "Tactile Paving",
"lit": "Lighting",
"traffic_calming": "Traffic Calming",
"wheelchair": "wheelchair=* tag",
}

attribute_layers = {
# default is "sidewalks", only specified if different:
'traffic_calming' : 'crossings',
"traffic_calming": "crossings",
}

different_else_color = {
# default is "gray", specifyed ony if different:
'traffic_calming' : '#63636366',
"traffic_calming": "#63636366",
}

for attribute in interest_attributes:
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,color_dict,attribute)
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, color_dict, attribute
)

# reading the base html
webmap_html = file_as_string(webmap_base_path)

# doing other stuff like insertions and nasty things (TODO):

# finally generate the files:
str_to_file(webmap_html,webmap_path)
dump_json(params,webmap_params_path)
str_to_file(webmap_html, webmap_path)
dump_json(params, webmap_params_path)

# if we are in dev mode, also dump the original params:
if in_dev:
dump_json(params,webmap_params_original_path)
dump_json(params, webmap_params_original_path)
47 changes: 35 additions & 12 deletions webmap/standalone_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from matplotlib.lines import Line2D
from matplotlib.patches import Patch

from functions import *


# thx ChatGPT, employed to transform a scratch code into the class
class StandaloneLegend:
def __init__(self):
Expand All @@ -11,19 +14,22 @@ def __init__(self):
self.legend_labels = []
self.legendFig = plt.figure("Legend plot")

def add_line(self, label='Line', **kwargs):
def add_line(self, label="Line", **kwargs):
"""
Add a line to the legend with customizable parameters.
Parameters:
label (str): The label for the line element.
**kwargs: Additional keyword arguments for Line2D.
"""

rename_dict_key(kwargs, "width", "linewidth")

line = Line2D([0], [0], label=label, **kwargs)
self.legend_elements.append(line)
self.legend_labels.append(label)

def add_marker(self, marker='o', label='Marker', **kwargs):
def add_marker(self, marker="o", label="Marker", **kwargs):
"""
Add a marker to the legend with customizable parameters.
Expand All @@ -32,13 +38,19 @@ def add_marker(self, marker='o', label='Marker', **kwargs):
label (str): The label for the marker element.
**kwargs: Additional keyword arguments for Line2D.
"""

# to standardize the key names
rename_dict_key(kwargs, "color", "markerfacecolor")
rename_dict_key(kwargs, "width", "markersize")

# Add default transparent color to kwargs if not provided
kwargs.setdefault('color', (0.0, 0.0, 0.0, 0.0))
kwargs.setdefault("color", (0.0, 0.0, 0.0, 0.0))
kwargs.setdefault("markeredgecolor", (0.0, 0.0, 0.0, 0.0))
marker = Line2D([0], [0], marker=marker, label=label, **kwargs)
self.legend_elements.append(marker)
self.legend_labels.append(label)

def add_patch(self, facecolor='orange', edgecolor='w', label='Patch', **kwargs):
def add_patch(self, facecolor="orange", edgecolor="w", label="Patch", **kwargs):
"""
Add a patch to the legend with customizable parameters.
Expand All @@ -48,6 +60,12 @@ def add_patch(self, facecolor='orange', edgecolor='w', label='Patch', **kwargs):
label (str): The label for the patch element.
**kwargs: Additional keyword arguments for Patch.
"""

# rename_dict_key(kwargs, "facecolor", "markerfacecolor")

if "width" in kwargs:
kwargs.pop("width")

patch = Patch(facecolor=facecolor, edgecolor=edgecolor, label=label, **kwargs)
self.legend_elements.append(patch)
self.legend_labels.append(label)
Expand All @@ -61,15 +79,17 @@ def add_element(self, element_type, label, **kwargs):
label (str): The label for the element.
**kwargs: Additional keyword arguments for the element.
"""
if element_type == 'line':
if element_type == "line":
self.add_line(label=label, **kwargs)
elif element_type == 'marker' or element_type == 'circle':
elif element_type == "marker" or element_type == "circle":
self.add_marker(label=label, **kwargs)
elif element_type == 'patch' or element_type == 'fill':
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'/'circle', and 'patch'/'fill'.")

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.
Expand All @@ -84,12 +104,15 @@ 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'):
def export(self, filename="legend.png"):
# Export the legend to an image file
self.legendFig.legend(handles=self.legend_elements, labels=self.legend_labels, loc='center')
self.legendFig.savefig(filename, bbox_inches='tight', transparent=True)
self.legendFig.legend(
handles=self.legend_elements, labels=self.legend_labels, loc="center"
)
self.legendFig.savefig(filename, bbox_inches="tight", transparent=True)
plt.close(self.legendFig) # Close the figure to free memory


# # Example usage:
# legend = StandaloneLegend()
# legend.add_line(color='b', linewidth=4, label='Line')
Expand Down
Loading

0 comments on commit 5099374

Please sign in to comment.