var map, featureList; var curaepresidioSearch = []; var attivitaformazioneSearch = []; var legalitaedirittiSearch = []; var obiettiviamministrazioneSearch = []; var attivitaculturaliSearch = []; var attivitasanitarieSearch = []; var attivitaeducativeSearch = []; $(window).resize(function() { sizeLayerControl(); }); $(document).on("click", ".feature-row", function(e) { $(document).off("mouseout", ".feature-row", clearHighlight); sidebarClick(parseInt($(this).attr("id"), 10)); }); if ( !("ontouchstart" in window) ) { $(document).on("mouseover", ".feature-row", function(e) { highlight.clearLayers().addLayer(L.circleMarker([$(this).attr("lat"), $(this).attr("lng")], highlightStyle)); }); } $(document).on("mouseout", ".feature-row", clearHighlight); $("#about-btn").click(function() { $("#aboutModal").modal("show"); $(".navbar-collapse.in").collapse("hide"); return false; }); /* $("#full-extent-btn").click(function() { map.fitBounds(singola.getBounds()); $(".navbar-collapse.in").collapse("hide"); return false; }); */ $("#legend-btn").click(function() { $("#legendModal").modal("show"); $(".navbar-collapse.in").collapse("hide"); return false; }); $("#login-btn").click(function() { $("#loginModal").modal("show"); $(".navbar-collapse.in").collapse("hide"); return false; }); $("#list-btn").click(function() { animateSidebar(); return false; }); $("#nav-btn").click(function() { $(".navbar-collapse").collapse("toggle"); return false; }); $("#sidebar-toggle-btn").click(function() { animateSidebar(); return false; }); $("#sidebar-hide-btn").click(function() { animateSidebar(); return false; }); function animateSidebar() { $("#sidebar").animate({ width: "toggle" }, 350, function() { map.invalidateSize(); }); } function sizeLayerControl() { $(".leaflet-control-layers").css("max-height", $("#map").height() - 50); } function clearHighlight() { highlight.clearLayers(); } function sidebarClick(id) { var layer = markerClusters.getLayer(id); map.setView([layer.getLatLng().lat, layer.getLatLng().lng], 17); layer.fire("click"); /* Hide sidebar and go to the map on small screens */ if (document.body.clientWidth <= 767) { $("#sidebar").hide(); map.invalidateSize(); } } function syncSidebar() { /* Empty sidebar features */ $("#feature-list tbody").empty(); /* Loop through theaters layer and add only features which are in the map bounds */ curaepresidio.eachLayer(function (layer) { if (map.hasLayer(curaepresidioLayer)) { if (map.getBounds().contains(layer.getLatLng())) { var appendString = ' '; appendString +=layer.feature.properties.nome + ' ' $("#feature-list tbody").append(appendString); } } }); /* Loop through theaters layer and add only features which are in the map bounds */ attivitaformazione.eachLayer(function (layer) { if (map.hasLayer(attivitaformazioneLayer)) { if (map.getBounds().contains(layer.getLatLng())) { var appendString = ' '; appendString +=layer.feature.properties.nome + ' ' $("#feature-list tbody").append(appendString); } } }); /* Loop through theaters layer and add only features which are in the map bounds */ legalitaediritti.eachLayer(function (layer) { if (map.hasLayer(legalitaedirittiLayer)) { if (map.getBounds().contains(layer.getLatLng())) { var appendString = ' '; appendString +=layer.feature.properties.nome + ' ' $("#feature-list tbody").append(appendString); } } }); /* Loop through theaters layer and add only features which are in the map bounds */ obiettiviamministrazione.eachLayer(function (layer) { if (map.hasLayer(obiettiviamministrazioneLayer)) { if (map.getBounds().contains(layer.getLatLng())) { var appendString = ' '; appendString +=layer.feature.properties.nome + ' ' $("#feature-list tbody").append(appendString); } } }); /* Loop through theaters layer and add only features which are in the map bounds */ attivitaculturali.eachLayer(function (layer) { if (map.hasLayer(attivitaculturaliLayer)) { if (map.getBounds().contains(layer.getLatLng())) { var appendString = ' '; appendString +=layer.feature.properties.nome + ' ' $("#feature-list tbody").append(appendString); } } }); /* Loop through theaters layer and add only features which are in the map bounds */ attivitasanitarie.eachLayer(function (layer) { if (map.hasLayer(attivitasanitarieLayer)) { if (map.getBounds().contains(layer.getLatLng())) { var appendString = ' '; appendString +=layer.feature.properties.nome + ' ' $("#feature-list tbody").append(appendString); } } }); /* Loop through theaters layer and add only features which are in the map bounds */ attivitaeducative.eachLayer(function (layer) { if (map.hasLayer(attivitaeducativeLayer)) { if (map.getBounds().contains(layer.getLatLng())) { var appendString = ' '; appendString +=layer.feature.properties.nome + ' ' $("#feature-list tbody").append(appendString); } } }); /* Update list.js featureList */ featureList = new List("features", { valueNames: ["feature-name"] }); featureList.sort("feature-name", { order: "asc" }); } /* basemap */ var osmBaseMap = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap © CartoDB', subdomains: 'abcd', maxZoom: 19 }); /* var osmBaseMap = L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png", { maxZoom: 19, attribution: '© OpenStreetMap contributors' }); */ var highlight = L.geoJson(null); var highlightStyle = { stroke: false, fillColor: "#00FFFF", fillOpacity: 0.7, radius: 10 }; /* Single marker cluster layer to hold all clusters */ var markerClusters = new L.MarkerClusterGroup({ spiderfyOnMaxZoom: true, showCoverageOnHover: false, zoomToBoundsOnClick: true, disableClusteringAtZoom: 16 }); /* geojson layer configuration */ var curaepresidioLayer = L.geoJson(null); var curaepresidio = L.geoJson(null, { pointToLayer: function (feature, latlng) { return L.marker(latlng, { icon: L.icon({ iconUrl: "assets/img/ciclica.png", iconSize: [24, 28], iconAnchor: [12, 28], popupAnchor: [0, -25] }), title: feature.properties.nome, riseOnHover: true }); }, onEachFeature: function (feature, layer) { if (feature.properties) { var image = ''; if (feature.properties.tipo == 'associazione') { var imagePath = 'pictures/associazioni/'+feature.properties.immagine; image = ''; } var content = image; if (feature.properties.tipo == 'soggetto') { content = content + "
" + "
Nome " + feature.properties.nome + "
Luogo " + feature.properties.luogo + "
"; } else if (feature.properties.tipo == 'associazione') { content = content + "
" + "" + "" + "" + "" + "
Nome " + feature.properties.nome + "
Sede legale " + feature.properties.sede_legale + "
Sede operativa " + feature.properties.sede_operativa + "
Email " + feature.properties.email + "
Facebook " + feature.properties.facebook + "
Sito web " + feature.properties.sito + "
"; } else { content = content + "
"+ "" + "" + "" + "" + "
Azione " + feature.properties.nome + "
Soggetto promotore " + (('soggetto promotore' in feature.properties) ? feature.properties['soggetto promotore'] : '') + "
Soggetti " + feature.properties.soggetti + "
Tipologia " + feature.properties.tipologia + "
Luoghi " + feature.properties.luoghi + "
Ambito " + feature.properties.ambito + "
"; } layer.on({ click: function (e) { $("#feature-title").html(feature.properties.nome); $("#feature-info").html(content); $("#featureModal").modal("show"); highlight.clearLayers().addLayer(L.circleMarker([feature.geometry.coordinates[1], feature.geometry.coordinates[0]], highlightStyle)); } }); var appendFeature = ' '; appendFeature+= layer.feature.properties.nome + ' '; $("#feature-list tbody").append(appendFeature); curaepresidioSearch.push({ name: layer.feature.properties.nome, address: layer.feature.properties.sede_legale, source: "curaepresidio", id: L.stamp(layer), lat: layer.feature.geometry.coordinates[1], lng: layer.feature.geometry.coordinates[0] }); } } }); $.getJSON("data/associazioni/curaepresidio.geojson", function (data) { curaepresidio.addData(data); map.addLayer(curaepresidioLayer); }); var attivitaformazioneLayer = L.geoJson(null); var attivitaformazione = L.geoJson(null, { pointToLayer: function (feature, latlng) { return L.marker(latlng, { icon: L.icon({ iconUrl: "assets/img/ciclica.png", iconSize: [24, 28], iconAnchor: [12, 28], popupAnchor: [0, -25] }), title: feature.properties.nome, riseOnHover: true }); }, onEachFeature: function (feature, layer) { if (feature.properties) { var image = ''; if (feature.properties.tipo == 'associazione') { var imagePath = 'pictures/associazioni/'+feature.properties.immagine; image = ''; } var content = image; if (feature.properties.tipo == 'soggetto') { content = content + "
" + "
Nome " + feature.properties.nome + "
Luogo " + feature.properties.luogo + "
"; } else if (feature.properties.tipo == 'associazione') { content = content + "
" + "" + "" + "" + "" + "
Nome " + feature.properties.nome + "
Sede legale " + feature.properties.sede_legale + "
Sede operativa " + feature.properties.sede_operativa + "
Email " + feature.properties.email + "
Facebook " + feature.properties.facebook + "
Sito web " + feature.properties.sito + "
"; } else { content = content + "
"+ "" + "" + "" + "" + "
Azione " + feature.properties.nome + "
Soggetto promotore " + (('soggetto promotore' in feature.properties) ? feature.properties['soggetto promotore'] : '') + "
Soggetti " + feature.properties.soggetti + "
Tipologia " + feature.properties.tipologia + "
Luoghi " + feature.properties.luoghi + "
Ambito " + feature.properties.ambito + "
"; } layer.on({ click: function (e) { $("#feature-title").html(feature.properties.nome); $("#feature-info").html(content); $("#featureModal").modal("show"); highlight.clearLayers().addLayer(L.circleMarker([feature.geometry.coordinates[1], feature.geometry.coordinates[0]], highlightStyle)); } }); var appendFeature = ' '; appendFeature+= layer.feature.properties.nome + ' '; $("#feature-list tbody").append(appendFeature); attivitaformazioneSearch.push({ name: layer.feature.properties.nome, address: layer.feature.properties.sede_legale, source: "attivitaformazione", id: L.stamp(layer), lat: layer.feature.geometry.coordinates[1], lng: layer.feature.geometry.coordinates[0] }); } } }); $.getJSON("data/associazioni/attivitaformazione.geojson", function (data) { attivitaformazione.addData(data); map.addLayer(attivitaformazioneLayer); }); var legalitaedirittiLayer = L.geoJson(null); var legalitaediritti = L.geoJson(null, { pointToLayer: function (feature, latlng) { return L.marker(latlng, { icon: L.icon({ iconUrl: "assets/img/ciclica.png", iconSize: [24, 28], iconAnchor: [12, 28], popupAnchor: [0, -25] }), title: feature.properties.nome, riseOnHover: true }); }, onEachFeature: function (feature, layer) { if (feature.properties) { var image = ''; if (feature.properties.tipo == 'associazione') { var imagePath = 'pictures/associazioni/'+feature.properties.immagine; image = ''; } var content = image; if (feature.properties.tipo == 'soggetto') { content = content + "
" + "
Nome " + feature.properties.nome + "
Luogo " + feature.properties.luogo + "
"; } else if (feature.properties.tipo == 'associazione') { content = content + "
" + "" + "" + "" + "" + "
Nome " + feature.properties.nome + "
Sede legale " + feature.properties.sede_legale + "
Sede operativa " + feature.properties.sede_operativa + "
Email " + feature.properties.email + "
Facebook " + feature.properties.facebook + "
Sito web " + feature.properties.sito + "
"; } else { content = content + "
"+ "" + "" + "" + "" + "
Azione " + feature.properties.nome + "
Soggetto promotore " + (('soggetto promotore' in feature.properties) ? feature.properties['soggetto promotore'] : '') + "
Soggetti " + feature.properties.soggetti + "
Tipologia " + feature.properties.tipologia + "
Luoghi " + feature.properties.luoghi + "
Ambito " + feature.properties.ambito + "
"; } layer.on({ click: function (e) { $("#feature-title").html(feature.properties.nome); $("#feature-info").html(content); $("#featureModal").modal("show"); highlight.clearLayers().addLayer(L.circleMarker([feature.geometry.coordinates[1], feature.geometry.coordinates[0]], highlightStyle)); } }); var appendFeature = ' '; appendFeature+= layer.feature.properties.nome + ' '; $("#feature-list tbody").append(appendFeature); legalitaedirittiSearch.push({ name: layer.feature.properties.nome, address: layer.feature.properties.sede_legale, source: "legalitaediritti", id: L.stamp(layer), lat: layer.feature.geometry.coordinates[1], lng: layer.feature.geometry.coordinates[0] }); } } }); $.getJSON("data/associazioni/legalitaediritti.geojson", function (data) { legalitaediritti.addData(data); map.addLayer(legalitaedirittiLayer); }); var obiettiviamministrazioneLayer = L.geoJson(null); var obiettiviamministrazione = L.geoJson(null, { pointToLayer: function (feature, latlng) { return L.marker(latlng, { icon: L.icon({ iconUrl: "assets/img/ciclica.png", iconSize: [24, 28], iconAnchor: [12, 28], popupAnchor: [0, -25] }), title: feature.properties.nome, riseOnHover: true }); }, onEachFeature: function (feature, layer) { if (feature.properties) { var image = ''; if (feature.properties.tipo == 'associazione') { var imagePath = 'pictures/associazioni/'+feature.properties.immagine; image = ''; } var content = image; if (feature.properties.tipo == 'soggetto') { content = content + "
" + "
Nome " + feature.properties.nome + "
Luogo " + feature.properties.luogo + "
"; } else if (feature.properties.tipo == 'associazione') { content = content + "
" + "" + "" + "" + "" + "
Nome " + feature.properties.nome + "
Sede legale " + feature.properties.sede_legale + "
Sede operativa " + feature.properties.sede_operativa + "
Email " + feature.properties.email + "
Facebook " + feature.properties.facebook + "
Sito web " + feature.properties.sito + "
"; } else { content = content + "
"+ "" + "" + "" + "" + "
Azione " + feature.properties.nome + "
Soggetto promotore " + (('soggetto promotore' in feature.properties) ? feature.properties['soggetto promotore'] : '') + "
Soggetti " + feature.properties.soggetti + "
Tipologia " + feature.properties.tipologia + "
Luoghi " + feature.properties.luoghi + "
Ambito " + feature.properties.ambito + "
"; } layer.on({ click: function (e) { $("#feature-title").html(feature.properties.nome); $("#feature-info").html(content); $("#featureModal").modal("show"); highlight.clearLayers().addLayer(L.circleMarker([feature.geometry.coordinates[1], feature.geometry.coordinates[0]], highlightStyle)); } }); var appendFeature = ' '; appendFeature+= layer.feature.properties.nome + ' '; $("#feature-list tbody").append(appendFeature); obiettiviamministrazioneSearch.push({ name: layer.feature.properties.nome, address: layer.feature.properties.sede_legale, source: "obiettiviamministrazione", id: L.stamp(layer), lat: layer.feature.geometry.coordinates[1], lng: layer.feature.geometry.coordinates[0] }); } } }); $.getJSON("data/associazioni/obiettiviamministrazione.geojson", function (data) { obiettiviamministrazione.addData(data); map.addLayer(obiettiviamministrazioneLayer); }); var attivitaculturaliLayer = L.geoJson(null); var attivitaculturali = L.geoJson(null, { pointToLayer: function (feature, latlng) { return L.marker(latlng, { icon: L.icon({ iconUrl: "assets/img/ciclica.png", iconSize: [24, 28], iconAnchor: [12, 28], popupAnchor: [0, -25] }), title: feature.properties.nome, riseOnHover: true }); }, onEachFeature: function (feature, layer) { if (feature.properties) { var image = ''; if (feature.properties.tipo == 'associazione') { var imagePath = 'pictures/associazioni/'+feature.properties.immagine; image = ''; } var content = image; if (feature.properties.tipo == 'soggetto') { content = content + "
" + "
Nome " + feature.properties.nome + "
Luogo " + feature.properties.luogo + "
"; } else if (feature.properties.tipo == 'associazione') { content = content + "
" + "" + "" + "" + "" + "
Nome " + feature.properties.nome + "
Sede legale " + feature.properties.sede_legale + "
Sede operativa " + feature.properties.sede_operativa + "
Email " + feature.properties.email + "
Facebook " + feature.properties.facebook + "
Sito web " + feature.properties.sito + "
"; } else { content = content + "
"+ "" + "" + "" + "" + "
Azione " + feature.properties.nome + "
Soggetto promotore " + (('soggetto promotore' in feature.properties) ? feature.properties['soggetto promotore'] : '') + "
Soggetti " + feature.properties.soggetti + "
Tipologia " + feature.properties.tipologia + "
Luoghi " + feature.properties.luoghi + "
Ambito " + feature.properties.ambito + "
"; } layer.on({ click: function (e) { $("#feature-title").html(feature.properties.nome); $("#feature-info").html(content); $("#featureModal").modal("show"); highlight.clearLayers().addLayer(L.circleMarker([feature.geometry.coordinates[1], feature.geometry.coordinates[0]], highlightStyle)); } }); var appendFeature = ' '; appendFeature+= layer.feature.properties.nome + ' '; $("#feature-list tbody").append(appendFeature); attivitaculturaliSearch.push({ name: layer.feature.properties.nome, address: layer.feature.properties.sede_legale, source: "attivitaculturali", id: L.stamp(layer), lat: layer.feature.geometry.coordinates[1], lng: layer.feature.geometry.coordinates[0] }); } } }); $.getJSON("data/associazioni/attivitaculturali.geojson", function (data) { attivitaculturali.addData(data); map.addLayer(attivitaculturaliLayer); }); var attivitasanitarieLayer = L.geoJson(null); var attivitasanitarie = L.geoJson(null, { pointToLayer: function (feature, latlng) { return L.marker(latlng, { icon: L.icon({ iconUrl: "assets/img/ciclica.png", iconSize: [24, 28], iconAnchor: [12, 28], popupAnchor: [0, -25] }), title: feature.properties.nome, riseOnHover: true }); }, onEachFeature: function (feature, layer) { if (feature.properties) { var image = ''; if (feature.properties.tipo == 'associazione') { var imagePath = 'pictures/associazioni/'+feature.properties.immagine; image = ''; } var content = image; if (feature.properties.tipo == 'soggetto') { content = content + "
" + "
Nome " + feature.properties.nome + "
Luogo " + feature.properties.luogo + "
"; } else if (feature.properties.tipo == 'associazione') { content = content + "
" + "" + "" + "" + "" + "
Nome " + feature.properties.nome + "
Sede legale " + feature.properties.sede_legale + "
Sede operativa " + feature.properties.sede_operativa + "
Email " + feature.properties.email + "
Facebook " + feature.properties.facebook + "
Sito web " + feature.properties.sito + "
"; } else { content = content + "
"+ "" + "" + "" + "" + "
Azione " + feature.properties.nome + "
Soggetto promotore " + (('soggetto promotore' in feature.properties) ? feature.properties['soggetto promotore'] : '') + "
Soggetti " + feature.properties.soggetti + "
Tipologia " + feature.properties.tipologia + "
Luoghi " + feature.properties.luoghi + "
Ambito " + feature.properties.ambito + "
"; } layer.on({ click: function (e) { $("#feature-title").html(feature.properties.nome); $("#feature-info").html(content); $("#featureModal").modal("show"); highlight.clearLayers().addLayer(L.circleMarker([feature.geometry.coordinates[1], feature.geometry.coordinates[0]], highlightStyle)); } }); var appendFeature = ' '; appendFeature+= layer.feature.properties.nome + ' '; $("#feature-list tbody").append(appendFeature); attivitasanitarieSearch.push({ name: layer.feature.properties.nome, address: layer.feature.properties.sede_legale, source: "attivitasanitarie", id: L.stamp(layer), lat: layer.feature.geometry.coordinates[1], lng: layer.feature.geometry.coordinates[0] }); } } }); $.getJSON("data/associazioni/attivitasanitarie.geojson", function (data) { attivitasanitarie.addData(data); map.addLayer(attivitasanitarieLayer); }); var attivitaeducativeLayer = L.geoJson(null); var attivitaeducative = L.geoJson(null, { pointToLayer: function (feature, latlng) { return L.marker(latlng, { icon: L.icon({ iconUrl: "assets/img/ciclica.png", iconSize: [24, 28], iconAnchor: [12, 28], popupAnchor: [0, -25] }), title: feature.properties.nome, riseOnHover: true }); }, onEachFeature: function (feature, layer) { if (feature.properties) { var image = ''; if (feature.properties.tipo == 'associazione') { var imagePath = 'pictures/associazioni/'+feature.properties.immagine; image = ''; } var content = image; if (feature.properties.tipo == 'soggetto') { content = content + "
" + "
Nome " + feature.properties.nome + "
Luogo " + feature.properties.luogo + "
"; } else if (feature.properties.tipo == 'associazione') { content = content + "
" + "" + "" + "" + "" + "
Nome " + feature.properties.nome + "
Sede legale " + feature.properties.sede_legale + "
Sede operativa " + feature.properties.sede_operativa + "
Email " + feature.properties.email + "
Facebook " + feature.properties.facebook + "
Sito web " + feature.properties.sito + "
"; } else { content = content + "
"+ "" + "" + "" + "" + "
Azione " + feature.properties.nome + "
Soggetto promotore " + (('soggetto promotore' in feature.properties) ? feature.properties['soggetto promotore'] : '') + "
Soggetti " + feature.properties.soggetti + "
Tipologia " + feature.properties.tipologia + "
Luoghi " + feature.properties.luoghi + "
Ambito " + feature.properties.ambito + "
"; } layer.on({ click: function (e) { $("#feature-title").html(feature.properties.nome); $("#feature-info").html(content); $("#featureModal").modal("show"); highlight.clearLayers().addLayer(L.circleMarker([feature.geometry.coordinates[1], feature.geometry.coordinates[0]], highlightStyle)); } }); var appendFeature = ' '; appendFeature+= layer.feature.properties.nome + ' '; $("#feature-list tbody").append(appendFeature); attivitaeducativeSearch.push({ name: layer.feature.properties.nome, address: layer.feature.properties.sede_legale, source: "attivitaeducative", id: L.stamp(layer), lat: layer.feature.geometry.coordinates[1], lng: layer.feature.geometry.coordinates[0] }); } } }); $.getJSON("data/associazioni/attivitaeducative.geojson", function (data) { attivitaeducative.addData(data); map.addLayer(attivitaeducativeLayer); }); map = L.map("map", { zoom: 14, center: [44.4182, 8.9322], layers: [osmBaseMap, markerClusters, highlight], zoomControl: false, attributionControl: false }); /* Layer control listeners that allow for a single markerClusters layer */ map.on("overlayadd", function(e) { if (e.layer === curaepresidioLayer) { markerClusters.addLayer(curaepresidio); syncSidebar(); } if (e.layer === attivitaformazioneLayer) { markerClusters.addLayer(attivitaformazione); syncSidebar(); } if (e.layer === legalitaedirittiLayer) { markerClusters.addLayer(legalitaediritti); syncSidebar(); } if (e.layer === obiettiviamministrazioneLayer) { markerClusters.addLayer(obiettiviamministrazione); syncSidebar(); } if (e.layer === attivitaculturaliLayer) { markerClusters.addLayer(attivitaculturali); syncSidebar(); } if (e.layer === attivitasanitarieLayer) { markerClusters.addLayer(attivitasanitarie); syncSidebar(); } if (e.layer === attivitaeducativeLayer) { markerClusters.addLayer(attivitaeducative); syncSidebar(); } }); map.on("overlayremove", function(e) { if (e.layer === curaepresidioLayer) { markerClusters.removeLayer(curaepresidio); syncSidebar(); } if (e.layer === attivitaformazioneLayer) { markerClusters.removeLayer(attivitaformazione); syncSidebar(); } if (e.layer === legalitaedirittiLayer) { markerClusters.removeLayer(legalitaediritti); syncSidebar(); } if (e.layer === obiettiviamministrazioneLayer) { markerClusters.removeLayer(obiettiviamministrazione); syncSidebar(); } if (e.layer === attivitaculturaliLayer) { markerClusters.removeLayer(attivitaculturali); syncSidebar(); } if (e.layer === attivitasanitarieLayer) { markerClusters.removeLayer(attivitasanitarie); syncSidebar(); } if (e.layer === attivitaeducativeLayer) { markerClusters.removeLayer(attivitaeducative); syncSidebar(); } }); /* Filter sidebar feature list to only show features in current map bounds */ map.on("moveend", function (e) { syncSidebar(); }); /* Clear feature highlight when map is clicked */ map.on("click", function(e) { highlight.clearLayers(); }); /* Attribution control */ function updateAttribution(e) { $.each(map._layers, function(index, layer) { if (layer.getAttribution) { $("#attribution").html((layer.getAttribution())); } }); } map.on("layeradd", updateAttribution); map.on("layerremove", updateAttribution); var attributionControl = L.control({ position: "bottomright" }); attributionControl.onAdd = function (map) { var div = L.DomUtil.create("div", "leaflet-control-attribution"); div.innerHTML = "Attribution"; return div; }; map.addControl(attributionControl); /* var zoomControl = L.control.zoom({ position: "bottomright" }).addTo(map); */ var zoomHome = L.Control.zoomHome({position: 'bottomright'}); zoomHome.addTo(map); /* GPS enabled geolocation control set to follow the user's location */ var locateControl = L.control.locate({ position: "bottomright", drawCircle: true, follow: true, setView: true, keepCurrentZoomLevel: true, markerStyle: { weight: 1, opacity: 0.8, fillOpacity: 0.8 }, circleStyle: { weight: 1, clickable: false }, icon: "fa fa-location-arrow", metric: false, strings: { title: "La mia posizione", popup: "Sei entro {distance} {unit} da questo punto", outsideMapBoundsMsg: "Sembri posizionato al di fuori dei confini della mappa" }, locateOptions: { maxZoom: 18, watch: true, enableHighAccuracy: true, maximumAge: 10000, timeout: 10000 } }).addTo(map); /* Larger screens get expanded layer control and visible sidebar */ if (document.body.clientWidth <= 767) { var isCollapsed = true; } else { var isCollapsed = false; } var baseLayers = { "Mappa": osmBaseMap }; var groupedOverlays = { "Cura e presidio del territorio": { " Cura e presidio del territorio": curaepresidioLayer, }, "Attività di formazione": { " Attività di formazione": attivitaformazioneLayer, }, "Attività di promozione della legalità e dei diritti": { " Attività di promozione della legalità e dei diritti": legalitaedirittiLayer, }, "Condivisione con amministrazione degli obiettivi e ricerca delle soluzioni": { " Condivisione con amministrazione degli obiettivi e ricerca delle soluzioni": obiettiviamministrazioneLayer, }, "Attività culturali": { " Attività culturali": attivitaculturaliLayer, }, "Attività sanitarie e/o socio-assistenziali": { " Attività sanitarie e/o socio-assistenziali": attivitasanitarieLayer, }, "Attività educative, formative, artistiche": { " Attività educative, formative, artistiche": attivitaeducativeLayer, }, }; L.Control.GroupedLayers.include({ addOverlays: function () { for (var i in this._layers) { if (this._layers[i].overlay) { if (!this._map.hasLayer(this._layers[i].layer)) { this._map.addLayer(this._layers[i].layer); } } } }, removeOverlays: function () { for (var i in this._layers) { if (this._layers[i].overlay) { if (this._map.hasLayer(this._layers[i].layer)) { this._map.removeLayer(this._layers[i].layer); } } } } }); var layerControl = L.control.groupedLayers(baseLayers, groupedOverlays, { collapsed: isCollapsed }).addTo(map); /* Highlight search box text on click */ $("#searchbox").click(function () { $(this).select(); }); /* Prevent hitting enter from refreshing the page */ $("#searchbox").keypress(function (e) { if (e.which == 13) { e.preventDefault(); } }); $("#featureModal").on("hidden.bs.modal", function (e) { $(document).on("mouseout", ".feature-row", clearHighlight); }); /* Typeahead search functionality */ $(document).one("ajaxStop", function () { $("#loading").hide(); sizeLayerControl(); /* Fit map to main layer bounds */ /*map.fitBounds(singola.getBounds());*/ featureList = new List("features", {valueNames: ["feature-name"]}); featureList.sort("feature-name", {order:"asc"}); var curaepresidioBH = new Bloodhound({ name: "curaepresidio", datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.name); }, queryTokenizer: Bloodhound.tokenizers.whitespace, local: curaepresidioSearch, limit: 10 }); curaepresidioBH.initialize(); var attivitaformazioneBH = new Bloodhound({ name: "attivitaformazione", datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.name); }, queryTokenizer: Bloodhound.tokenizers.whitespace, local: attivitaformazioneSearch, limit: 10 }); attivitaformazioneBH.initialize(); var legalitaedirittiBH = new Bloodhound({ name: "legalitaediritti", datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.name); }, queryTokenizer: Bloodhound.tokenizers.whitespace, local: legalitaedirittiSearch, limit: 10 }); legalitaedirittiBH.initialize(); var obiettiviamministrazioneBH = new Bloodhound({ name: "obiettiviamministrazione", datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.name); }, queryTokenizer: Bloodhound.tokenizers.whitespace, local: obiettiviamministrazioneSearch, limit: 10 }); obiettiviamministrazioneBH.initialize(); var attivitaculturaliBH = new Bloodhound({ name: "attivitaculturali", datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.name); }, queryTokenizer: Bloodhound.tokenizers.whitespace, local: attivitaculturaliSearch, limit: 10 }); attivitaculturaliBH.initialize(); var attivitasanitarieBH = new Bloodhound({ name: "attivitasanitarie", datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.name); }, queryTokenizer: Bloodhound.tokenizers.whitespace, local: attivitasanitarieSearch, limit: 10 }); attivitasanitarieBH.initialize(); var attivitaeducativeBH = new Bloodhound({ name: "attivitaeducative", datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.name); }, queryTokenizer: Bloodhound.tokenizers.whitespace, local: attivitaeducativeSearch, limit: 10 }); attivitaeducativeBH.initialize(); /* instantiate the typeahead UI */ $("#searchbox").typeahead({ minLength: 3, highlight: true, hint: false }, { name: "curaepresidio", displayKey: "name", source: curaepresidioBH.ttAdapter(), templates: { header: "

 curaepresidio

", suggestion: Handlebars.compile(["{{name}}
 {{address}}"].join("")) } }, { name: "attivitaformazione", displayKey: "name", source: attivitaformazioneBH.ttAdapter(), templates: { header: "

 attivitaformazione

", suggestion: Handlebars.compile(["{{name}}
 {{address}}"].join("")) } }, { name: "legalitaediritti", displayKey: "name", source: legalitaedirittiBH.ttAdapter(), templates: { header: "

 legalitaediritti

", suggestion: Handlebars.compile(["{{name}}
 {{address}}"].join("")) } }, { name: "obiettiviamministrazione", displayKey: "name", source: obiettiviamministrazioneBH.ttAdapter(), templates: { header: "

 obiettiviamministrazione

", suggestion: Handlebars.compile(["{{name}}
 {{address}}"].join("")) } }, { name: "attivitaculturali", displayKey: "name", source: attivitaculturaliBH.ttAdapter(), templates: { header: "

 attivitaculturali

", suggestion: Handlebars.compile(["{{name}}
 {{address}}"].join("")) } }, { name: "attivitasanitarie", displayKey: "name", source: attivitasanitarieBH.ttAdapter(), templates: { header: "

 attivitasanitarie

", suggestion: Handlebars.compile(["{{name}}
 {{address}}"].join("")) } }, { name: "attivitaeducative", displayKey: "name", source: attivitaeducativeBH.ttAdapter(), templates: { header: "

 attivitaeducative

", suggestion: Handlebars.compile(["{{name}}
 {{address}}"].join("")) } }).on("typeahead:selected", function (obj, datum) { if (datum.source === "curaepresidio") { if (!map.hasLayer(curaepresidioLayer)) { map.addLayer(curaepresidioLayer); } map.setView([datum.lat, datum.lng], 17); if (map._layers[datum.id]) { map._layers[datum.id].fire("click"); } } if (datum.source === "attivitaformazione") { if (!map.hasLayer(attivitaformazioneLayer)) { map.addLayer(attivitaformazioneLayer); } map.setView([datum.lat, datum.lng], 17); if (map._layers[datum.id]) { map._layers[datum.id].fire("click"); } } if (datum.source === "legalitaediritti") { if (!map.hasLayer(legalitaedirittiLayer)) { map.addLayer(legalitaedirittiLayer); } map.setView([datum.lat, datum.lng], 17); if (map._layers[datum.id]) { map._layers[datum.id].fire("click"); } } if (datum.source === "obiettiviamministrazione") { if (!map.hasLayer(obiettiviamministrazioneLayer)) { map.addLayer(obiettiviamministrazioneLayer); } map.setView([datum.lat, datum.lng], 17); if (map._layers[datum.id]) { map._layers[datum.id].fire("click"); } } if (datum.source === "attivitaculturali") { if (!map.hasLayer(attivitaculturaliLayer)) { map.addLayer(attivitaculturaliLayer); } map.setView([datum.lat, datum.lng], 17); if (map._layers[datum.id]) { map._layers[datum.id].fire("click"); } } if (datum.source === "attivitasanitarie") { if (!map.hasLayer(attivitasanitarieLayer)) { map.addLayer(attivitasanitarieLayer); } map.setView([datum.lat, datum.lng], 17); if (map._layers[datum.id]) { map._layers[datum.id].fire("click"); } } if (datum.source === "attivitaeducative") { if (!map.hasLayer(attivitaeducativeLayer)) { map.addLayer(attivitaeducativeLayer); } map.setView([datum.lat, datum.lng], 17); if (map._layers[datum.id]) { map._layers[datum.id].fire("click"); } } }).on("typeahead:opened", function () { $(".navbar-collapse.in").css("max-height", $(document).height() - $(".navbar-header").height()); $(".navbar-collapse.in").css("height", $(document).height() - $(".navbar-header").height()); }).on("typeahead:closed", function () { $(".navbar-collapse.in").css("max-height", ""); $(".navbar-collapse.in").css("height", ""); }); $(".twitter-typeahead").css("position", "static"); $(".twitter-typeahead").css("display", "block"); }); // Leaflet patch to make layer control scrollable on touch browsers var container = $(".leaflet-control-layers")[0]; if (!L.Browser.touch) { L.DomEvent .disableClickPropagation(container) .disableScrollPropagation(container); } else { L.DomEvent.disableClickPropagation(container); }