Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

50 righe
1.7 KiB

  1. import base64
  2. from io import BytesIO
  3. def get_image_base64(img):
  4. buffered = BytesIO()
  5. img.save(buffered, format="PNG")
  6. img_str = base64.b64encode(buffered.getvalue()).decode()
  7. return f"data:image/png;base64,{img_str}"
  8. def show_mapper_v2(cfg):
  9. # ... (caricamento meta e percorsi come nel tuo file originale) ...
  10. img_path = MAPS_DIR / f"{cfg['maps']['floor_prefix']}{floor_id}.png"
  11. img = Image.open(img_path).convert("RGBA")
  12. img_width, img_height = img.size
  13. img_b64 = get_image_base64(img)
  14. # Prepariamo la lista dei punti esistenti (Punto 6 delle specifiche)
  15. dots_data = []
  16. # Qui cicla sui tuoi file CSV e popola dots_data con {x, y, relX, relY, status}
  17. # Integrazione del componente HTML
  18. # Carichiamo il JS dal file esterno
  19. with open("leaflet_bridge.js", "r") as f:
  20. js_code = f.read()
  21. html_content = f"""
  22. <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
  23. <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
  24. <div id="map" style="height: 600px; width: 100%;"></div>
  25. <script>
  26. {js_code}
  27. initMap({{
  28. imgUrl: "{img_b64}",
  29. width: {img_width},
  30. height: {img_height},
  31. meta: {json.dumps(meta)},
  32. dots: {json.dumps(dots_data)},
  33. dot_size: {dot_size}
  34. }});
  35. </script>
  36. """
  37. # Il componente restituisce il valore di window.parent.postMessage
  38. result = components.html(html_content, height=650)
  39. if result:
  40. st.write(f"Posizione catturata: {result}")
  41. # Qui inserisci la tua logica di salvataggio CSV che avevi nel punto 7