|
|
@ -5,36 +5,29 @@ let long = 106.559242; |
|
|
|
let zoom = 10; |
|
|
|
let zoom = 10; |
|
|
|
let currentIdAct = 0; |
|
|
|
let currentIdAct = 0; |
|
|
|
let map = L.map('map_activity').setView([lat, long], zoom); |
|
|
|
let map = L.map('map_activity').setView([lat, long], zoom); |
|
|
|
|
|
|
|
let drawnItems = new L.FeatureGroup().addTo(map); |
|
|
|
let inter = 5; |
|
|
|
let inter = 5; |
|
|
|
|
|
|
|
|
|
|
|
let circLat = "", |
|
|
|
let circLat = "", |
|
|
|
circLong = ""; |
|
|
|
circLong = ""; |
|
|
|
|
|
|
|
|
|
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { |
|
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { |
|
|
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' |
|
|
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' |
|
|
|
}).addTo(map); |
|
|
|
}).addTo(map); |
|
|
|
|
|
|
|
|
|
|
|
let drawnItem = L.featureGroup().addTo(map); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var drawControl = new L.Control.Draw({ |
|
|
|
var drawControl = new L.Control.Draw({ |
|
|
|
draw: { |
|
|
|
draw: { |
|
|
|
circlemarker: false, |
|
|
|
circlemarker: false, |
|
|
|
circle:false, |
|
|
|
circle: false, |
|
|
|
polyline: false |
|
|
|
polyline: false |
|
|
|
}, |
|
|
|
}, |
|
|
|
edit:{ |
|
|
|
|
|
|
|
featureGroup:drawnItem, |
|
|
|
|
|
|
|
edit:false, |
|
|
|
|
|
|
|
delete:false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var drawnControlEdit = new L.Control.Draw({ |
|
|
|
var drawnControlEdit = new L.Control.Draw({ |
|
|
|
draw: false, |
|
|
|
draw: false, |
|
|
|
edit:{ |
|
|
|
edit: { |
|
|
|
featureGroup:drawnItem, |
|
|
|
featureGroup: drawnItems, |
|
|
|
delete:true |
|
|
|
delete: true |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -42,39 +35,72 @@ map.addControl(drawControl); |
|
|
|
|
|
|
|
|
|
|
|
// add searching location (nominatim) on map
|
|
|
|
// add searching location (nominatim) on map
|
|
|
|
L.Control.geocoder().addTo(map); |
|
|
|
L.Control.geocoder().addTo(map); |
|
|
|
|
|
|
|
function addDrawnLayer(layer) { |
|
|
|
|
|
|
|
drawnItems.addLayer(layer); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function openActivityMap(id) |
|
|
|
function updateCurrentGeoJson() { |
|
|
|
{ |
|
|
|
let shapes = []; |
|
|
|
|
|
|
|
drawnItems.eachLayer(function (layer) { |
|
|
|
|
|
|
|
let geojson = layer.toGeoJSON(); |
|
|
|
|
|
|
|
if (layer instanceof L.Circle) { |
|
|
|
|
|
|
|
geojson.properties.radius = layer.getRadius(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
shapes.push(geojson); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
currentGeoJson = { |
|
|
|
|
|
|
|
type: 'FeatureCollection', |
|
|
|
|
|
|
|
features: shapes |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function openActivityMap(id) { |
|
|
|
currentIdAct = id; |
|
|
|
currentIdAct = id; |
|
|
|
map.invalidateSize(); |
|
|
|
map.invalidateSize(); |
|
|
|
$.ajax({ |
|
|
|
$.ajax({ |
|
|
|
url: `${base_url}task/edit/${id}`, |
|
|
|
url: `${base_url}task/edit/${id}`, |
|
|
|
type:"get", |
|
|
|
type: "get", |
|
|
|
success: function (data) { |
|
|
|
success: function (data) { |
|
|
|
let dataRes = data.data |
|
|
|
let dataRes = data.data |
|
|
|
// console.log("cek data", data);
|
|
|
|
// console.log("cek data", data);
|
|
|
|
drawnItem.clearLayers(); |
|
|
|
drawnItems.clearLayers(); |
|
|
|
if(dataRes.geom){ |
|
|
|
if (dataRes.geom) { |
|
|
|
let datageojson = JSON.parse(dataRes.geom); |
|
|
|
let datageojson = JSON.parse(dataRes.geom); |
|
|
|
currentGeoJson = datageojson |
|
|
|
currentGeoJson = datageojson |
|
|
|
// console.log("cek data geojson", datageojson);
|
|
|
|
// console.log("cek data geojson", datageojson);
|
|
|
|
if(datageojson.properties.radius){ |
|
|
|
if (datageojson.type === 'FeatureCollection') { |
|
|
|
|
|
|
|
datageojson.features.forEach(feature => { |
|
|
|
|
|
|
|
let lGeoJson = L.geoJSON(feature); |
|
|
|
|
|
|
|
let layers = lGeoJson.getLayers(); |
|
|
|
|
|
|
|
layers.forEach(layer => { |
|
|
|
|
|
|
|
let radius = layer.feature.properties.radius; |
|
|
|
|
|
|
|
if (radius) { |
|
|
|
|
|
|
|
let latlon = layer.getLatLng(); |
|
|
|
|
|
|
|
let circle = L.circle([latlon.lat, latlon.lng], { radius: radius }); |
|
|
|
|
|
|
|
addDrawnLayer(circle); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
addDrawnLayer(layer) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (datageojson.properties.radius) { |
|
|
|
let radius = datageojson.properties.radius |
|
|
|
let radius = datageojson.properties.radius |
|
|
|
let lGeoJson = L.geoJson(datageojson); |
|
|
|
let lGeoJson = L.geoJson(datageojson); |
|
|
|
let layers = lGeoJson.getLayers(); |
|
|
|
let layers = lGeoJson.getLayers(); |
|
|
|
let latlon = layers[0].getLatLng(); |
|
|
|
let latlon = layers[0].getLatLng(); |
|
|
|
let newCircle = L.circle([latlon.lat,latlon.lng], {radius: radius}); |
|
|
|
let newCircle = L.circle([latlon.lat, latlon.lng], { radius: radius }); |
|
|
|
drawnItem.addLayer(newCircle); |
|
|
|
addDrawnLayer(newCircle) |
|
|
|
// console.log("cek layers", layers[0]);
|
|
|
|
// console.log("cek layers", layers[0]);
|
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
let lGeoJson = L.geoJson(datageojson); |
|
|
|
let lGeoJson = L.geoJson(datageojson); |
|
|
|
let layers = lGeoJson.getLayers(); |
|
|
|
let layers = lGeoJson.getLayers(); |
|
|
|
drawnItem.addLayer(layers[0]); |
|
|
|
addDrawnLayer(layers[0]) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
actionLocationAc = "edit"; |
|
|
|
actionLocationAc = "edit"; |
|
|
|
drawControl.remove(); |
|
|
|
|
|
|
|
map.addControl(drawnControlEdit); |
|
|
|
map.addControl(drawnControlEdit); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
currentGeoJson = ""; |
|
|
|
currentGeoJson = ""; |
|
|
|
actionLocationAc = "add"; |
|
|
|
actionLocationAc = "add"; |
|
|
|
drawnControlEdit.remove(); |
|
|
|
drawnControlEdit.remove(); |
|
|
@ -89,7 +115,7 @@ function openActivityMap(id) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$('#modal_activity_location').on('hide.bs.modal', function (event) { |
|
|
|
$('#modal_activity_location').on('hide.bs.modal', function (event) { |
|
|
|
currentGeoJson ="" |
|
|
|
currentGeoJson = "" |
|
|
|
currentIdAct = 0; |
|
|
|
currentIdAct = 0; |
|
|
|
actionLocationAc = "add"; |
|
|
|
actionLocationAc = "add"; |
|
|
|
drawnControlEdit.remove(); |
|
|
|
drawnControlEdit.remove(); |
|
|
@ -100,7 +126,7 @@ $('#modal_activity_location').on('hide.bs.modal', function (event) { |
|
|
|
// map initialization
|
|
|
|
// map initialization
|
|
|
|
$(document).ready(function () { |
|
|
|
$(document).ready(function () { |
|
|
|
let intervalMap = setInterval(function () { |
|
|
|
let intervalMap = setInterval(function () { |
|
|
|
if(inter=0){ |
|
|
|
if (inter = 0) { |
|
|
|
clearInterval(intervalMap) |
|
|
|
clearInterval(intervalMap) |
|
|
|
} |
|
|
|
} |
|
|
|
map.invalidateSize(); |
|
|
|
map.invalidateSize(); |
|
|
@ -127,22 +153,22 @@ $(document).ready(function () { |
|
|
|
// console.log("cek layer", layer.toGeoJSON());
|
|
|
|
// console.log("cek layer", layer.toGeoJSON());
|
|
|
|
// layer.bindTooltip("cek");
|
|
|
|
// layer.bindTooltip("cek");
|
|
|
|
// Do whatever else you need to. (save to db; add to map etc)
|
|
|
|
// Do whatever else you need to. (save to db; add to map etc)
|
|
|
|
drawnItem.addLayer(layer); |
|
|
|
addDrawnLayer(layer); |
|
|
|
drawControl.remove(); |
|
|
|
updateCurrentGeoJson(); |
|
|
|
map.addControl(drawnControlEdit); |
|
|
|
map.addControl(drawnControlEdit); |
|
|
|
// map.addLayer(layer);
|
|
|
|
// map.addLayer(layer);
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
map.on(L.Draw.Event.DELETED, function (e) { |
|
|
|
map.on(L.Draw.Event.DELETED, function (e) { |
|
|
|
var type = e.layerType, |
|
|
|
var type = e.layerType; |
|
|
|
layer = e.layer; |
|
|
|
let layers = e.layers.getLayers(); |
|
|
|
|
|
|
|
layers.forEach(layer => { |
|
|
|
|
|
|
|
drawnItems.removeLayer(layer); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
updateCurrentGeoJson() |
|
|
|
// console.log("cek layer", layer.toGeoJSON());
|
|
|
|
// console.log("cek layer", layer.toGeoJSON());
|
|
|
|
// Do whatever else you need to. (save to db; add to map etc)
|
|
|
|
// Do whatever else you need to. (save to db; add to map etc)
|
|
|
|
currentGeoJson = ""; |
|
|
|
|
|
|
|
drawnItem.removeLayer(layer); |
|
|
|
|
|
|
|
drawnControlEdit.remove(); |
|
|
|
|
|
|
|
map.addControl(drawControl); |
|
|
|
|
|
|
|
// map.addLayer(layer);
|
|
|
|
// map.addLayer(layer);
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -150,51 +176,82 @@ $(document).ready(function () { |
|
|
|
// var type = e.layerType,
|
|
|
|
// var type = e.layerType,
|
|
|
|
// layer = e.layer;
|
|
|
|
// layer = e.layer;
|
|
|
|
let layers = e.layers.getLayers(); |
|
|
|
let layers = e.layers.getLayers(); |
|
|
|
let layer = layers[0] |
|
|
|
layers.forEach(layer => { |
|
|
|
let geoJson = layers[0].toGeoJSON(); |
|
|
|
let geoJson = layer.toGeoJSON(); |
|
|
|
if(layer instanceof L.Circle){ |
|
|
|
if (layer instanceof L.Circle) { |
|
|
|
geoJson.properties.radius = layer.getRadius(); |
|
|
|
geoJson.properties.radius = layer.getRadius(); |
|
|
|
currentGeoJson = geoJson |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
currentGeoJson = geoJson |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
updateCurrentGeoJson(); |
|
|
|
|
|
|
|
}); |
|
|
|
// console.log("cek layer", layers[0].toGeoJSON());
|
|
|
|
// console.log("cek layer", layers[0].toGeoJSON());
|
|
|
|
// console.log("cek layer", layer.toGeoJSON());
|
|
|
|
// console.log("cek layer", layer.toGeoJSON());
|
|
|
|
// Do whatever else you need to. (save to db; add to map etc)
|
|
|
|
// Do whatever else you need to. (save to db; add to map etc)
|
|
|
|
// drawnItem.removeLayer(layer);
|
|
|
|
|
|
|
|
// drawnControlEdit.remove();
|
|
|
|
// drawnControlEdit.remove();
|
|
|
|
// map.addControl(drawControl);
|
|
|
|
// map.addControl(drawControl);
|
|
|
|
// map.addLayer(layer);
|
|
|
|
// map.addLayer(layer);
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$("#modal_activity_location").on("click", "#btn_save_location", function() { |
|
|
|
$("#modal_activity_location").on("click", "#btn_save_location", function () { |
|
|
|
if(currentGeoJson==""){ |
|
|
|
if (currentGeoJson == "") { |
|
|
|
gantt.confirm({ |
|
|
|
gantt.confirm({ |
|
|
|
text: "Lokasi belum ditentukan!, lanjutkan?", |
|
|
|
text: "Lokasi belum ditentukan!, lanjutkan?", |
|
|
|
ok:"Submit",
|
|
|
|
ok: "Submit", |
|
|
|
cancel:"Cancel", |
|
|
|
cancel: "Cancel", |
|
|
|
callback: function(result){ |
|
|
|
callback: function (result) { |
|
|
|
if(!result){ |
|
|
|
if (!result) { |
|
|
|
return false |
|
|
|
return false |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
submitLocation(); |
|
|
|
submitShapes(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
submitLocation() |
|
|
|
submitShapes(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function submitShapes() { |
|
|
|
|
|
|
|
let payload |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentGeoJson && currentGeoJson != "") { |
|
|
|
|
|
|
|
payload = { |
|
|
|
|
|
|
|
geom: JSON.stringify(currentGeoJson), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
payload = { |
|
|
|
|
|
|
|
geom: null, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
|
|
|
|
data: JSON.stringify(payload), |
|
|
|
|
|
|
|
url: `${base_url}task/update-regular/${currentIdAct}`, |
|
|
|
|
|
|
|
type: "PUT", |
|
|
|
|
|
|
|
processData: false, |
|
|
|
|
|
|
|
contentType: false, |
|
|
|
|
|
|
|
success: function (data) { |
|
|
|
|
|
|
|
$("#modal_activity_location").modal("hide"); |
|
|
|
|
|
|
|
currentGeoJson = "" |
|
|
|
|
|
|
|
currentIdAct = 0; |
|
|
|
|
|
|
|
gantt.alert("Activity Location successfully updated!"); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
error: function (data) { |
|
|
|
|
|
|
|
$("#modal_activity_location").modal("hide"); |
|
|
|
|
|
|
|
currentGeoJson = "" |
|
|
|
|
|
|
|
currentIdAct = 0; |
|
|
|
|
|
|
|
gantt.alert("Activity Location failed updated!, try again later!"); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function submitLocation() |
|
|
|
function submitLocation() { |
|
|
|
{ |
|
|
|
|
|
|
|
let payload |
|
|
|
let payload |
|
|
|
|
|
|
|
|
|
|
|
if(currentGeoJson && currentGeoJson!=""){ |
|
|
|
if (currentGeoJson && currentGeoJson != "") { |
|
|
|
payload = { |
|
|
|
payload = { |
|
|
|
geom: JSON.stringify(currentGeoJson), |
|
|
|
geom: JSON.stringify(currentGeoJson), |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
payload = { |
|
|
|
payload = { |
|
|
|
geom: null, |
|
|
|
geom: null, |
|
|
|
} |
|
|
|
} |
|
|
@ -208,38 +265,36 @@ $(document).ready(function () { |
|
|
|
contentType: false, |
|
|
|
contentType: false, |
|
|
|
success: function (data) { |
|
|
|
success: function (data) { |
|
|
|
$("#modal_activity_location").modal("hide"); |
|
|
|
$("#modal_activity_location").modal("hide"); |
|
|
|
currentGeoJson ="" |
|
|
|
currentGeoJson = "" |
|
|
|
currentIdAct = 0; |
|
|
|
currentIdAct = 0; |
|
|
|
gantt.alert("Activity Location successfully updated!"); |
|
|
|
gantt.alert("Activity Location successfully updated!"); |
|
|
|
}, |
|
|
|
}, |
|
|
|
error: function (data) { |
|
|
|
error: function (data) { |
|
|
|
$("#modal_activity_location").modal("hide"); |
|
|
|
$("#modal_activity_location").modal("hide"); |
|
|
|
currentGeoJson ="" |
|
|
|
currentGeoJson = "" |
|
|
|
currentIdAct = 0; |
|
|
|
currentIdAct = 0; |
|
|
|
gantt.alert("Activity Location failed updated!, try again later!"); |
|
|
|
gantt.alert("Activity Location failed updated!, try again later!"); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$("#modal_radius").on("click", "#btn_save_radius", function() { |
|
|
|
$("#modal_radius").on("click", "#btn_save_radius", function () { |
|
|
|
let radius = $("#buffer_radius").val(); |
|
|
|
let radius = $("#buffer_radius").val(); |
|
|
|
if(radius <= 0){ |
|
|
|
if (radius <= 0) { |
|
|
|
gantt.alert("radius buffer tidak boleh kurang dari atau sama dengan 0!!"); |
|
|
|
gantt.alert("radius buffer tidak boleh kurang dari atau sama dengan 0!!"); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
submitCircle(radius); |
|
|
|
submitCircle(radius); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
function submitCircle(radius) |
|
|
|
function submitCircle(radius) { |
|
|
|
{ |
|
|
|
let circle = L.circle([circLat, circLong], { radius: radius }); |
|
|
|
let circle = L.circle([circLat,circLong], {radius: radius}); |
|
|
|
|
|
|
|
let geojsoncircle = circle.toGeoJSON(); |
|
|
|
let geojsoncircle = circle.toGeoJSON(); |
|
|
|
geojsoncircle.properties.radius = radius |
|
|
|
geojsoncircle.properties.radius = radius |
|
|
|
currentGeoJson = geojsoncircle |
|
|
|
currentGeoJson = geojsoncircle |
|
|
|
// console.log("geojsoncircle", geojsoncircle);
|
|
|
|
addDrawnLayer(circle); |
|
|
|
drawnItem.addLayer(circle); |
|
|
|
updateCurrentGeoJson(); |
|
|
|
drawControl.remove(); |
|
|
|
|
|
|
|
map.addControl(drawnControlEdit); |
|
|
|
map.addControl(drawnControlEdit); |
|
|
|
|
|
|
|
|
|
|
|
$("#modal_radius").modal('hide'); |
|
|
|
$("#modal_radius").modal('hide'); |
|
|
|