Spaces:
Sleeping
Sleeping
| import leafmap | |
| import numpy as np | |
| # Fonction pour calculer les coordonnées de la bbox | |
| def calculate_bbox(center_lat, center_lon, format, scale): | |
| paper_sizes = { | |
| 'A4': (210, 297), | |
| 'A3': (297, 420), | |
| 'A2': (420, 594), | |
| 'A1': (594, 841), | |
| 'A0': (841, 1189) | |
| } | |
| size = paper_sizes.get(format) | |
| if not size: | |
| return None | |
| width_mm, height_mm = size | |
| width_m = (width_mm / 1000) * scale | |
| height_m = (height_mm / 1000) * scale | |
| bounds = [ | |
| [center_lat - (height_m / 2) / 111320, center_lon - (width_m / 2) / (111320 * np.cos(center_lat * np.pi / 180))], | |
| [center_lat + (height_m / 2) / 111320, center_lon + (width_m / 2) / (111320 * np.cos(center_lat * np.pi / 180))] | |
| ] | |
| return bounds | |
| # Créer une carte centrée sur la Suisse | |
| m = leafmap.Map(center=[46.8182, 8.2275], zoom=8) | |
| # Ajouter un outil pour dessiner des formes | |
| m.add_draw_control() | |
| # Fonction pour ajuster la carte à la bbox calculée | |
| def draw_bbox(): | |
| center_lat, center_lon = m.center | |
| format = 'A4' # Exemple de format | |
| scale = 1000 # Exemple d'échelle | |
| bbox = calculate_bbox(center_lat, center_lon, format, scale) | |
| if bbox: | |
| m.fit_bounds(bbox) | |
| # Ajouter un bouton pour dessiner la bbox | |
| m.add_button(label="Dessiner BBox", on_click=draw_bbox) | |
| # Afficher la carte dans Streamlit | |
| m.to_streamlit() |