78 lines
2.1 KiB
JavaScript
78 lines
2.1 KiB
JavaScript
window.getPolygonColor = function (status) {
|
|
if (status === "SHM") {
|
|
return "#ff8c00";
|
|
}
|
|
|
|
if (status === "HGB") {
|
|
return "#6f42c1";
|
|
}
|
|
|
|
if (status === "HGU") {
|
|
return "#20c997";
|
|
}
|
|
|
|
return "#6c757d";
|
|
};
|
|
|
|
window.normalizePolygonStatus = function (value) {
|
|
var normalized = String(value || "").trim().toUpperCase();
|
|
var allowed = ["SHM", "HGB", "HGU", "HP"];
|
|
|
|
if (allowed.indexOf(normalized) === -1) {
|
|
return "";
|
|
}
|
|
|
|
return normalized;
|
|
};
|
|
|
|
window.collectPolygonData = async function () {
|
|
return window.openEditModal({
|
|
title: "Tambah Kavling",
|
|
subtitle: "Lengkapi atribut kavling untuk polygon yang sudah digambar.",
|
|
fields: [
|
|
{ name: "nama", label: "Nama Kavling", value: "", required: true },
|
|
{
|
|
name: "status",
|
|
label: "Status Kavling",
|
|
type: "select",
|
|
value: "SHM",
|
|
options: [
|
|
{ value: "SHM", label: "SHM" },
|
|
{ value: "HGB", label: "HGB" },
|
|
{ value: "HGU", label: "HGU" },
|
|
{ value: "HP", label: "HP" }
|
|
]
|
|
}
|
|
],
|
|
validate: function (data) {
|
|
if (!data.nama || !window.normalizePolygonStatus(data.status)) {
|
|
return "Nama dan status kavling wajib valid.";
|
|
}
|
|
return "";
|
|
}
|
|
});
|
|
};
|
|
|
|
window.buildPolygonLayer = function (kavling) {
|
|
var coordinates = window.parseGeometry(kavling.geom).map(function (point) {
|
|
return L.latLng(point[0], point[1]);
|
|
});
|
|
|
|
if (coordinates.length < 3) {
|
|
return null;
|
|
}
|
|
|
|
var color = window.getPolygonColor(kavling.status);
|
|
|
|
return L.polygon(coordinates, {
|
|
color: color,
|
|
fillColor: color,
|
|
fillOpacity: 0.35,
|
|
weight: 3
|
|
}).bindPopup(
|
|
"<b>" + window.escapeHtml(kavling.nama) + "</b><br>" +
|
|
"Status: " + window.escapeHtml(kavling.status) + "<br>" +
|
|
"Luas: " + window.formatSquareMeters(kavling.luas)
|
|
);
|
|
};
|