Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
199 righe
6.2 KiB
199 righe
6.2 KiB
2 anni fa
|
function _displayMapDelete (divtarget) {
|
||
|
divtarget = typeof divtarget !== 'undefined' ? divtarget : 'app';
|
||
|
document.getElementById(divtarget).innerHTML = "<div id='map' class='map-wrapper'></div>";
|
||
|
document.getElementById('home').className = "nav-link flat";
|
||
|
document.getElementById('leaflet_crud_create').className = "nav-link flat";
|
||
|
document.getElementById('leaflet_crud_read').className = "nav-link flat";
|
||
|
document.getElementById('navbarDropdownUpdate').className = "nav-link dropdown-toggle";
|
||
|
document.getElementById('leaflet_crud_delete').className = "nav-link flat active";
|
||
|
|
||
|
var map, isCollapsed, openStreetMaps;
|
||
|
|
||
|
if (document.body.clientWidth <= 767) {
|
||
|
isCollapsed = true;
|
||
|
} else {
|
||
|
isCollapsed = false;
|
||
|
}
|
||
|
|
||
|
var promisePoint = $.ajax({ url: "assets/dataservice/read_point.php",
|
||
|
method: "GET",
|
||
|
dataType: "json",
|
||
|
data: {command:"POINT"},
|
||
|
username: null,
|
||
|
password: null
|
||
|
});
|
||
|
|
||
|
var pointObjects = L.geoJson(null, {
|
||
|
onEachFeature: function (feature, layer) {
|
||
|
if (feature.properties) {
|
||
|
layer.on({
|
||
|
click: function (e) {
|
||
|
var featureGid = feature.properties.id;
|
||
|
var deleteConfirmation = confirm("Vuoi cancellare questa geometria?");
|
||
|
if (deleteConfirmation == true) {
|
||
|
$.ajax({ url: "assets/dataservice/delete_point.php",
|
||
|
method: "GET",
|
||
|
dataType: "json",
|
||
|
data: {command:"DELETE",id:featureGid},
|
||
|
success: function (data) {
|
||
|
if (data.response=="200") {
|
||
|
map.off();
|
||
|
map.remove();
|
||
|
_displayMapDelete('app');
|
||
|
} else {
|
||
|
console.log('Failed to delete.');
|
||
|
}
|
||
|
},
|
||
|
username: null,
|
||
|
password: null
|
||
|
});
|
||
|
} else {
|
||
|
console.log('Delete feature is cancelled.');
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
promisePoint.then(function (data) {
|
||
|
pointObjects.addData(data);
|
||
|
map.addLayer(pointObjects);
|
||
|
});
|
||
|
|
||
|
var promiseLinestring = $.ajax({ url: "assets/dataservice/read_linestring.php",
|
||
|
method: "GET",
|
||
|
dataType: "json",
|
||
|
data: {command:"LINESTRING"},
|
||
|
username: null,
|
||
|
password: null
|
||
|
});
|
||
|
|
||
|
var linestringObjects = L.geoJson(null, {
|
||
|
onEachFeature: function (feature, layer) {
|
||
|
if (feature.properties) {
|
||
|
layer.on({
|
||
|
click: function (e) {
|
||
|
var featureGid = feature.properties.id;
|
||
|
var deleteConfirmation = confirm("Vuoi cancellare questa geometria?");
|
||
|
if (deleteConfirmation == true) {
|
||
|
$.ajax({ url: "assets/dataservice/delete_linestring.php",
|
||
|
method: "GET",
|
||
|
dataType: "json",
|
||
|
data: {command:"DELETE",id:featureGid},
|
||
|
success: function (data) {
|
||
|
if (data.response=="200") {
|
||
|
map.off();
|
||
|
map.remove();
|
||
|
_displayMapDelete('app');
|
||
|
} else {
|
||
|
console.log('Failed to delete.');
|
||
|
}
|
||
|
},
|
||
|
username: null,
|
||
|
password: null
|
||
|
});
|
||
|
} else {
|
||
|
console.log('Delete feature is cancelled.');
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
promiseLinestring.then(function (data) {
|
||
|
linestringObjects.addData(data);
|
||
|
map.addLayer(linestringObjects);
|
||
|
});
|
||
|
|
||
|
var promisePolygon = $.ajax({ url: "assets/dataservice/read_polygon.php",
|
||
|
method: "GET",
|
||
|
dataType: "json",
|
||
|
data: {command:"POLYGON"},
|
||
|
username: null,
|
||
|
password: null
|
||
|
});
|
||
|
|
||
|
var polygonObjects = L.geoJson(null, {
|
||
|
onEachFeature: function (feature, layer) {
|
||
|
if (feature.properties) {
|
||
|
layer.on({
|
||
|
click: function (e) {
|
||
|
var featureGid = feature.properties.id;
|
||
|
var deleteConfirmation = confirm("Vuoi cancellare questa geometria?");
|
||
|
if (deleteConfirmation == true) {
|
||
|
$.ajax({ url: "assets/dataservice/delete_polygon.php",
|
||
|
method: "GET",
|
||
|
dataType: "json",
|
||
|
data: {command:"DELETE",id:featureGid},
|
||
|
success: function (data) {
|
||
|
if (data.response=="200") {
|
||
|
map.off();
|
||
|
map.remove();
|
||
|
_displayMapDelete('app');
|
||
|
} else {
|
||
|
console.log('Failed to delete.');
|
||
|
}
|
||
|
},
|
||
|
username: null,
|
||
|
password: null
|
||
|
});
|
||
|
} else {
|
||
|
console.log('Delete feature is cancelled.');
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
promisePolygon.then(function (data) {
|
||
|
polygonObjects.addData(data);
|
||
|
map.addLayer(polygonObjects);
|
||
|
});
|
||
|
|
||
|
|
||
|
//################# INIZIO PARTICELLA SELEZIONATA #################
|
||
|
<?php if ( strlen($_SESSION['SELECT_PARTICELLA']) > 100 ) { ?>
|
||
|
particella = L.geoJson(<?php echo $_SESSION['SELECT_PARTICELLA'];?>, {
|
||
|
style: {'color': "#ff0000",'fillColor': "rgb(255, 255, 0)",'fillOpacity': 0.4,'dashArray': 4,'weight': 3,'opacity': 0.9}
|
||
|
}),
|
||
|
<?php } ?>
|
||
|
//################# FINE PARTICELLA SELEZIONATA #################
|
||
|
|
||
|
openStreetMaps = new L.TileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
||
|
minZoom: 3,
|
||
|
maxZoom: 20,
|
||
|
attribution: 'Map Data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors.'
|
||
|
});
|
||
|
|
||
|
map = L.map("map", {
|
||
|
zoom: <?php echo $_SESSION['ZOOM'];?>,
|
||
|
center: [<?php echo $_SESSION['CENTER'];?>],
|
||
|
layers: [openStreetMaps,particella],
|
||
|
minZoom: 3,
|
||
|
maxZoom: 20,
|
||
|
zoomControl: false,
|
||
|
attributionControl: true
|
||
|
});
|
||
|
|
||
|
map.setMaxBounds([<?php echo $_SESSION['BOUND']; ?>]);
|
||
|
|
||
|
var zoomControl = L.control.zoom({
|
||
|
position: "topleft"
|
||
|
}).addTo(map);
|
||
|
|
||
|
var baseLayers = {
|
||
|
"OpenStreetMap": openStreetMaps
|
||
|
};
|
||
|
|
||
|
var overlayLayers = {
|
||
|
"Elementi puntuali": pointObjects,
|
||
|
"Elementi lineari": linestringObjects,
|
||
|
"Elementi poligonali": polygonObjects
|
||
|
};
|
||
|
|
||
|
var layerControl = L.control.layers(baseLayers, overlayLayers, {
|
||
|
collapsed: isCollapsed
|
||
|
}).addTo(map);
|
||
|
|
||
|
}
|