Gestione mappe OpenStreetMap

This commit is contained in:
MatteoPistorello 2023-06-15 14:09:04 +02:00
parent c678362e5b
commit 92f4e62c2d
12 changed files with 218 additions and 226 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -120,6 +120,8 @@ const JS = gulp.parallel(() => {
'datatables.net-buttons-bs/js/buttons.bootstrap.js', 'datatables.net-buttons-bs/js/buttons.bootstrap.js',
'smartwizard/dist/js/jquery.smartWizard.min.js', 'smartwizard/dist/js/jquery.smartWizard.min.js',
'bootstrap-maxlength/dist/bootstrap-maxlength.js', 'bootstrap-maxlength/dist/bootstrap-maxlength.js',
'leaflet/dist/leaflet.js',
'leaflet-gesture-handling/dist/leaflet-gesture-handling.min.js',
]; ];
for (const i in vendor) { for (const i in vendor) {
@ -178,6 +180,8 @@ const CSS = gulp.parallel(() => {
'select2-bootstrap-theme/dist/select2-bootstrap.css', 'select2-bootstrap-theme/dist/select2-bootstrap.css',
'smartwizard/dist/css/smart_wizard.min.css', 'smartwizard/dist/css/smart_wizard.min.css',
'smartwizard/dist/css/smart_wizard_theme_arrows.min.css', 'smartwizard/dist/css/smart_wizard_theme_arrows.min.css',
'leaflet-gesture-handling/dist/leaflet-gesture-handling.min.css',
'leaflet/dist/leaflet.css',
]; ];
for (const i in vendor) { for (const i in vendor) {
@ -244,6 +248,15 @@ function srcImages() {
.pipe(gulp.dest(config.production + '/' + config.paths.images)); .pipe(gulp.dest(config.production + '/' + config.paths.images));
} }
function leaflet() {
return gulp.src([
config.nodeDirectory + '/leaflet/dist/images/*.{jpg,png,jpeg}',
])
.pipe(flatten())
.pipe(gulp.dest(config.production + '/' + config.paths.images + '/leaflet'));
}
// Elaborazione dei fonts // Elaborazione dei fonts
const fonts = gulp.parallel(() => { const fonts = gulp.parallel(() => {
@ -516,7 +529,7 @@ function clean() {
} }
// Operazioni di default per la generazione degli assets // Operazioni di default per la generazione degli assets
const bower = gulp.series(clean, gulp.parallel(JS, CSS, images, fonts, phpDebugBar, ckeditor, colorpicker, i18n, pdfjs, hotkeys, chartjs, password_strength, csrf)); const bower = gulp.series(clean, gulp.parallel(JS, CSS, images, fonts, phpDebugBar, ckeditor, colorpicker, i18n, pdfjs, hotkeys, chartjs, password_strength, csrf, leaflet));
// Debug su CSS e JS // Debug su CSS e JS
exports.srcJS = srcJS; exports.srcJS = srcJS;

View File

@ -245,8 +245,6 @@ $sede_cliente = $anagrafica->sedeLegale;
$anagrafica_azienda = Anagrafica::find(setting('Azienda predefinita')); $anagrafica_azienda = Anagrafica::find(setting('Azienda predefinita'));
$sede_azienda = $anagrafica_azienda->sedeLegale; $sede_azienda = $anagrafica_azienda->sedeLegale;
$google = setting('Google Maps API key');
echo ' echo '
<div class="col-md-4"> <div class="col-md-4">
<div class="panel panel-primary"> <div class="panel panel-primary">
@ -257,13 +255,7 @@ echo '
$map_load_message = tr('Clicca per visualizzare'); $map_load_message = tr('Clicca per visualizzare');
if (empty($google)) { if (!empty($sede_cliente->gaddress) || (!empty($sede_cliente->lat) && !empty($sede_cliente->lng))) {
echo '
<div class="alert alert-info">
'.Modules::link('Impostazioni', null, tr('Per abilitare la visualizzazione delle anagrafiche nella mappa, inserire la Google Maps API Key nella scheda Impostazioni'), true, null, true, null, '&search=Google Maps API key').'.
</div>';
} elseif (!empty($sede_cliente->gaddress) || (!empty($sede_cliente->lat) && !empty($sede_cliente->lng))) {
echo ' echo '
<div id="map-edit" style="height: 200px;width: 100%;display: flex;align-items: center;justify-content: center;" onclick="caricaMappa()"> <div id="map-edit" style="height: 200px;width: 100%;display: flex;align-items: center;justify-content: center;" onclick="caricaMappa()">
<p class="clickable badge">'.$map_load_message.'</p> <p class="clickable badge">'.$map_load_message.'</p>
@ -294,10 +286,10 @@ if (empty($google)) {
'.((!empty($sede_cliente->lat) && !empty($sede_azienda->lat)) ? tr('(GPS)'): '' ).' '.((!empty($sede_cliente->lat) && !empty($sede_azienda->lat)) ? tr('(GPS)'): '' ).'
</a>'; </a>';
// Ricerca diretta su Google Maps // Ricerca diretta su Mappa
echo ' echo '
<a class="btn btn-info btn-block" onclick="cercaGoogleMaps()"> <a class="btn btn-info btn-block" onclick="cercaOpenStreetMap()">
<i class="fa fa-map-marker"></i> '.tr('Cerca su Google Maps').' <i class="fa fa-map-marker"></i> '.tr('Cerca su Mappa').'
'.((!empty($sede_cliente->lat)) ? tr(' (GPS)'): '' ).' '.((!empty($sede_cliente->lat)) ? tr(' (GPS)'): '' ).'
</a>'; </a>';
@ -312,15 +304,19 @@ echo '
openModal("'.tr('Modifica posizione').'", "'.$module->fileurl('modals/posizione.php').'?id_module='.$id_module.'&id_record='.$id_record.'"); openModal("'.tr('Modifica posizione').'", "'.$module->fileurl('modals/posizione.php').'?id_module='.$id_module.'&id_record='.$id_record.'");
} }
function cercaGoogleMaps() { function cercaOpenStreetMap() {
const indirizzo = getIndirizzoAnagrafica(); const indirizzo = getIndirizzoAnagrafica();
window.open("https://maps.google.com/maps/search/" + indirizzo); if (indirizzo[0] && indirizzo[1]) {
window.open("https://www.openstreetmap.org/?mlat=" + indirizzo[0] + "&mlon=" + indirizzo[1] + "#map=12/" + indirizzo[0] + "/" + indirizzo[1]);
} else {
window.open("https://www.openstreetmap.org/search?query=" + indirizzo[2]);
}
} }
function calcolaPercorso() { function calcolaPercorso() {
const indirizzo_partenza = getIndirizzoAzienda(); const indirizzo_partenza = getIndirizzoAzienda();
const indirizzo_destinazione = getIndirizzoAnagrafica(); const indirizzo_destinazione = getIndirizzoAnagrafica();
window.open("https://www.google.com/maps/dir/?api=1&origin=" + indirizzo_partenza + "&destination=" + indirizzo_destinazione); window.open("https://www.openstreetmap.org/directions?engine=fossgis_osrm_car&route=" + indirizzo_partenza + ";" + indirizzo_destinazione[0] + "," + indirizzo_destinazione[1]);
} }
function getIndirizzoAzienda() { function getIndirizzoAzienda() {
@ -330,9 +326,6 @@ echo '
const lat = parseFloat("'.$sede_azienda->lat.'"); const lat = parseFloat("'.$sede_azienda->lat.'");
const lng = parseFloat("'.$sede_azienda->lng.'"); const lng = parseFloat("'.$sede_azienda->lng.'");
const indirizzo_default = encodeURI(indirizzo) + "," + encodeURI(citta);
if (!lat || !lng) return indirizzo_default;
return lat + "," + lng; return lat + "," + lng;
} }
@ -344,9 +337,8 @@ echo '
const lng = parseFloat("'.$sede_cliente->lng.'"); const lng = parseFloat("'.$sede_cliente->lng.'");
const indirizzo_default = encodeURI(indirizzo) + "," + encodeURI(citta); const indirizzo_default = encodeURI(indirizzo) + "," + encodeURI(citta);
if (!lat || !lng) return indirizzo_default;
return lat + "," + lng; return [lat, lng, indirizzo_default];
} }
function caricaMappa() { function caricaMappa() {
@ -355,32 +347,32 @@ echo '
return; return;
} }
$.getScript("//maps.googleapis.com/maps/api/js?libraries=places&key='.$google.'", function() { const lat = parseFloat("'.$sede_cliente->lat.'");
const map_element = map_div[0]; const lng = parseFloat("'.$sede_cliente->lng.'");
const lat = parseFloat("'.$sede_cliente->lat.'");
const lng = parseFloat("'.$sede_cliente->lng.'");
if (!lat || !lng) return; var map = L.map("map-edit", {
const position = new google.maps.LatLng(lat, lng); center: [lat, lng],
zoom: 10,
gestureHandling: true
});
// Create a Google Maps native view under the map_canvas div. var icon = new L.Icon({
const map = new google.maps.Map(map_element, { iconUrl: globals.rootdir + "/assets/dist/img/marker-icon.png",
zoom: 14, shadowUrl:globals.rootdir + "/assets/dist/img/leaflet/marker-shadow.png",
scrollwheel: false, iconSize: [25, 41],
mapTypeControl: true, iconAnchor: [12, 41],
mapTypeId: "roadmap", popupAnchor: [1, -34],
mapTypeControlOptions: { shadowSize: [41, 41]
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, });
mapTypeIds: ["roadmap", "terrain"],
}
});
map.setCenter(position); L.tileLayer("'.setting("Tile layer OpenStreetMap").'", {
const marker = new google.maps.Marker({ maxZoom: 17,
position: position, attribution: "© OpenStreetMap"
map: map, }).addTo(map);
});
}); var marker = L.marker([lat, lng], {
icon: icon
}).addTo(map);
} }
function risolviConto(tipo){ function risolviConto(tipo){

View File

@ -20,8 +20,6 @@
include_once __DIR__.'/../../../core.php'; include_once __DIR__.'/../../../core.php';
include_once __DIR__.'/../init.php'; include_once __DIR__.'/../init.php';
$google = setting('Google Maps API key');
echo ' echo '
<form action="" method="post" id="form-posizione"> <form action="" method="post" id="form-posizione">
<input type="hidden" name="backto" value="record-edit"> <input type="hidden" name="backto" value="record-edit">
@ -29,16 +27,20 @@ echo '
<div class="row"> <div class="row">
<div class="col-md-4" id="geocomplete"> <div class="col-md-4" id="geocomplete">
{[ "type": "text", "label": "'.tr('Indirizzo Google').'", "name": "gaddress", "value": "'.$record['gaddress'].'", "extra": "data-geo=\'formatted_address\'" ]} {[ "type": "text", "label": "'.tr('Indirizzo').'", "name": "gaddress", "value": "'.$record['gaddress'].'", "extra": "data-geo=\'formatted_address\'" ]}
</div> </div>
<div class="col-md-4"> <div class="col-md-3">
{[ "type": "text", "label": "'.tr('Latitudine').'", "name": "lat", "value": "'.$record['lat'].'", "extra": "data-geo=\'lat\'", "class": "text-right" ]} {[ "type": "text", "label": "'.tr('Latitudine').'", "name": "lat", "value": "'.$record['lat'].'", "extra": "data-geo=\'lat\'", "class": "text-right" ]}
</div> </div>
<div class="col-md-4"> <div class="col-md-3">
{[ "type": "text", "label": "'.tr('Longitudine').'", "name": "lng", "value": "'.$record['lng'].'", "extra": "data-geo=\'lng\'", "class": "text-right" ]} {[ "type": "text", "label": "'.tr('Longitudine').'", "name": "lng", "value": "'.$record['lng'].'", "extra": "data-geo=\'lng\'", "class": "text-right" ]}
</div> </div>
<div class="col-md-2">
<br><button type="button" class="btn btn-lg btn-default pull-right" onclick="initGeocomplete();"><i class="fa fa-search"></i> '.tr('Cerca').'</button>
</div>
</div> </div>
<div class="row"> <div class="row">
@ -61,24 +63,60 @@ echo '
<script>$(document).ready(init)</script> <script>$(document).ready(init)</script>
<script> <script>
if(window.google){ $(document).ready(function(){
initGeocomplete(); if (input("lat").get() && input("lng").get()) {
} else { setTimeout(function () {
$.getScript("//maps.googleapis.com/maps/api/js?libraries=places&key='.$google.'", function() { caricaMappa();
initGeocomplete(); }, 1000);
}
});
function initGeocomplete() {
$.ajax({
url: "https://nominatim.openstreetmap.org/search.php?q=" + encodeURI(input("gaddress").get()) + "&format=jsonv2",
type : "GET",
dataType: "JSON",
success: function(data){
input("lat").set(data[0].lat);
input("lng").set(data[0].lon);
input("gaddress").set(data[0].display_name);
caricaMappa();
}
}); });
} }
function initGeocomplete() { function caricaMappa() {
$("#geocomplete input").geocomplete({ const lat = parseFloat(input("lat").get());
map: $("#map").length ? "#map" : false, const lng = parseFloat(input("lng").get());
location: $("#gaddress").val() ? $("#gaddress").val() : [$("#lat").val(), $("#lng").val()],
details: ".details", var container = L.DomUtil.get("map");
detailsAttribute: "data-geo" if(container != null){
}).bind("geocode:result", function (event, result) { container._leaflet_id = null;
$("#lat").val(result.geometry.location.lat()); }
$("#lng").val(result.geometry.location.lng());
var map = L.map("map", {
center: [lat, lng],
zoom: 10,
gestureHandling: true
}); });
var icon = new L.Icon({
iconUrl: globals.rootdir + "/assets/dist/img/marker-icon.png",
shadowUrl:globals.rootdir + "/assets/dist/img/leaflet/marker-shadow.png",
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
L.tileLayer("'.setting("Tile layer OpenStreetMap").'", {
maxZoom: 17,
attribution: "© OpenStreetMap"
}).addTo(map);
var marker = L.marker([lat, lng], {
icon: icon
}).addTo(map);
} }
// Ricaricamento della pagina alla chiusura // Ricaricamento della pagina alla chiusura

View File

@ -143,8 +143,6 @@ if (!empty($intervento->idsede_destinazione)) {
$anagrafica_azienda = Anagrafica::find(setting('Azienda predefinita')); $anagrafica_azienda = Anagrafica::find(setting('Azienda predefinita'));
$sede_azienda = $anagrafica_azienda->sedeLegale; $sede_azienda = $anagrafica_azienda->sedeLegale;
$google = setting('Google Maps API key');
echo ' echo '
<div class="col-md-4"> <div class="col-md-4">
<div class="panel panel-primary"> <div class="panel panel-primary">
@ -154,12 +152,8 @@ echo '
<div class="panel-body">'; <div class="panel-body">';
$map_load_message = tr('Clicca per visualizzare'); $map_load_message = tr('Clicca per visualizzare');
if (empty($google)) {
echo ' if (!empty($sede_cliente->gaddress) || (!empty($sede_cliente->lat) && !empty($sede_cliente->lng))) {
<div class="alert alert-info">
'.Modules::link('Impostazioni', null, tr('Per abilitare la visualizzazione delle anagrafiche nella mappa, inserire la Google Maps API Key nella scheda Impostazioni'), true, null, true, null, '&search=Google Maps API key').'.
</div>';
} elseif (!empty($sede_cliente->gaddress) || (!empty($sede_cliente->lat) && !empty($sede_cliente->lng))) {
echo ' echo '
<div id="map-edit" style="height: 200px;width: 100%;display: flex;align-items: center;justify-content: center;" onclick="caricaMappa()"> <div id="map-edit" style="height: 200px;width: 100%;display: flex;align-items: center;justify-content: center;" onclick="caricaMappa()">
<p class="clickable badge">'.$map_load_message.'</p> <p class="clickable badge">'.$map_load_message.'</p>
@ -180,10 +174,11 @@ if (empty($google)) {
<i class="fa fa-map-signs"></i> '.tr('Calcola percorso').' <i class="fa fa-map-signs"></i> '.tr('Calcola percorso').'
</a>'; </a>';
// Ricerca diretta su Google Maps // Ricerca diretta su Mappa
echo ' echo '
<a class="btn btn-info btn-block" onclick="cercaGoogleMaps()"> <a class="btn btn-info btn-block" onclick="cercaOpenStreetMap()">
<i class="fa fa-map-marker"></i> '.tr('Cerca su Google Maps').' <i class="fa fa-map-marker"></i> '.tr('Cerca su Mappa').'
'.((!empty($sede_cliente->lat)) ? tr(' (GPS)'): '' ).'
</a>'; </a>';
} }
@ -198,15 +193,19 @@ echo '
openModal("'.tr('Modifica posizione').'", "'.$module->fileurl('modals/posizione.php').'?id_module='.$id_module.'&id_record='.$id_record.'"); openModal("'.tr('Modifica posizione').'", "'.$module->fileurl('modals/posizione.php').'?id_module='.$id_module.'&id_record='.$id_record.'");
} }
function cercaGoogleMaps() { function cercaOpenStreetMap() {
const indirizzo = getIndirizzoAnagrafica(); const indirizzo = getIndirizzoAnagrafica();
window.open("https://maps.google.com/maps/search/" + indirizzo); if (indirizzo[0] && indirizzo[1]) {
window.open("https://www.openstreetmap.org/?mlat=" + indirizzo[0] + "&mlon=" + indirizzo[1] + "#map=12/" + indirizzo[0] + "/" + indirizzo[1]);
} else {
window.open("https://www.openstreetmap.org/search?query=" + indirizzo[2]);
}
} }
function calcolaPercorso() { function calcolaPercorso() {
const indirizzo_partenza = getIndirizzoAzienda(); const indirizzo_partenza = getIndirizzoAzienda();
const indirizzo_destinazione = getIndirizzoAnagrafica(); const indirizzo_destinazione = getIndirizzoAnagrafica();
window.open("https://www.google.com/maps/dir/?api=1&origin=" + indirizzo_partenza + "&destination=" + indirizzo_destinazione); window.open("https://www.openstreetmap.org/directions?engine=fossgis_osrm_car&route=" + indirizzo_partenza + ";" + indirizzo_destinazione[0] + "," + indirizzo_destinazione[1]);
} }
function getIndirizzoAzienda() { function getIndirizzoAzienda() {
@ -216,9 +215,6 @@ echo '
const lat = parseFloat("'.$sede_azienda->lat.'"); const lat = parseFloat("'.$sede_azienda->lat.'");
const lng = parseFloat("'.$sede_azienda->lng.'"); const lng = parseFloat("'.$sede_azienda->lng.'");
const indirizzo_default = encodeURI(indirizzo) + "," + encodeURI(citta);
if (!lat || !lng) return indirizzo_default;
return lat + "," + lng; return lat + "," + lng;
} }
@ -230,9 +226,8 @@ echo '
const lng = parseFloat("'.$sede_cliente->lng.'"); const lng = parseFloat("'.$sede_cliente->lng.'");
const indirizzo_default = encodeURI(indirizzo) + "," + encodeURI(citta); const indirizzo_default = encodeURI(indirizzo) + "," + encodeURI(citta);
if (!lat || !lng) return indirizzo_default;
return lat + "," + lng; return [lat, lng, indirizzo_default];
} }
function caricaMappa() { function caricaMappa() {
@ -241,32 +236,32 @@ echo '
return; return;
} }
$.getScript("//maps.googleapis.com/maps/api/js?libraries=places&key='.$google.'", function() { const lat = parseFloat("'.$sede_cliente->lat.'");
const map_element = map_div[0]; const lng = parseFloat("'.$sede_cliente->lng.'");
const lat = parseFloat("'.$sede_cliente->lat.'");
const lng = parseFloat("'.$sede_cliente->lng.'");
if (!lat || !lng) return; var map = L.map("map-edit", {
const position = new google.maps.LatLng(lat, lng); center: [lat, lng],
zoom: 10,
gestureHandling: true
});
// Create a Google Maps native view under the map_canvas div. var icon = new L.Icon({
const map = new google.maps.Map(map_element, { iconUrl: globals.rootdir + "/assets/dist/img/marker-icon.png",
zoom: 14, shadowUrl:globals.rootdir + "/assets/dist/img/leaflet/marker-shadow.png",
scrollwheel: false, iconSize: [25, 41],
mapTypeControl: true, iconAnchor: [12, 41],
mapTypeId: "roadmap", popupAnchor: [1, -34],
mapTypeControlOptions: { shadowSize: [41, 41]
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, });
mapTypeIds: ["roadmap", "terrain"],
}
});
map.setCenter(position); L.tileLayer("https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png", {
const marker = new google.maps.Marker({ maxZoom: 17,
position: position, attribution: "© OpenStreetMap"
map: map, }).addTo(map);
});
}); var marker = L.marker([lat, lng], {
icon: icon
}).addTo(map);
} }
</script>'; </script>';

View File

@ -8,7 +8,7 @@
height:700px; height:700px;
position:fixed; position:fixed;
top:100px; top:100px;
z-index: 10000;
} }
.open-menu{ .open-menu{
@ -101,4 +101,8 @@ a:active, a:hover, a:focus {
outline: 0; outline: 0;
text-decoration: none; text-decoration: none;
outline: 0 !important; outline: 0 !important;
}
.select2-container {
z-index: 10000;
} }

View File

@ -23,10 +23,6 @@ include_once __DIR__.'/../../core.php';
<link rel="stylesheet" href="<?=$rootdir?>/modules/mappa/css/app.css"> <link rel="stylesheet" href="<?=$rootdir?>/modules/mappa/css/app.css">
<?php
if(!empty(setting('Google Maps API key'))){
?>
<!-- Mappa --> <!-- Mappa -->
<div id="mappa"></div> <div id="mappa"></div>
@ -48,7 +44,7 @@ if(!empty(setting('Google Maps API key'))){
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
{[ "type": "select", "name": "idanagrafica", "id": "idanagrafica", "required": 1, "ajax-source": "clienti_fornitori" ]} {[ "type": "select", "name": "idanagrafica", "id": "idanagrafica", "required": 1, "ajax-source": "clienti" ]}
</div> </div>
</div> </div>
@ -82,19 +78,21 @@ if(!empty(setting('Google Maps API key'))){
<script> <script>
var ROOTDIR = '<?=$rootdir?>'; var ROOTDIR = '<?=$rootdir?>';
function calcolaPercorso(indirizzo) { function caricaMappa() {
window.open("https://www.google.com/maps/dir/?api=1&destination=" + indirizzo); const lat = "41.706";
const lng = "13.228";
map = L.map("mappa", {
center: [lat, lng],
zoom: 6,
gestureHandling: true
});
L.tileLayer("<?php echo setting("Tile layer OpenStreetMap"); ?>", {
maxZoom: 17,
attribution: "© OpenStreetMap"
}).addTo(map);
} }
</script> </script>
<script type="text/javascript" src="<?=$rootdir?>/modules/mappa/js/app.js"></script> <script type="text/javascript" src="<?=$rootdir?>/modules/mappa/js/app.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?callback=initialize&key=<?=setting('Google Maps API key')?>&libraries=&v=weekly" async></script>
<?php
}else{
echo '
<div class="alert alert-info">
'.Modules::link('Impostazioni', null, tr('Per abilitare la visualizzazione della mappa, inserire la Google Maps API Key nella scheda Impostazioni'), true, null, true, null, '&search=Google Maps API key').'.
</div>';
}
?>

View File

@ -1,42 +1,27 @@
$(document).ready(function(){ $(document).ready(function() {
if(!$('body').hasClass('sidebar-collapse')){ if(!$('body').hasClass('sidebar-collapse')){
$('.sidebar-toggle').trigger('click'); $('.sidebar-toggle').trigger('click');
$('.nav').hide(); $('.nav').hide();
} }
reload_pointers(); setTimeout(function () {
caricaMappa();
reload_pointers();
}, 1000);
}); });
let map; let map;
var markers = []; var markers = [];
var icon = new L.Icon({
iconUrl: globals.rootdir + "/assets/dist/img/marker-icon.png",
shadowUrl:globals.rootdir + "/assets/dist/img/leaflet/marker-shadow.png",
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
function initialize(startLat, startLon) { $('#menu-filtri-toggle').click(function() {
if (startLat==undefined){
startLat = 43.45291889;
}
if (startLon==undefined){
startLon = 11.96411133;
}
var myLatlng = new google.maps.LatLng(startLat, startLon);
var mapOptions = {
zoom: 7,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false,
panControl: false,
scaleControl: false,
rotateControl: false
}
map = new google.maps.Map(document.getElementById('mappa'), mapOptions);
}
$('#menu-filtri-toggle').click(function(){
if($(this).parent().parent().parent().hasClass("open-menu")){ if($(this).parent().parent().parent().hasClass("open-menu")){
$(this).parent().parent().parent().removeClass("open-menu"); $(this).parent().parent().parent().removeClass("open-menu");
@ -57,75 +42,44 @@ $('#menu-filtri-toggle').click(function(){
} }
}); });
function reload_pointers(){ function reload_pointers() {
clearMarkers(); clearMarkers();
var check = []; var check = [];
$("input[type='checkbox']").each(function(){ $("input[type='checkbox']").each(function() {
if($(this).is(':checked')){ if($(this).is(':checked')){
id = $(this).attr('id'); id = $(this).attr('id');
check.push(id); check.push(id);
} }
}); });
$.get(ROOTDIR+'/modules/mappa/actions.php?op=get_markers&idanagrafica='+$('#idanagrafica').val()+'&check='+check, function(data){ $.get(ROOTDIR+'/modules/mappa/actions.php?op=get_markers&idanagrafica='+$('#idanagrafica').val()+'&check='+check, function(data){
var infowindow = new google.maps.InfoWindow();
var bounds = new google.maps.LatLngBounds ();
var dettagli = JSON.parse(data); var dettagli = JSON.parse(data);
var marker, i;
var counter = 0;
dettagli.forEach(function(dettaglio) { dettagli.forEach(function(dettaglio) {
const posizione = new google.maps.LatLng(dettaglio.lat, dettaglio.lng); if (dettaglio.lat && dettaglio.lng) {
L.marker([dettaglio.lat, dettaglio.lng], {
marker = new google.maps.Marker({ icon: icon
position: posizione, }).addTo(map);
map: map, }
});
markers.push(marker);
bounds.extend(posizione);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(dettaglio.descrizione);
infowindow.open(map, marker);
}
})(marker, i));
counter++;
}); });
});
}
if(counter>0){ function clearMarkers() {
map.setCenter(bounds.getCenter()); // this will set the center of map to center of all markers map.eachLayer(function (layer) {
map.fitBounds(bounds); // this will fit all the markers to screen if(layer instanceof L.Marker) {
map.removeLayer(layer);
} }
}); });
} }
function setMapOnAll(map) { $("input[type='checkbox']").change(function() {
for (let i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
function clearMarkers() {
setMapOnAll(null);
}
$("input[type='checkbox']").change(function(){
reload_pointers(); reload_pointers();
}); });
$('#idanagrafica').change(function(){ $('#idanagrafica').change(function() {
reload_pointers(); reload_pointers();
}); });

View File

@ -12,7 +12,7 @@
"bootstrap-daterangepicker": "^2.1.25", "bootstrap-daterangepicker": "^2.1.25",
"bootstrap-maxlength": "^1.10.1", "bootstrap-maxlength": "^1.10.1",
"chart.js": "^3.8.0", "chart.js": "^3.8.0",
"ckeditor4": "ckeditor/ckeditor4-releases#full/latest", "ckeditor4": "^4.21.0",
"components-jqueryui": "^1.12.1", "components-jqueryui": "^1.12.1",
"datatables.net-bs": "^1.10.15", "datatables.net-bs": "^1.10.15",
"datatables.net-buttons-bs": "^1.3.1", "datatables.net-buttons-bs": "^1.3.1",
@ -30,10 +30,12 @@
"jquery-form": "^4.2.1", "jquery-form": "^4.2.1",
"jquery-ui-touch-punch": "^0.2.3", "jquery-ui-touch-punch": "^0.2.3",
"jquery.shorten": "^1.0.0", "jquery.shorten": "^1.0.0",
"leaflet": "^1.9.4",
"leaflet-gesture-handling": "^1.2.2",
"moment": "^2.18.1", "moment": "^2.18.1",
"numeral": "^2.0.6", "numeral": "^2.0.6",
"parsleyjs": "^2.7.2", "parsleyjs": "^2.7.2",
"pdf.js": "alekswebnet/pdfjs-viewer-element", "pdfjs-viewer-element": "^2.3.1",
"pwstrength-bootstrap": "^3.0.4", "pwstrength-bootstrap": "^3.0.4",
"select2": "^4.0.3", "select2": "^4.0.3",
"select2-bootstrap-theme": "^0.1.0-beta.10", "select2-bootstrap-theme": "^0.1.0-beta.10",

View File

@ -108,10 +108,8 @@ echo '
<div class="col-md-12"> <div class="col-md-12">
{[ "type": "textarea", "label": "'.tr('Note').'", "name": "note", "value": "$note$" ]} {[ "type": "textarea", "label": "'.tr('Note').'", "name": "note", "value": "$note$" ]}
</div> </div>
</div>'; </div>
if (!empty($google)) {
echo '
<div class="row"> <div class="row">
<div class="col-md-6" id="geocomplete"> <div class="col-md-6" id="geocomplete">
{[ "type": "text", "label": "'.tr('Indirizzo Google').'", "name": "gaddress", "value": "$gaddress$", "extra": "data-geo=\'formatted_address\'" ]} {[ "type": "text", "label": "'.tr('Indirizzo Google').'", "name": "gaddress", "value": "$gaddress$", "extra": "data-geo=\'formatted_address\'" ]}
@ -125,31 +123,24 @@ if (!empty($google)) {
{[ "type": "text", "label": "'.tr('Longitudine').'", "name": "lng", "id": "lng_", "value": "$lng$", "extra": "data-geo=\'lng\'", "class": "text-right" ]} {[ "type": "text", "label": "'.tr('Longitudine').'", "name": "lng", "id": "lng_", "value": "$lng$", "extra": "data-geo=\'lng\'", "class": "text-right" ]}
</div>'; </div>';
// Vedi su google maps if (!empty($record['indirizzo']) || (empty($record['citta']))) {
if (!empty($record['indirizzo']) || (empty($record['citta']))) { echo '
echo ' <div class="btn-group col-md-2" >
<div class="btn-group col-md-2" > <label>&nbsp;</label><br>
<label>&nbsp;</label><br> <a class="btn btn-info" title="'.tr('Mostra la sede su Openstreetmap').'" onclick="window.open(\'https://maps.google.com/maps/search/\'+encodeURI( $(\'#indirizzo_\').val() )+\', \'+encodeURI( $(\'#citta_\').val() ) );">&nbsp;<i class="fa fa-map-marker">&nbsp;</i></a>
<a class="btn btn-info" title="'.tr('Mostra la sede su Google Maps').'" onclick="window.open(\'https://maps.google.com/maps/search/\'+encodeURI( $(\'#indirizzo_\').val() )+\', \'+encodeURI( $(\'#citta_\').val() ) );">&nbsp;<i class="fa fa-map-marker">&nbsp;</i></a> ';
';
echo ' echo '
<a title="'.tr('Calcola percoso da sede legale a questa sede').'" class="btn btn-primary btn-secondary" onclick="window.open(\'https://maps.google.com/maps/dir/\'+encodeURI( $(\'#indirizzo_\').val() )+\', \'+encodeURI( $(\'#citta_\').val() )+\'/\'+encodeURI( $(\'#indirizzo\').val() )+\',\'+encodeURI( $(\'#citta\').val() )+\',8z\');"><i class="fa fa-car"></i></a> <a title="'.tr('Calcola percoso da sede legale a questa sede').'" class="btn btn-primary btn-secondary" onclick="window.open(\'https://maps.google.com/maps/dir/\'+encodeURI( $(\'#indirizzo_\').val() )+\', \'+encodeURI( $(\'#citta_\').val() )+\'/\'+encodeURI( $(\'#indirizzo\').val() )+\',\'+encodeURI( $(\'#citta\').val() )+\',8z\');"><i class="fa fa-car"></i></a>
</div>'; </div>';
} }
echo ' echo '
</div>'; </div>';
if (!empty($record['gaddress']) || (!empty($record['lat']) && !empty($record['lng']))) { if (!empty($record['gaddress']) || (!empty($record['lat']) && !empty($record['lng']))) {
echo ' echo '
<div id="map" style="height:400px; width:100%"></div><br>'; <div id="map" style="height:400px; width:100%"></div><br>';
}
} else {
echo '
<div class="alert alert-info">
'.Modules::link('Impostazioni', null, tr('Per abilitare la visualizzazione delle anagrafiche nella mappa, inserire la Google Maps API Key nella scheda Impostazioni'), true, null, true, null, '&search=Google Maps API key').'.
</div>';
} }
// Permetto eliminazione tipo sede solo se non è utilizzata da nessun'altra parte nel gestionale // Permetto eliminazione tipo sede solo se non è utilizzata da nessun'altra parte nel gestionale

View File

@ -11,3 +11,8 @@ UPDATE `zz_settings` SET `help` = "Se abilitato viene effettuato un backup compl
UPDATE `zz_settings` SET `editable` = 1 WHERE `zz_settings`.`nome` = 'Soft quota'; UPDATE `zz_settings` SET `editable` = 1 WHERE `zz_settings`.`nome` = 'Soft quota';
UPDATE `zz_settings` SET `help` = "Valore espresso in Giga superato il quale viene visualizzato un avviso di spazio in esaurimento." WHERE `zz_settings`.`nome` = 'Soft quota'; UPDATE `zz_settings` SET `help` = "Valore espresso in Giga superato il quale viene visualizzato un avviso di spazio in esaurimento." WHERE `zz_settings`.`nome` = 'Soft quota';
-- Rimozione google maps
DELETE FROM `zz_settings` WHERE `zz_settings`.`nome` = 'Google Maps API key';
INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `created_at`, `order`, `help`) VALUES (NULL, 'Tile layer OpenStreetMap', 'https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png', 'string', '1', 'Generali', NULL, NULL, '')