|
- import base64
- from io import BytesIO
-
- def get_image_base64(img):
- buffered = BytesIO()
- img.save(buffered, format="PNG")
- img_str = base64.b64encode(buffered.getvalue()).decode()
- return f"data:image/png;base64,{img_str}"
-
- def show_mapper_v2(cfg):
- # ... (caricamento meta e percorsi come nel tuo file originale) ...
-
- img_path = MAPS_DIR / f"{cfg['maps']['floor_prefix']}{floor_id}.png"
- img = Image.open(img_path).convert("RGBA")
- img_width, img_height = img.size
- img_b64 = get_image_base64(img)
-
- # Prepariamo la lista dei punti esistenti (Punto 6 delle specifiche)
- dots_data = []
- # Qui cicla sui tuoi file CSV e popola dots_data con {x, y, relX, relY, status}
-
- # Integrazione del componente HTML
- # Carichiamo il JS dal file esterno
- with open("leaflet_bridge.js", "r") as f:
- js_code = f.read()
-
- html_content = f"""
- <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
- <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
- <div id="map" style="height: 600px; width: 100%;"></div>
- <script>
- {js_code}
- initMap({{
- imgUrl: "{img_b64}",
- width: {img_width},
- height: {img_height},
- meta: {json.dumps(meta)},
- dots: {json.dumps(dots_data)},
- dot_size: {dot_size}
- }});
- </script>
- """
-
- # Il componente restituisce il valore di window.parent.postMessage
- result = components.html(html_content, height=650)
-
- if result:
- st.write(f"Posizione catturata: {result}")
- # Qui inserisci la tua logica di salvataggio CSV che avevi nel punto 7
|