You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

59 rivejä
1.8 KiB

  1. // leaflet_bridge.js
  2. function initMap(config) {
  3. const { imgUrl, width, height, meta, grid_size, dots } = config;
  4. // Setup Coordinate XY (0,0 in alto a sinistra)
  5. const map = L.map('map', {
  6. crs: L.CRS.Simple,
  7. minZoom: -2,
  8. maxZoom: 4,
  9. attributionControl: false
  10. });
  11. const bounds = [[-height, 0], [0, width]];
  12. L.imageOverlay(imgUrl, bounds).addTo(map);
  13. map.fitBounds(bounds);
  14. // Gestione Griglia
  15. let gridLayer = L.layerGroup();
  16. if (meta.show_grid) {
  17. const step = meta.grid_size || 100;
  18. const S = meta.pixel_ratio || 1;
  19. for (let x = 0; x <= width; x += (step * S)) {
  20. L.polyline([[0, x], [-height, x]], {color: '#ccc', weight: 1, opacity: 0.5}).addTo(gridLayer);
  21. }
  22. for (let y = 0; y >= -height; y -= (step * S)) {
  23. L.polyline([[y, 0], [y, width]], {color: '#ccc', weight: 1, opacity: 0.5}).addTo(gridLayer);
  24. }
  25. gridLayer.addTo(map);
  26. }
  27. // Visualizzazione punti esistenti (Verdi e Blu)
  28. dots.forEach(dot => {
  29. const color = dot.status === 'completed' ? '#228B22' : '#0000FF';
  30. L.circleMarker([dot.y, dot.x], {
  31. radius: config.dot_size / 5,
  32. fillColor: color,
  33. color: 'white',
  34. weight: 2,
  35. fillOpacity: 0.8
  36. }).addTo(map).bindPopup(`X: ${dot.relX}, Y: ${dot.relY}`);
  37. });
  38. // Evento Click per rilievo
  39. map.on('click', function(e) {
  40. const raw_x = e.latlng.lng;
  41. const raw_y = e.latlng.lat; // In Leaflet Simple, Y è negativa sotto l'origine
  42. // Invio dati a Streamlit
  43. window.parent.postMessage({
  44. type: 'streamlit:setComponentValue',
  45. value: {
  46. x: raw_x,
  47. y: raw_y,
  48. timestamp: new Date().getTime()
  49. }
  50. }, '*');
  51. });
  52. }