Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="it">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Mappa Municipio X - Biblioteca Elsa Morante</title>
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.css" />
- <link rel="stylesheet" href="https://unpkg.com/leaflet-routing-machine@3.2.12/dist/leaflet-routing-machine.css" />
- <link rel="icon" href="favicon.png" type="image/png">
- <style>
- :root {
- --primary: #bc0b36; /* Colore primario */
- }
- body, html {
- margin: 0;
- padding: 0;
- height: 100%;
- width: 100%;
- overflow: hidden; /* Prevents scrolling */
- position: fixed; /* Ensures no bouncing/scrolling on mobile */
- }
- #map {
- height: 100%; /* Changed from 100vh to 100% */
- width: 100%;
- position: absolute;
- top: 0;
- left: 0;
- }
- .search-box{position:absolute;top:10px;left:50px;z-index:1000;background:#fff;padding:10px;border-radius:5px;box-shadow:0 0 15px rgba(0,0,0,.2);display:flex;align-items:center}
- .search-box input{width:250px;margin-right:10px;padding:5px 10px;border:1px solid #ccc;border-radius:3px;font-size:14px}
- .search-box button {
- background-color: var(--primary);
- color: #fff;
- border: none;
- padding: 5px 10px;
- border-radius: 3px;
- cursor: pointer;
- font-size: 14px;
- }
- .search-box .icon{width:24px;height:24px;margin-right:10px;cursor:pointer}
- .search-box .separator{width:1px;height:24px;background-color:#ccc;margin:0 10px}
- /* Barra laterale fissa */
- .sidebar {
- position: absolute;
- top: 0;
- left: 0;
- height: 100%;
- width: 60px;
- background: rgba(255, 255, 255, 0.9);
- box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
- z-index: 1000;
- display: flex;
- flex-direction: column;
- align-items: center;
- padding-top: 40px; /* Riduci questo valore (era 20px) */
- }
- .sidebar button {
- background: transparent;
- border: none;
- cursor: pointer;
- margin-bottom: 20px;
- margin-top: 5px;
- position: relative;
- transition: background-color 0.3s ease;
- }
- /* Effetto hover sui pulsanti */
- .sidebar button:hover {
- background-color: rgba(0, 0, 0, 0.1); /* Cambia colore di sfondo al passaggio del mouse */
- border-radius: 5px; /* Arrotonda gli angoli */
- }
- /* Add new styles for active button state */
- .sidebar button.active {
- background-color: rgba(0,0,0,0.1);
- border-radius: 5px;
- }
- /* Stile per il tooltip */
- .sidebar button::after {
- content: attr(data-tooltip); /* Usa l'attributo data-tooltip per il testo */
- position: absolute;
- left: 60px; /* Posizione a destra del pulsante */
- top: 50%;
- transform: translateY(-50%);
- background-color: rgba(0, 0, 0, 0.8);
- color: #fff;
- padding: 5px 10px;
- border-radius: 4px;
- font-size: 12px;
- white-space: nowrap;
- opacity: 0;
- visibility: hidden;
- transition: opacity 0.3s ease, visibility 0.3s ease;
- }
- /* Mostra il tooltip al passaggio del mouse */
- .sidebar button:hover::after {
- opacity: 1;
- visibility: visible;
- }
- .sidebar button img {
- width: 24px;
- height: 24px;
- padding: 0;
- margin: 0;
- }
- /* Seconda barra laterale (espansione) */
- .sidebar-expanded {
- overflow-y: auto;
- position: absolute;
- top: 0;
- left: 60px;
- height: 100%;
- width: 0;
- background: #f4f7f0;
- box-shadow: 2px 0 10px rgba(0,0,0,0.1);
- z-index: 999;
- transition: width 0.3s ease;
- }
- .sidebar-expanded.open {
- width: 400px;
- padding: 20px;
- box-sizing: border-box;
- }
- .sidebar-close-icon {
- position: absolute;
- right: 8px;
- top: 8px;
- cursor: pointer;
- opacity: 0.8;
- transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
- z-index: 1000;
- width: 28px;
- height: 28px;
- display: flex;
- align-items: center;
- justify-content: center;
- border-radius: 50%;
- background: url('x.svg') center center no-repeat;
- background-size: 14px;
- }
- .sidebar-close-icon:hover {
- opacity: 1;
- background-color: rgba(0, 0, 0, 0.05);
- transform: scale(1.08);
- box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
- }
- /* Casella di ricerca */
- /* Stile per il pannello di ricerca */
- .search-container {
- position: relative; /* Permette di posizionare il riquadro dei risultati relativamente a questo contenitore */
- padding: 20px;
- display: none;
- }
- .sidebar-expanded.open .search-container {
- display: block; /* Mostra la casella di ricerca */
- }
- .search-container input {
- width: 100%;
- padding: 8px;
- border: 1px solid #4285f4; /* Contorno blu */
- border-radius: 4px; /* Bordi arrotondati */
- font-size: 14px;
- outline: none; /* Rimuove il bordo predefinito */
- }
- .search-container button {
- width: 100%;
- padding: 8px;
- margin-top: 10px;
- background-color: var(--primary);
- color: #fff;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- font-size: 14px;
- }
- .search-container .icon {
- width: 24px;
- height: 24px;
- padding: 6px;
- border-radius: 4px;
- transition: background-color 0.2s ease;
- }
- .search-container .icon:hover {
- background-color: rgba(0, 0, 0, 0.05);
- }
- .legend.visible {
- right: 40px; /* Modificato da 0 a 40px per lasciare spazio alla maniglia */
- }
- .legend-container {
- padding: 20px;
- }
- .legend-container h4 {
- margin: 0 0 12px 0;
- font-size: 14px;
- color: #333;
- }
- /* Rimuovere questi stili dalla classe .legend esistente poiché non serviranno più */
- .legend {
- display: none;
- }
- /* Assicurati che il contenitore della legenda abbia una posizione relativa */
- .legend {
- position: fixed; /* Fisso in modo che resti visibile anche durante lo scroll */
- top: 10px; /* Vicino al bordo superiore */
- bottom: 25px; /* Vicino al bordo inferiore */
- right: -350px; /* Posizione iniziale fuori dalla vista */
- z-index: 1000;
- width: 250px; /* Larghezza della legenda */
- background: rgba(255,255,255,.95);
- padding: 15px 20px;
- font: 13px/15px 'Segoe UI', system-ui, sans-serif;
- box-shadow: 0 5px 25px rgba(0,0,0,.15);
- border-radius: 12px;
- border: 1px solid rgba(0,0,0,.1);
- backdrop-filter: blur(4px);
- transition: right .3s ease;
- overflow: visible;
- }
- .legend h4 {
- margin: 0 0 12px 0; /* Margin più bilanciato */
- font-size: 14px;
- }
- .legend-grid {
- display: grid;
- grid-template-columns: 1fr;
- gap: 6px; /* Gap intermedio tra gli elementi */
- margin-top: 20px; /* Aggiungi un margine superiore per abbassare i municipi */
- }
- /* Stili comuni */
- .legend-item {
- display: flex;
- padding: 6px 10px;
- border-radius: 6px;
- cursor: pointer;
- transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
- background: rgba(255, 255, 255, 0.7);
- border: 1px solid transparent;
- position: relative;
- padding-right: 40px;
- }
- /* Stili specifici per .legend-item (default) */
- .legend-item {
- align-items: center;
- flex-direction: column;
- }
- /* Stili specifici per .federate-container .legend-item */
- .federate-container .legend-item {
- align-items: flex-start;
- flex-direction: row; /* Imposta esplicitamente il valore predefinito */
- }
- .legend-item span {
- width: 18px; /* Dimensione icona bilanciata */
- height: 18px;
- margin-right: 10px; /* Margin bilanciato */
- border-radius: 4px;
- box-shadow: 0 2px 6px rgba(0,0,0,0.1);
- }
- .legend-item:hover {
- background: rgba(241, 242, 246,0.6);
- transform: translateX(3px);
- border-color: #dfe4ea;
- }
- .legend-item.highlighted {
- background: #f8f9fa;
- box-shadow: 0 3px 15px rgba(0,0,0,0.1);
- border-color: #ced6e0;
- }
- .legend-item:hover span {
- transform: scale(1.1);
- }
- .legend-item .text {
- font-size: 13px;
- color: #4a5568;
- font-weight: 500;
- letter-spacing: 0.02em;
- margin-right: 20px;
- }
- .legend-item.disabled {
- opacity: 0.5;
- pointer-events: none;
- }
- .legend-close-icon {
- position: absolute;
- right: 8px;
- top: 8px;
- cursor: pointer;
- opacity: .8;
- transition: all .2s cubic-bezier(.4, 0, .2, 1);
- z-index: 1000;
- width: 28px; /* Ridotto da 32px a 28px */
- height: 28px; /* Ridotto da 32px a 28px */
- display: flex;
- align-items: center;
- justify-content: center;
- border-radius: 50%;
- background: url('x.svg') center center no-repeat;
- background-size: 14px; /* Ridotto da 16px a 14px per mantenere le proporzioni */
- }
- .legend-close-icon:hover {
- opacity: 1;
- background-color: rgba(0, 0, 0, 0.05); /* Cambiato da rgba(255,68,68,.15) a un grigio più sottile */
- transform: scale(1.08); /* Ridotto da 1.15 a 1.08 per un effetto più sottile */
- box-shadow: 0 1px 4px rgba(0,0,0,0.05); /* Ridotto l'effetto ombra */
- }
- .municipio-highlight {
- stroke-width: 4px !important;
- stroke-opacity: 0.9 !important;
- filter: drop-shadow(0 0 12px rgba(0,0,0,0.15));
- animation: pulseBorder 1.5s ease-in-out infinite;
- }
- .municipio-selected {
- stroke-width: 5px !important;
- stroke-opacity: 1 !important;
- fill-opacity: 0.2 !important;
- filter: drop-shadow(0 0 15px rgba(0, 0, 0, 0.3));
- }
- @keyframes pulseBorder {
- 0% { stroke-width: 4px; }
- 50% { stroke-width: 5px; }
- 100% { stroke-width: 4px; }
- }
- .leaflet-routing-container{position:relative}
- .routing-close-btn {
- position: absolute;
- top: 10px;
- right: 10px;
- width: 24px;
- height: 24px;
- background-color: var(--primary);
- color: white;
- border: none;
- border-radius: 50%;
- cursor: pointer;
- display: flex;
- align-items: center;
- justify-content: center;
- font-weight: bold;
- font-size: 14px;
- z-index: 1000;
- transition: background-color 0.3s;
- }
- .routing-close-btn:hover {
- background-color: rgba(255, 26, 26, 0.8);
- }
- .custom-popup .leaflet-popup-content-wrapper {
- background-color: rgb(255, 255, 255); /* Fully opaque white background */
- border-radius: 8px;
- }
- .custom-popup .leaflet-popup-tip {
- background-color: rgb(255, 255, 255); /* Fully opaque white background */
- }
- .custom-popup {
- margin-bottom: 30px;
- }
- .custom-popup .leaflet-popup-close-button {
- color: #ff4d4d;
- font-size: 20px;
- font-weight: bold;
- opacity: 1;
- right: 8px;
- top: 8px;
- }
- .custom-popup .leaflet-popup-close-button:hover {
- color: #ff1a1a;
- }
- .hours-info {
- margin-top: 10px;
- font-size: 12px;
- color: #333;
- }
- .baloon h3 {
- margin: 0 0 10px 0;
- color: #333;
- }
- .baloon p {
- margin: 0 0 10px 0;
- line-height: 1.4;
- }
- .baloon a {
- display: inline-block;
- text-decoration: none;
- margin-top: 5px;
- }
- /* Stile per il riquadro dei risultati */
- #search-results {
- display: none; /* Nascondi di default */
- position: relative;
- width: calc(100% - 40px);
- max-height: calc(100% - 150px); /* Adjust based on your header height */
- overflow-y: auto;
- background-color: #fff;
- border-radius: 8px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
- padding: 15px;
- margin: 20px auto;
- border: 1px solid #e0e0e0;
- z-index: 1;
- }
- /* Stile per il titolo del municipio */
- #search-results .municipio-title {
- font-size: 16px;
- font-weight: 600;
- color: #333;
- margin-bottom: 10px;
- padding-bottom: 10px;
- border-bottom: 1px solid #e0e0e0;
- }
- /* Stile per ogni voce di biblioteca */
- #search-results .library-item {
- padding: 8px 12px;
- margin: 5px 0;
- border-radius: 6px;
- background-color: #f9f9f9;
- cursor: pointer;
- transition: background-color 0.2s ease, transform 0.2s ease;
- font-size: 14px;
- color: #555;
- border: 1px solid #e0e0e0;
- }
- /* Effetto hover sulle voci di biblioteca */
- #search-results .library-item:hover {
- background-color: #f1f1f1;
- transform: translateX(5px);
- border-color: #4285f4;
- }
- /* Scrollbar personalizzata */
- #search-results::-webkit-scrollbar {
- width: 8px;
- }
- #search-results::-webkit-scrollbar-track {
- background: #f1f1f1;
- border-radius: 4px;
- }
- #search-results::-webkit-scrollbar-thumb {
- background: #888;
- border-radius: 4px;
- }
- #search-results::-webkit-scrollbar-thumb:hover {
- background: #555;
- }
- @media (max-width: 768px) {
- .sidebar-expanded.open {
- width: 100%; /* Occupa tutta la larghezza su schermi piccoli */
- padding: 10px; /* Riduci il padding su schermi piccoli */
- }
- #search-results {
- width: calc(100% - 20px); /* Riduci la larghezza su schermi piccoli */
- margin: 10px auto; /* Riduci il margine su schermi piccoli */
- }
- }
- /* Stile per il contenitore del campo di ricerca */
- .search-input-wrapper {
- position: relative;
- display: inline-block;
- width: 100%; /* Occupa tutta la larghezza disponibile */
- }
- /* Stile per il campo di ricerca */
- #start-point {
- width: 100%; /* Occupa tutta la larghezza del contenitore */
- padding-right: 30px; /* Lascia spazio per la "x" */
- box-sizing: border-box; /* Include il padding nella larghezza totale */
- }
- /* Stile per il pulsante "x" */
- .clear-search-btn {
- display: none; /* Inizialmente nascosto */
- position: absolute;
- right: 10px; /* Posizione rispetto al bordo destro del campo */
- top: 50%;
- transform: translateY(-50%);
- cursor: pointer;
- color: #888; /* Colore grigio */
- font-size: 14px;
- background: none;
- border: none;
- padding: 0;
- margin: 0;
- }
- .clear-search-btn:hover {
- color: #555; /* Colore più scuro al passaggio del mouse */
- }
- .custom-datalist {
- display: none;
- position: absolute;
- top: 100%;
- left: 0;
- width: 100%;
- max-height: 200px;
- overflow-y: auto;
- background-color: #fff;
- border: 1px solid #ccc;
- border-radius: 4px;
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
- z-index: 1000;
- }
- .custom-datalist div {
- padding: 8px 12px;
- cursor: pointer;
- transition: background-color 0.2s ease;
- display: block;
- }
- .custom-datalist div:hover {
- background-color: #f1f1f1;
- }
- .custom-datalist div.highlighted {
- background-color: #4285f4;
- color: #fff;
- }
- /* Stile per il contenitore delle biblioteche federate */
- .federate-container {
- padding: 20px;
- }
- .federate-container h4 {
- margin: 0 0 12px 0;
- font-size: 14px;
- color: #333;
- }
- .federate-container .legend-grid {
- display: grid;
- grid-template-columns: 1fr;
- gap: 6px;
- margin-top: 20px;
- }
- .federate-container .legend-item span {
- width: 18px;
- height: 18px;
- margin-right: 10px;
- border-radius: 4px;
- box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
- flex-shrink: 0; /* Impedisce al quadrato di ridimensionarsi */
- margin-top: 3px; /* Aggiunge un piccolo offset verso il basso */
- }
- .federate-container .legend-item:hover {
- background: rgba(241, 242, 246, 0.6);
- transform: translateX(3px);
- border-color: #dfe4ea;
- }
- .federate-container .legend-item .text {
- font-size: 13px;
- color: #4a5568;
- font-weight: 500;
- letter-spacing: 0.02em;
- margin-right: 20px;
- flex: 1; /* Permette al testo di occupare lo spazio rimanente */
- line-height: 1.4; /* Migliora la spaziatura delle righe per il testo su più righe */
- }
- .legend-item-header {
- display: flex;
- align-items: center;
- width: 100%;
- }
- .libraries-list {
- display: none;
- margin-top: 10px;
- margin-left: 28px;
- font-size: 12px;
- }
- .libraries-list.expanded {
- display: block;
- }
- .library-item-legend {
- padding: 4px 0;
- color: #666;
- cursor: pointer;
- transition: color 0.2s ease;
- }
- .library-item-legend:hover {
- color: #000;
- }
- .legend-item.expanded .expand-icon {
- transform: rotate(180deg);
- }
- /* Aggiungi questi nuovi stili */
- .expand-button {
- width: 20px;
- height: 20px;
- background-color: #f0f0f0;
- border: 1px solid #ddd;
- border-radius: 50%;
- position: absolute;
- right: 10px;
- top: 50%;
- transform: translateY(-50%);
- cursor: pointer;
- display: flex;
- align-items: center;
- justify-content: center;
- transition: all 0.2s ease;
- }
- .expand-button:hover {
- background-color: #e0e0e0;
- }
- .expand-button::after {
- content: '+';
- font-size: 16px;
- color: #666;
- }
- .legend-item.expanded .expand-button::after {
- content: '−';
- }
- </style>
- </head>
- <body>
- <!-- Barra laterale fissa -->
- <div class=sidebar>
- <button id=searchBtn onclick=toggleSearch() data-tooltip="Cerca biblioteca o indirizzo">
- <img src=search-icon.svg alt="Cerca biblioteca o indirizzo">
- </button>
- <button id="legendBtn" onclick="toggleLegendSidebar()" data-tooltip="Mostra/Nascondi legenda">
- <img src="legend-icon.svg" alt="Mostra/Nascondi legenda">
- </button>
- <!-- Nuovo bottone con icona federate-icon.svg -->
- <button id="federateBtn" onclick="toggleFederateSidebar()" data-tooltip="Biblioteche federate">
- <img src="federate-icon.svg" alt="Biblioteche federate">
- </button>
- </div>
- <!-- Terzo pannello laterale espanso: legenda municipi -->
- <div class="sidebar-expanded" id="legendSidebar">
- <div class="sidebar-close-icon" onclick="toggleLegendSidebar()"></div>
- <div class="legend-container">
- <h4>Mappa Biblioteche di Roma per Municipio</h4>
- <div class="legend-grid">
- <!-- Il contenuto della legenda verrà popolato dinamicamente dal JavaScript -->
- </div>
- </div>
- </div>
- <!-- Seconda barra laterale (espansione) -->
- <div class="sidebar-expanded" id="expandedSidebar">
- <div class="sidebar-close-icon" onclick="toggleExpandedSidebar()"></div>
- <!-- Aggiungi questa linea -->
- <div class="search-container" id="searchContainer">
- <div style="display: flex; align-items: center; gap: 10px;">
- <a href="https://www.bibliotechediroma.it/opac/library/Biblioteca%20Elsa%20Morante/RMBO2" title="Vai alla Biblioteca Elsa Morante">
- <img src="home.svg" alt="Biblioteca Home" class="icon">
- </a>
- <div class="search-input-wrapper" style="flex: 1;">
- <input id="start-point" placeholder="Inserisci punto di partenza" list="library-suggestions">
- <span id="clear-search" class="clear-search-btn" onclick="clearSearchField()">✕</span>
- </div>
- </div>
- <div id="library-suggestions" class="custom-datalist"></div>
- <div style="display: flex; gap: 10px;">
- <button onclick="searchRoute()" style="flex: 1;">Cerca</button>
- <button onclick="resetMap()" style="flex: 1; background-color: #6B7280;">Reset</button>
- </div>
- <!-- Nuovo pannello per le biblioteche federate -->
- <div class="sidebar-expanded" id="federateSidebar">
- <div class="sidebar-close-icon" onclick="toggleFederateSidebar()"></div>
- <div class="federate-container">
- <h4>Biblioteche Federate</h4>
- <div class="legend-grid">
- <div class="legend-item" onclick="zoomToSystemLibraries('CASTELLI ROMANI')">
- <span style="background: #0006fd"></span>
- <div class="text">Biblioteche Sistema Castelli Romani</div>
- </div>
- <div class="legend-item" onclick="zoomToSystemLibraries('Ceretano-Sabatino')">
- <span style="background: #fc04f7"></span>
- <div class="text">Sistema Bibliotecario Ceretano-Sabatino</div>
- </div>
- <div class="legend-item" onclick="zoomToSystemLibraries('Monti Prenestini')">
- <span style="background: #844715"></span>
- <div class="text">Sistema Bibliotecario Monti Prenestini</div>
- </div>
- <div class="legend-item" onclick="zoomToSystemLibraries('LUMSA')">
- <span style="background: #1e8b1f"></span>
- <div class="text">Lumsa</div>
- </div>
- <div class="legend-item" onclick="zoomToSystemLibraries('Foro Italico')">
- <span style="background: #473e86"></span>
- <div class="text">Foro Italico</div>
- </div>
- <div class="legend-item" onclick="zoomToSystemLibraries('Link')">
- <span style="background: #2f4d4c"></span>
- <div class="text">Link Campus</div>
- </div>
- <div class="legend-item" onclick="zoomToSystemLibraries('La Sapienza')">
- <span style="background: #86134f"></span>
- <div class="text">Sistema Bibliotecario di Ateneo<br>Università degli Studi Roma La Sapienza</div>
- </div>
- <div class="legend-item" onclick="zoomToSystemLibraries('Tor Vergata')">
- <span style="background: #382724"></span>
- <div class="text">Sistema Bibliotecario di Ateneo<br>Università degli Studi Roma Tor Vergata</div>
- </div>
- <div class="legend-item" onclick="zoomToSystemLibraries('Roma Tre')">
- <span style="background: #f20000"></span>
- <div class="text">Sistema Bibliotecario di Ateneo<br>Università degli Studi Roma Tre</div>
- </div>
- </div>
- <button id="toggleFederatedLibraries" onclick="toggleFederatedLibraries()" style="width: 100%; margin-top: 15px; padding: 8px; background-color: var(--primary); color: white; border: none; border-radius: 4px; cursor: pointer;">
- Mostra Biblioteche Federate
- </button>
- <button id="toggleRomeLibraries" onclick="toggleRomeLibraries()" style="width: 100%; margin-top: 15px; padding: 8px; background-color: var(--primary); color: white; border: none; border-radius: 4px; cursor: pointer;">
- Rimuovi Biblioteche di Roma
- </button>
- </div>
- </div>
- </div>
- <div id=search-results></div>
- </div>
- <div id="map"></div>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.js"></script>
- <script src="https://unpkg.com/leaflet-routing-machine@3.2.12/dist/leaflet-routing-machine.js"></script>
- <script src="icons-config.js"></script> <!-- Aggiungi questa riga -->
- <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js"></script>
- <script>
- // Colori per i diversi municipi
- const municipalityColors = {
- 1: "#6a3f3a", // Marrone
- 2: "#00faff", // Turchese
- 3: "#fbd51c", // Giallo
- 4: "#473e86", // Blu scuro
- 5: "#018a87", // Verde acqua
- 6: "#d33682", // Rosa
- 7: "#ff7c4e", // Arancione
- 8: "#22a825", // Verde erba
- 9: "#2b83cb", // Blu cielo
- 10: "#cb283c", // Rosso
- 11: "#cac12e", // Giallo oliva
- 12: "#a329ca", // Viola
- 13: "#c9832c", // Arancione-marrone
- 14: "#7b7b79", // Grigio
- 15: "#000000" // Nero
- };
- // Funzione per convertire numeri in numeri romani
- function romanize(num) {
- const roman = ['I','II','III','IV','V','VI','VII','VIII','IX','X','XI','XII','XIII','XIV','XV'];
- return roman[num - 1] || num;
- }
- // Initialize global variables
- let map;
- let currentBorder = null;
- let routingControl = null;
- let municipioLayer = null;
- let municipioLayers = {};
- let currentHighlight = null;
- let selectedMunicipio = null;
- let romeLibrariesVisible = true;
- let federatedLibrariesVisible = false;
- let removedRomeLibraries = [];
- let removedFederatedLibraries = [];
- // Funzione per aprire/chiudere la seconda barra laterale
- function toggleExpandedSidebar() {
- const expandedSidebar = document.getElementById('expandedSidebar');
- expandedSidebar.classList.toggle('open');
- }
- // Add this new function for legend toggle
- function toggleLegendSidebar() {
- const legendSidebar = document.getElementById('legendSidebar');
- const legendBtn = document.getElementById('legendBtn');
- const expandedSidebar = document.getElementById('expandedSidebar');
- const federateSidebar = document.getElementById('federateSidebar');
- const searchContainer = document.getElementById('searchContainer');
- // Rimuovo la classe active da tutti i pulsanti
- document.querySelectorAll('.sidebar button').forEach(button => {
- button.classList.remove('active');
- });
- // Chiudo gli altri pannelli
- expandedSidebar.classList.remove('open');
- federateSidebar.classList.remove('open');
- if (searchContainer) {
- searchContainer.style.display = 'none';
- }
- // Gestisco l'apertura/chiusura del pannello legenda
- legendSidebar.classList.toggle('open');
- if (legendSidebar.classList.contains('open')) {
- legendBtn.classList.add('active');
- } else {
- legendBtn.classList.remove('active');
- }
- }
- // Modifica la funzione toggleLegend esistente per chiamare toggleLegendSidebar
- function toggleLegend() {
- toggleLegendSidebar();
- }
- // Funzione per cercare una biblioteca e aprire il popup corrispondente
- async function searchLibrary() {
- const searchTerm = document.getElementById('start-point').value.toLowerCase();
- if (!searchTerm) return;
- try {
- const response = await fetch('libraries.json');
- const data = await response.json();
- // Trova la biblioteca cercata
- const foundLibrary = data.libraries.find(library =>
- library.name.toLowerCase().includes(searchTerm)
- );
- if (foundLibrary) {
- // Trova tutte le biblioteche dello stesso municipio
- const librariesInMunicipio = data.libraries.filter(library =>
- library.municipality === foundLibrary.municipality
- );
- // Mostra il municipio e le biblioteche
- showMunicipioAndLibraries(foundLibrary.municipality, librariesInMunicipio);
- } else {
- alert('Biblioteca non trovata. Riprova.');
- }
- } catch (error) {
- console.error('Errore nella ricerca della biblioteca:', error);
- alert('Errore nella ricerca. Riprova.');
- }
- }
- function showMunicipioAndLibraries(municipioNumber, libraries) {
- const resultsContainer = document.getElementById('search-results');
- // Svuota il contenuto precedente
- resultsContainer.innerHTML = '';
- // Aggiungi il titolo del municipio
- const municipioDiv = document.createElement('div');
- municipioDiv.className = 'municipio-title';
- municipioDiv.textContent = `Municipio ${romanize(municipioNumber)}`;
- resultsContainer.appendChild(municipioDiv);
- // Aggiungi le biblioteche del municipio
- libraries.forEach(library => {
- const libraryDiv = document.createElement('div');
- libraryDiv.className = 'library-item';
- libraryDiv.textContent = library.name;
- libraryDiv.onclick = () => selectLibrary(library);
- resultsContainer.appendChild(libraryDiv);
- });
- // Mostra il riquadro dei risultati solo se ci sono biblioteche
- if (libraries.length > 0) {
- resultsContainer.style.display = 'block';
- } else {
- resultsContainer.style.display = 'none';
- }
- // Evidenzia il municipio sulla mappa
- loadAndShowBorder(municipioNumber, map);
- highlightLegendItem(municipioNumber);
- selectedMunicipio = municipioNumber;
- }
- function selectLibrary(library) {
- let foundMarker = null;
- map.eachLayer((layer) => {
- if (layer instanceof L.Marker) {
- const pos = layer.getLatLng();
- if (pos.lat === library.coords[0] && pos.lng === library.coords[1]) {
- foundMarker = layer;
- }
- }
- });
- if (foundMarker) {
- foundMarker.openPopup();
- map.setView(foundMarker.getLatLng(), 14);
- loadAndShowBorder(library.municipality, map);
- highlightLegendItem(library.municipality);
- selectedMunicipio = library.municipality;
- } else {
- console.log('Marker not found for library:', library);
- }
- // Nascondi il riquadro dei risultati
- const resultsContainer = document.getElementById('search-results');
- if (resultsContainer) {
- resultsContainer.style.display = 'none';
- }
- }
- // Funzione per aprire/chiudere il pannello delle biblioteche federate
- function toggleFederateSidebar() {
- const federateSidebar = document.getElementById('federateSidebar');
- const federateBtn = document.getElementById('federateBtn');
- const expandedSidebar = document.getElementById('expandedSidebar');
- const searchContainer = document.getElementById('searchContainer');
- // Rimuovo la classe active da tutti i pulsanti
- document.querySelectorAll('.sidebar button').forEach(button => {
- button.classList.remove('active');
- });
- // Chiudo il pannello di ricerca se aperto
- expandedSidebar.classList.remove('open');
- if (searchContainer) {
- searchContainer.style.display = 'none';
- }
- // Gestisco l'apertura/chiusura del pannello federate
- federateSidebar.classList.toggle('open');
- if (federateSidebar.classList.contains('open')) {
- federateBtn.classList.add('active');
- } else {
- federateBtn.classList.remove('active');
- }
- }
- function toggleSearch() {
- const searchBtn = document.getElementById('searchBtn');
- const expandedSidebar = document.getElementById('expandedSidebar');
- const searchContainer = document.getElementById('searchContainer');
- const federateSidebar = document.getElementById('federateSidebar');
- const federateBtn = document.getElementById('federateBtn');
- // Rimuovo la classe active da tutti i pulsanti eccetto searchBtn
- document.querySelectorAll('.sidebar button').forEach(button => {
- if (button !== searchBtn) {
- button.classList.remove('active');
- }
- });
- // Chiudo il pannello federate se aperto
- federateSidebar.classList.remove('open');
- federateBtn.classList.remove('active');
- // Verifico se il pannello di ricerca è già aperto
- const isSearchOpen = expandedSidebar.classList.contains('open');
- if (isSearchOpen) {
- // Se il pannello di ricerca è aperto, lo chiudo
- expandedSidebar.classList.remove('open');
- searchBtn.classList.remove('active');
- searchContainer.style.display = 'none';
- } else {
- // Se il pannello di ricerca è chiuso, lo apro
- expandedSidebar.classList.add('open');
- searchBtn.classList.add('active');
- const startPoint = document.getElementById('start-point');
- startPoint.placeholder = "Cerca biblioteca o indirizzo...";
- const searchButton = searchContainer.querySelector('button');
- searchButton.textContent = "Cerca";
- searchButton.onclick = async function() {
- const searchQuery = startPoint.value.toLowerCase();
- try {
- const response = await fetch('libraries.json');
- const data = await response.json();
- const foundLibrary = data.libraries.find(lib =>
- lib.name.toLowerCase().includes(searchQuery)
- );
- if (foundLibrary) {
- const municipioLibraries = data.libraries.filter(lib =>
- lib.municipality === foundLibrary.municipality
- );
- showMunicipioAndLibraries(foundLibrary.municipality, municipioLibraries);
- return;
- }
- } catch (error) {
- console.error('Errore nella ricerca della biblioteca:', error);
- }
- searchRoute();
- };
- searchContainer.style.display = 'block';
- }
- }
- // Funzione per resettare il campo di ricerca
- function clearSearchField() {
- const searchInput = document.getElementById('start-point');
- searchInput.value = '';
- searchInput.focus();
- toggleClearButton();
- }
- // Funzione per mostrare/nascondere il pulsante "x"
- function toggleClearButton() {
- const searchInput = document.getElementById('start-point');
- const clearButton = document.getElementById('clear-search');
- if (searchInput.value.trim() !== '') {
- clearButton.style.display = 'inline-block'; // Mostra la "x"
- } else {
- clearButton.style.display = 'none'; // Nascondi la "x"
- }
- }
- // Aggiungi un listener per l'input nel campo di ricerca
- document.getElementById('start-point').addEventListener('input', toggleClearButton);
- // Aggiungi un listener per l'input nel campo di ricerca
- document.getElementById('start-point').addEventListener('input', toggleClearButton);
- // Funzione helper per caricare e visualizzare il confine di un municipio
- async function loadAndShowBorder(municipalityNumber, map) {
- // Se c'è già un confine visualizzato, rimuovilo
- if (currentBorder) {
- map.removeLayer(currentBorder);
- }
- try {
- const response = await fetch(`municipio${municipalityNumber}.geojson`);
- const data = await response.json();
- currentBorder = L.geoJSON(data, {
- style: {
- color: municipalityColors[municipalityNumber],
- weight: 3,
- opacity: 0.65,
- fillOpacity: 0.2
- }
- }).addTo(map);
- map.fitBounds(currentBorder.getBounds());
- } catch (error) {
- console.error(`Errore nel caricamento del confine del municipio ${municipalityNumber}:`, error);
- }
- }
- // Funzione per evidenziare la voce della legenda
- function highlightLegendItem(municipioNumber) {
- const allItems = document.querySelectorAll('.legend-item');
- allItems.forEach(item => item.classList.remove('highlighted'));
- const item = document.querySelector(`.legend-item[data-municipio="${municipioNumber}"]`);
- if (item) {
- item.classList.add('highlighted');
- }
- }
- window.highlightLegendItem = highlightLegendItem;
- document.addEventListener("DOMContentLoaded", async function() {
- // Initialize map
- const center = [41.732522, 12.271879];
- map = L.map("map", {
- zoomControl: false
- }).setView(center, 14);
- // Add zoom control to the right side with custom CSS class
- const zoomControl = L.control.zoom({
- position: 'topright'
- });
- zoomControl.addTo(map);
- // Add custom CSS to the zoom control container after it's added to the map
- const zoomContainer = zoomControl.getContainer();
- zoomContainer.style.marginTop = '22px';
- L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
- maxZoom: 19,
- attribution: "© OpenStreetMap contributors"
- }).addTo(map);
- // Definizione del percorso
- const pathPoints = [
- center,
- [41.732154, 12.271675],
- [41.732282, 12.271254],
- [41.73224, 12.27123],
- [41.732276, 12.27109],
- [41.732092, 12.27098]
- ];
- // Creazione della linea tratteggiata
- const dottedLine = L.polyline(pathPoints, {
- color: "#0000FF",
- weight: 4,
- opacity: 0.8,
- dashArray: "10, 10"
- }).addTo(map);
- // Punto finale del percorso
- const endPoint = pathPoints[pathPoints.length - 1];
- // Definizione della funzione createMarker
- function createMarker(coords, title, icon, popupContent, municipioNumber, map) {
- const marker = L.marker(coords, { title, icon });
- if (map) {
- marker.addTo(map);
- }
- marker.on('click', () => {
- if (selectedMunicipio === municipioNumber) {
- // Deseleziona se cliccato nuovamente
- if (currentBorder) {
- map.removeLayer(currentBorder);
- currentBorder = null;
- }
- selectedMunicipio = null;
- const item = document.querySelector(`.legend-item[data-municipio="${municipioNumber}"]`);
- if (item) {
- item.classList.remove('highlighted');
- }
- } else {
- // Seleziona il municipio
- loadAndShowBorder(municipioNumber, map);
- highlightLegendItem(municipioNumber);
- selectedMunicipio = municipioNumber;
- }
- });
- const popup = L.popup({
- className: 'custom-popup',
- offset: [0, -10],
- closeButton: true
- }).setContent(popupContent);
- marker.bindPopup(popup);
- return marker;
- }
- const icons = getIconsConfig();
- // Spazio dove erano i marker per le biblioteche...
- // Carica le biblioteche dal file JSON
- // Dopo aver caricato le biblioteche dal file JSON
- try {
- const response = await fetch('libraries.json');
- const data = await response.json();
- // Add this line to make data globally accessible
- window.libraryData = data;
- // Popola il datalist con i nomi delle biblioteche
- const customDatalist = document.getElementById('library-suggestions');
- // Aggiungi sia le biblioteche normali che quelle federate al datalist
- [...data.libraries, ...data.federate].forEach(library => {
- const option = document.createElement('div');
- option.textContent = library.name;
- option.onclick = () => {
- document.getElementById('start-point').value = library.name;
- customDatalist.style.display = 'none';
- searchLibrary();
- };
- customDatalist.appendChild(option);
- });
- // Mostra/nascondi il menu personalizzato quando il campo di ricerca è focalizzato
- document.getElementById('start-point').addEventListener('focus', () => {
- customDatalist.style.display = 'block';
- });
- document.getElementById('start-point').addEventListener('blur', () => {
- setTimeout(() => {
- customDatalist.style.display = 'none';
- }, 200);
- });
- function filterSuggestions(searchText) {
- const customDatalist = document.getElementById('library-suggestions');
- const options = customDatalist.querySelectorAll('div');
- options.forEach(option => {
- const libraryName = option.textContent.toLowerCase();
- if (libraryName.includes(searchText.toLowerCase())) {
- option.style.display = 'block'; // Mostra l'opzione
- } else {
- option.style.display = 'none'; // Nascondi l'opzione
- }
- });
- // Mostra il menu solo se ci sono opzioni visibili
- const visibleOptions = Array.from(options).filter(option => option.style.display !== 'none');
- if (visibleOptions.length > 0) {
- customDatalist.style.display = 'block';
- } else {
- customDatalist.style.display = 'none';
- }
- }
- document.getElementById('start-point').addEventListener('input', (e) => {
- const searchText = e.target.value;
- filterSuggestions(searchText);
- });
- document.addEventListener('click', (e) => {
- const customDatalist = document.getElementById('library-suggestions');
- const searchInput = document.getElementById('start-point');
- if (e.target !== searchInput && e.target !== customDatalist) {
- customDatalist.style.display = 'none';
- }
- });
- // Crea i marker per ogni biblioteca
- data.libraries.forEach(library => {
- const popupContent = `
- <div class="baloon">
- <h3>${library.name}</h3>
- <p style="font-size: 15px;">
- ${library.address} <br>
- ${library.cap} Municipio ${library.municipalityName}
- </p>
- <a style="color: #bc0b34; font-size: 16px;" href="${library.url}">
- Vai alla scheda
- </a>
- </div>
- `;
- createMarker(
- library.coords,
- library.name,
- icons[`municipio${library.municipality}`],
- popupContent,
- library.municipality,
- map
- );
- });
- // Crea i marker per le biblioteche federate
- // Memorizza i marker delle biblioteche federate in un array
- window.federatedMarkers = data.federate.map(library => {
- const popupContent = `
- <div class="baloon">
- <h3>${library.name}</h3>
- <p style="font-size: 15px;">
- ${library.address}<br>
- ${library.libraryType} - ${library.system}
- </p>
- <a style="color: #bc0b34; font-size: 16px;" href="${library.url}">
- Vai alla scheda
- </a>
- </div>
- `;
- // Seleziona l'icona appropriata in base al sistema bibliotecario
- const iconKey = library.system.includes('Roma Tre') ? 'uniroma3' :
- library.system.includes('CASTELLI ROMANI') ? 'castelli' :
- library.system.includes('Ceretano-Sabatino') ? 'ceretano' :
- library.system.includes('Monti Prenestini') ? 'prenestini' :
- library.system.includes('LUMSA') ? 'lumsa' :
- library.system.includes('Foro Italico') ? 'foro' :
- library.system.includes('Tor Vergata') ? 'vergata' :
- library.system.includes('La Sapienza') ? 'sapienza' :
- library.system.includes('Link') ? 'link' : 'municipio1'; // fallback icon
- return createMarker(
- library.coords,
- library.name,
- icons[iconKey],
- popupContent,
- null, // non c'è un municipio associato
- null // non aggiungere alla mappa inizialmente
- );
- });
- } catch (error) {
- console.error('Errore nel caricamento delle biblioteche:', error);
- }
- async function showMunicipioI() {
- // Rimuovi il layer precedente se esiste
- if (municipioLayer) {
- map.removeLayer(municipioLayer);
- }
- try {
- const response = await fetch('municipio1.geojson');
- const data = await response.json();
- municipioLayer = L.geoJSON(data, {
- style: {
- color: '#6a3f3a',
- weight: 3,
- opacity: 0.65,
- fillOpacity: 0
- }
- }).addTo(map);
- map.fitBounds(municipioLayer.getBounds());
- } catch (error) {
- console.error('Errore nel caricamento del confine:', error);
- }
- }
- window.searchRoute = async function() {
- const startPoint = document.getElementById('start-point').value;
- if (routingControl) {
- map.removeControl(routingControl);
- }
- try {
- const response = await axios.get('https://nominatim.openstreetmap.org/search', {
- params: {
- q: startPoint,
- format: 'json',
- limit: 1
- }
- });
- if (response.data.length > 0) {
- const startCoords = [
- parseFloat(response.data[0].lat),
- parseFloat(response.data[0].lon)
- ];
- routingControl = L.Routing.control({
- waypoints: [
- L.latLng(startCoords[0], startCoords[1]),
- L.latLng(center[0], center[1])
- ],
- routeWhileDragging: true,
- language: 'it',
- show: true,
- addWaypoints: false,
- draggableWaypoints: false,
- fitSelectedRoutes: true,
- lineOptions: {
- styles: [{color: '#0000FF', opacity: 0.8, weight: 5}]
- },
- createMarker: function(i, waypoint, n) {
- const closeBtn = document.createElement('button');
- closeBtn.innerHTML = '✕';
- closeBtn.className = 'routing-close-btn';
- closeBtn.onclick = function() {
- map.removeControl(routingControl);
- };
- // Append close button to routing container
- setTimeout(() => {
- const container = document.querySelector('.leaflet-routing-container');
- if (container) {
- container.appendChild(closeBtn);
- }
- }, 100);
- return null; // No markers for waypoints
- }
- }).addTo(map);
- } else {
- alert('Indirizzo non trovato. Riprova.');
- }
- } catch (error) {
- console.error('Errore nella ricerca del percorso:', error);
- alert('Errore nel trovare il percorso. Riprova.');
- }
- }
- document.getElementById('start-point').addEventListener('keypress', function(event) {
- if (event.key === 'Enter') {
- const searchButton = document.querySelector('#searchContainer button');
- if (searchButton.textContent === "Cerca Biblioteca") {
- searchLibrary();
- } else {
- searchRoute();
- }
- }
- });
- document.getElementById('start-point').focus();
- // Fetch and display the municipality border
- fetch('municipio10.geojson')
- .then(response => response.json())
- .then(data => {
- // Carica il municipio X di default
- municipioLayers[10] = L.geoJSON(data, {
- style: {
- color: municipalityColors[10],
- weight: 3,
- opacity: 0.65,
- fillOpacity: 0
- }
- }).addTo(map);
- // Popola la legenda
- // Modifica questa parte nel codice JavaScript dove viene popolata la legenda
- const legendContainer = document.querySelector('.legend-container .legend-grid');
- if (legendContainer) {
- legendContainer.innerHTML = Object.entries(municipalityColors).map(([num, color]) => {
- const municipioLibraries = window.libraryData.libraries
- .filter(lib => lib.municipality === parseInt(num))
- .map(lib => `<div class="library-item-legend" onclick="selectLibrary(${JSON.stringify(lib)})">${lib.name}</div>`)
- .join('');
- return `
- <div class="legend-item" data-municipio="${num}">
- <div class="legend-item-header" onclick="handleMunicipioClick(${num}, event)">
- <span style="background: ${color}"></span>
- <div class="text">Municipio ${romanize(parseInt(num))}</div>
- </div>
- <button class="expand-button" onclick="toggleLibrariesList(${num}, event)"></button>
- <div class="libraries-list">
- ${municipioLibraries}
- </div>
- </div>
- `;
- }).join('');
- }
- // Aggiungi queste nuove funzioni
- window.handleMunicipioClick = function(municipioNumber, event) {
- event.stopPropagation();
- // Gestisci solo la selezione del municipio
- handleLegendClick(municipioNumber, null);
- };
- window.toggleLibrariesList = function(municipioNumber, event) {
- event.stopPropagation();
- const legendItem = document.querySelector(`.legend-item[data-municipio="${municipioNumber}"]`);
- const librariesList = legendItem.querySelector('.libraries-list');
- legendItem.classList.toggle('expanded');
- librariesList.classList.toggle('expanded');
- };
- // Gestore hover sulla legenda
- // Funzione per gestire l'hover sulla legenda
- window.handleLegendHover = async function(municipioNumber) {
- // Non mostrare l'hover se il municipio è già selezionato
- if (municipioNumber === selectedMunicipio) return;
- const item = document.querySelector(`.legend-item[data-municipio="${municipioNumber}"]`);
- item.classList.add('highlighted');
- if (!municipioLayers[municipioNumber]) {
- try {
- const response = await fetch(`municipio${municipioNumber}.geojson`);
- const data = await response.json();
- municipioLayers[municipioNumber] = L.geoJSON(data, {
- style: {
- color: municipalityColors[municipioNumber],
- weight: 4,
- opacity: 0.9,
- fillOpacity: 0.1
- }
- });
- } catch (error) {
- console.error(`Error loading municipality ${municipioNumber}:`, error);
- return;
- }
- }
- if (currentHighlight && currentHighlight !== currentBorder) {
- map.removeLayer(currentHighlight);
- }
- currentHighlight = municipioLayers[municipioNumber].addTo(map).bringToFront();
- };
- // Funzione per gestire l'uscita del mouse dalla legenda
- window.handleLegendOut = function(municipioNumber) {
- if (municipioNumber === selectedMunicipio) return;
- const item = document.querySelector(`.legend-item[data-municipio="${municipioNumber}"]`);
- item.classList.remove('highlighted');
- if (currentHighlight && currentHighlight !== currentBorder) {
- map.removeLayer(currentHighlight);
- currentHighlight = null;
- }
- // Se c'è un municipio selezionato, assicurati che rimanga visibile
- if (selectedMunicipio && currentBorder) {
- currentBorder.bringToFront();
- }
- };
- // Funzione per gestire il click sulla legenda
- window.handleLegendClick = async function(municipioNumber, event) {
- if (event) {
- event.stopPropagation();
- }
- // Rimuovi la parte che gestisce l'espansione e mantieni solo la logica di selezione del municipio
- const allItems = document.querySelectorAll('.legend-item');
- allItems.forEach(item => item.classList.remove('highlighted'));
- if (selectedMunicipio === municipioNumber) {
- if (currentBorder) {
- map.removeLayer(currentBorder);
- currentBorder = null;
- }
- if (municipioNumber === 10) {
- municipioLayers[10].setStyle({
- color: municipalityColors[10],
- weight: 3,
- opacity: 0.65,
- fillOpacity: 0
- });
- }
- selectedMunicipio = null;
- return;
- }
- // Carica il GeoJSON se non è già stato caricato
- if (!municipioLayers[municipioNumber]) {
- try {
- const response = await fetch(`municipio${municipioNumber}.geojson`);
- const data = await response.json();
- municipioLayers[municipioNumber] = L.geoJSON(data, {
- style: {
- color: municipalityColors[municipioNumber],
- weight: 4,
- opacity: 0.9,
- fillOpacity: 0.2
- }
- });
- } catch (error) {
- console.error(`Error loading municipality ${municipioNumber}:`, error);
- return;
- }
- }
- // Rimuovi il bordo precedente se non è il municipio X
- if (currentBorder && currentBorder !== municipioLayers[10]) {
- map.removeLayer(currentBorder);
- }
- selectedMunicipio = municipioNumber;
- const item = document.querySelector(`.legend-item[data-municipio="${municipioNumber}"]`);
- if (item) {
- item.classList.add('highlighted');
- }
- // Gestione speciale per il municipio X
- if (municipioNumber === 10) {
- municipioLayers[10].setStyle({
- color: municipalityColors[10],
- weight: 6,
- opacity: 1,
- fillOpacity: 0.3
- }).bringToFront();
- currentBorder = municipioLayers[10];
- } else {
- // Per altri municipi, aggiungi il nuovo bordo
- currentBorder = municipioLayers[municipioNumber].addTo(map).bringToFront();
- }
- map.fitBounds(currentBorder.getBounds());
- };
- // Modifica della funzione handleLegendOut
- window.handleLegendOut = function(municipioNumber) {
- if (municipioNumber === selectedMunicipio) return;
- const item = document.querySelector(`.legend-item[data-municipio="${municipioNumber}"]`);
- item.classList.remove('highlighted');
- if (currentHighlight && currentHighlight !== currentBorder) {
- map.removeLayer(currentHighlight);
- currentHighlight = null;
- }
- // Se c'è un municipio selezionato, assicurati che rimanga visibile
- if (selectedMunicipio && currentBorder) {
- currentBorder.bringToFront();
- }
- // Assicurati che il municipio X rimanga sempre visibile
- if (municipioLayers[10]) {
- municipioLayers[10].bringToFront();
- }
- };
- })
- .catch(error => console.error('Errore nel caricamento dei confini:', error));
- });
- function toggleRomeLibraries() {
- const button = document.getElementById('toggleRomeLibraries');
- if (romeLibrariesVisible) {
- // Fase di nascondimento
- removedRomeLibraries = []; // Resetta l'array
- map.eachLayer((layer) => {
- if (layer instanceof L.Marker) {
- const libraryName = layer.options.title;
- const isRomeLibrary = window.libraryData.libraries.some(lib => lib.name === libraryName);
- if (isRomeLibrary) {
- removedRomeLibraries.push(layer); // Memorizza il marker
- layer.remove(); // Rimuovi dalla mappa
- }
- }
- });
- button.textContent = 'Mostra Biblioteche di Roma';
- romeLibrariesVisible = false;
- } else {
- // Fase di ricomparsa
- removedRomeLibraries.forEach(marker => {
- marker.addTo(map); // Riaggiunge tutti i marker memorizzati
- });
- button.textContent = 'Nascondi Biblioteche di Roma';
- romeLibrariesVisible = true;
- removedRomeLibraries = []; // Resetta l'array dopo il ripristino
- }
- }
- function toggleFederatedLibraries() {
- const button = document.getElementById('toggleFederatedLibraries');
- if (federatedLibrariesVisible) {
- // Nascondi le biblioteche federate
- window.federatedMarkers.forEach(marker => {
- if (map.hasLayer(marker)) {
- map.removeLayer(marker);
- }
- });
- button.textContent = 'Mostra Biblioteche Federate';
- federatedLibrariesVisible = false;
- } else {
- // Mostra le biblioteche federate
- window.federatedMarkers.forEach(marker => {
- if (!map.hasLayer(marker)) {
- marker.addTo(map);
- }
- });
- button.textContent = 'Nascondi Biblioteche federate';
- federatedLibrariesVisible = true;
- }
- }
- function resetMap() {
- // Reset del campo di ricerca
- const searchInput = document.getElementById('start-point');
- searchInput.value = '';
- // Rimuovi il controllo del percorso se presente
- if (routingControl) {
- map.removeControl(routingControl);
- routingControl = null;
- }
- // Reset della vista della mappa
- const center = [41.732522, 12.271879];
- map.setView(center, 14);
- // Reset del municipio selezionato
- if (selectedMunicipio) {
- if (currentBorder) {
- map.removeLayer(currentBorder);
- currentBorder = null;
- }
- selectedMunicipio = null;
- }
- // Reset dell'evidenziazione nella legenda
- const allItems = document.querySelectorAll('.legend-item');
- allItems.forEach(item => item.classList.remove('highlighted'));
- // Nascondi i risultati della ricerca
- const searchResults = document.getElementById('search-results');
- if (searchResults) {
- searchResults.style.display = 'none';
- }
- // Reset del municipio X allo stile originale
- if (municipioLayers[10]) {
- municipioLayers[10].setStyle({
- color: municipalityColors[10],
- weight: 3,
- opacity: 0.65,
- fillOpacity: 0
- });
- }
- }
- function zoomToSystemLibraries(systemName) {
- // Verifica se ci sono marker delle biblioteche federate
- if (!window.federatedMarkers) {
- console.error('Marker delle biblioteche federate non trovati');
- return;
- }
- // Mappatura dei nomi dei sistemi alle stringhe di ricerca nei popup
- const systemMappings = {
- 'CASTELLI ROMANI': 'CASTELLI ROMANI',
- 'Ceretano-Sabatino': 'Ceretano-Sabatino',
- 'Monti Prenestini': 'Monti Prenestini',
- 'LUMSA': 'LUMSA',
- 'Foro Italico': 'Foro Italico',
- 'Link': 'Link Campus',
- 'La Sapienza': 'La Sapienza',
- 'Tor Vergata': 'Tor Vergata',
- 'Roma Tre': 'Roma Tre'
- };
- const searchString = systemMappings[systemName] || systemName;
- // Filtra i marker del sistema bibliotecario specificato
- const systemMarkers = window.federatedMarkers.filter(marker => {
- const popupContent = marker.getPopup().getContent();
- return popupContent.includes(searchString);
- });
- if (systemMarkers.length === 0) {
- console.log('Nessun marker trovato per il sistema:', systemName);
- return;
- }
- // Crea un gruppo di layer per calcolare i bounds
- const group = L.featureGroup(systemMarkers);
- // Se le biblioteche federate non sono visibili, mostrale
- if (!federatedLibrariesVisible) {
- toggleFederatedLibraries();
- }
- // Rimuovi l'evidenziazione precedente se presente
- window.federatedMarkers.forEach(marker => {
- const icon = marker.getIcon();
- if (icon.options.className) {
- icon.options.className = '';
- marker.setIcon(icon);
- }
- });
- // Aggiungi tutti i marker del sistema alla mappa e evidenziali
- systemMarkers.forEach(marker => {
- if (!map.hasLayer(marker)) {
- marker.addTo(map);
- }
- // Evidenzia i marker del sistema selezionato
- const icon = marker.getIcon();
- icon.options.className = 'highlighted-marker';
- marker.setIcon(icon);
- });
- // Calcola i bounds e applica lo zoom con padding
- const bounds = group.getBounds();
- map.fitBounds(bounds, {
- padding: [50, 50], // Padding di 50 pixel su tutti i lati
- maxZoom: 13, // Limita lo zoom massimo per una vista migliore
- duration: 0.5 // Durata dell'animazione in secondi
- });
- // Mostra il numero di biblioteche trovate
- const count = systemMarkers.length;
- const message = `Trovate ${count} biblioteche del sistema ${systemName}`;
- console.log(message);
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement