Skip to content

Commit

Permalink
Store user logos locally to avoid missing markers in map
Browse files Browse the repository at this point in the history
  • Loading branch information
XinShen-CHN authored Aug 2, 2024
1 parent 98a33de commit c387d67
Show file tree
Hide file tree
Showing 29 changed files with 3 additions and 28 deletions.
Binary file removed docs/source/images/ENEA.png
Binary file not shown.
Binary file removed docs/source/images/MIT_Cambridge_MA_USA.png
Binary file not shown.
Binary file not shown.
Binary file removed docs/source/images/digiLab_UK.png
Binary file not shown.
File renamed without changes
Binary file added docs/source/images/user_logos/ENEA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
31 changes: 3 additions & 28 deletions docs/source/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,6 @@

LOGO_HEIGHT = 60


def get_image_dimensions_from_url(image_url):
"""Function to get the dimensions of an image from URL
Args:
image_url (str): the url
Returns:
tuple: the dimensions of the image
"""
headers = {
"User-Agent": "FESTIM (https://github.com/festim-dev/festim; [email protected])"
}

try:
response = requests.get(image_url, headers=headers)
response.raise_for_status() # Raise an exception for HTTP errors
img = Image.open(BytesIO(response.content))
return img.size
except Exception as e:
print(f"Error fetching or processing image: {e}")
return None


def generate_map(clustered=True, draggable=False):
# Load GeoJSON data
with open("map.json") as f:
Expand All @@ -55,8 +30,8 @@ def generate_map(clustered=True, draggable=False):
# Get the dimensions of the image from local images

if "path" in feature["properties"]:
url = feature["properties"]["path"]
image_dimensions = Image.open(url).size
path = feature["properties"]["path"]
image_dimensions = Image.open(path).size

if image_dimensions:
height_to_width_ratio = image_dimensions[1] / image_dimensions[0]
Expand All @@ -65,7 +40,7 @@ def generate_map(clustered=True, draggable=False):
image_dimensions = (LOGO_HEIGHT, LOGO_HEIGHT)
# Create a marker with a custom icon and popup
if coordinates != [0, 0]:
icon = folium.CustomIcon(url, icon_size=image_dimensions)
icon = folium.CustomIcon(path, icon_size=image_dimensions)
marker = folium.Marker(
location=[coordinates[1], coordinates[0]],
icon=icon,
Expand Down

0 comments on commit c387d67

Please sign in to comment.