const API_ENDPOINT = "https://141.ir/api";
const MAP_ENDPOINT = "https://testmap.141.ir";
const MAP_MIN_ZOOM = 6;
const MAP_MAX_ZOOM = 15;
const API_TEST = "http://192.168.1.75/rms_new/public/index.php";
var globalqueryparam = "";
var frommDate, toDate;
var mapradar = null;
var marker141Layers = null;
var marker141List = [];
var marker141Layers = null;
var globalcolor = "";
var routeControls = [];
var routecolor = [];
var routeControlsPath = [];
var isSetEndAbrarMarker = false;
var isSetStartAbrarMarker = false;
var marker141LayersWithoutCluster = null;
var frommDate, tooDate;
//pooria
var provincesArray;
var citiesArray;
var iranGeoJSON;
var iranMapGeo;
var iranArrayCount = 0;
var iranCityCount = 0;
var keepMapFeatureColor = null;
var fullCityGeoJSONTemp = new Object();
var fullCityGeoJSON = null;
var iranCityMapGeo;
var flagProvince = 0;
var flagCity = 0;
var HopeData;
var statusSet;
//End pooria
// testing
var routeControls = [];
var routecolor = [];
var routeControlsPath = [];
//testing
// map marker
var startAbrarDivIconrahdar = L.divIcon({
html: `
`,
iconSize: [55, 75],
iconAnchor: [33, 64],
});
var endAbrarDivIconrahdar = L.divIcon({
html: `
`,
iconSize: [55, 75],
iconAnchor: [33, 64],
});
//route need code
function drawStartToEndPath(pathType, source, dest, pathColor) {
if (routeControlsPath.length) {
$(routeControlsPath).each(function (index, control) {
map.removeControl(control);
routeControlsPath.splice(routeControlsPath.indexOf(index), 1);
});
}
if (polylinePath != null) {
map.removeLayer(polylinePath);
}
switch (pathType) {
case "line": {
polylinePath = L.polyline(
[
[source[0], source[1]],
[dest[0], dest[1]],
],
{
color: pathColor,
opacity: 0.8,
weight: 3,
}
).addTo(map);
break;
}
case "axis": {
$.get(
`https://testmap.141.ir/route/v1/driving/${source[1]},${source[0]};${dest[1]},${dest[0]}?overview=full&alternatives=false`,
function (data) {
alert("ppp");
routeControlsPath.push(
L.Routing.control({
waypoints: [
L.latLng(parseFloat(source[0]), parseFloat(source[1])),
L.latLng(parseFloat(dest[0]), parseFloat(dest[1])),
],
fitSelectedRoutes: false,
draggableWaypoints: true,
createMarker: function () {
return null;
},
lineOptions: {
addWaypoints: false,
styles: [
{
color: pathColor,
opacity: 0.8,
weight: 3,
},
],
},
})
.on("routesfound", function (e) {
for (let index = 0; index < popupArraysPath.length; index++) {
if (popupArraysPath[index] !== null) {
map.removeLayer(popupArraysPath[index]);
}
}
/*let popup = new L.Popup({
'maxWidth': '300',
'maxHeight': '150',
'className': 'customRouteEstimate'
});
let popupLocation = new L.LatLng(e.routes[0].coordinates[parseInt(e.routes[0]
.coordinates
.length /
2)].lat,
e.routes[0].coordinates[parseInt(e.routes[0].coordinates.length / 2)]
.lng);
let popupContent = "مسافت : " + parseFloat(e.routes[0].summary.totalDistance / 1000.0).toFixed(2) + " کیلومتر";
popup.setLatLng(popupLocation);
popup.setContent(popupContent);
popupArraysPath.push(popup);
map.addLayer(popup);*/
})
.addTo(map)
);
}
);
$(".leaflet-control-container").css("display", "none");
$(".leaflet-routing-container-hide").css("display", "none");
break;
}
}
}
function calculateRouteCoridor(first, last, num) {
let routeArray = [];
// if (routeControls.length) {
// // alert("hi")
// $(routeControls).each(function (index, control) {
// map.removeControl(control);
// routeControls.splice(routeControls.indexOf(index), 1);
// });
// }
let result = new Promise(function (resolve, reject) {
console.log("nummmmm", num);
if (num == 0) {
$.get(
"https://testmap.141.ir/route/v1/driving/51.4013785,35.7006177;52.8579311,36.4636399?overview=full&alternatives=true&steps=true&hints=C9UogA3VKIAAAAAARQAAAAAAAAAAAAAAAAAAADdAN0IAAAAAAAAAAAAAAABFAAAAAAAAAAAAAAC_AQAAIlIQA7-_IAKjUhADir8gAgAAbwARLKj6",
function (data) {
// console.log(data.routes[0].geometry)
// console.log("decoooooooode",decode(data.routes[0].geometry, 6));
resolve(decode(data.routes[0].geometry, 6));
}
);
}
if (num == 1) {
$.get(
"https://testmap.141.ir/route/v1/driving/51.4013785,35.7006177;52.3499009,36.4718947?overview=full&alternatives=true&steps=true&hints=C9UogA3VKIAAAAAARQAAAAAAAAAAAAAAAAAAADdAN0IAAAAAAAAAAAAAAABFAAAAAAAAAAAAAAC_AQAAIlIQA7-_IAKjUhADir8gAgAAbwARLKj6;BGE-gAVhPoALAAAAAAAAAGMAAAAAAAAA9NXyQAAAAAD2RolCAAAAAAsAAAAAAAAAYwAAAAAAAAC_AQAAY8weA_aELALNyx4DV4QsAgMA3woRLKj6",
function (data) {
// console.log(data.routes[0].geometry)
// console.log("decoooooooode",decode(data.routes[0].geometry, 6));
resolve(decode(data.routes[0].geometry, 6));
}
);
}
if (num == 2) {
$.get(
"https://testmap.141.ir/route/v1/driving/49.5846102,37.2793607;49.589109420776374,37.01365617294853;49.39663410186768,36.76501688279228;49.41307067871094,36.71865951515749;49.53460693359376,36.618903290216785;49.59546089172364,36.3709172544364;49.81874942779541,36.31037025501364;50.006663,36.2804074?overview=full&alternatives=true&steps=true&hints=itQMgKOuPIAYAAAAAAAAAAAAAAAAAAAAylbYQQAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAC_AQAADp30AkfYOALimfQCgdY4AgAArw8RLKj6;mVIBgECFD4AHAAAAAgAAAIMAAAB0AwAAmN51QbFihEA79YlD7x7qRAcAAAACAAAAgwAAAHQDAAC_AQAAG6v0AhLJNAJ1q_QCmMg0AgQAvwMRLKj6;bAkAgOPdLYAKAAAACgAAAAgAAABGAAAAls_iQZ5QwEEWe7FBrp87QwoAAAAKAAAACAAAAEYAAAC_AQAAMLzxAiL9MAKau_ECWf0wAgEAjwERLKj6;WQkAgISGAYAnAAAADgAAAIQGAAABAQAAczG7Qtog-UERoHVFrYgWRCcAAAAOAAAAhAYAAAEBAAC_AQAAi_vxAixIMALP-_ECREgwAhEADxURLKj6;UgkAgGdsGIBBAAAAIgAAAAAAAACJCgAAhN0LQ8sSjEIAAAAAjE-xRUEAAAAiAAAAAAAAAIkKAAC_AQAAENbzAqnBLgKP1vMCl8IuAgAAHwcRLKj6;9AgAgF5sGIARAAAAFAAAADMGAABPAgAAFgMTQjFOKEKcqFFFOFOcRBEAAAAUAAAAMwYAAE8CAAC_AQAAu8P0Agn2KgJFxPQC5fkqAjQATxERLKj6;7lcZgP___38sAAAAbQIAAAYAAACSAAAApbDRQjSWqkRVFF9Bp6esQywAAABtAgAABgAAAJIAAAC_AQAAgSz4Am0NKgJ9LPgCYg0qAgEAnwYRLKj6;e3cTgJd3E4BAAAAAHQAAAGUAAAAAAAAA_O4tQpWml0HLjoZCAAAAAEAAAAAdAAAAZQAAAAAAAAC_AQAARwr7Ak-XKQKHCvsCV5gpAgIAnxERLKj6",
function (data) {
// console.log(data.routes[0].geometry)
// console.log("decoooooooode",decode(data.routes[0].geometry, 6));
resolve(decode(data.routes[0].geometry, 6));
}
);
}
if (num == 3) {
$.get(
"https://testmap.141.ir/route/v1/driving/50.006663,36.2804074;49.5846102,37.2793607?overview=full&alternatives=true&steps=true&hints=e3cTgJd3E4BAAAAAHQAAAGUAAAAAAAAA_O4tQpWml0HLjoZCAAAAAEAAAAAdAAAAZQAAAAAAAAC_AQAARwr7Ak-XKQKHCvsCV5gpAgIAnxERLKj6;itQMgKOuPIAYAAAAAAAAAAAAAAAAAAAAylbYQQAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAC_AQAADp30AkfYOALimfQCgdY4AgAArw8RLKj6",
function (data) {
// console.log(data.routes[0].geometry)
// console.log("decoooooooode",decode(data.routes[0].geometry, 6));
resolve(decode(data.routes[0].geometry, 6));
}
);
} else if (num == 4) {
$.get(
"https://testmap.141.ir/route/v1/driving/51.0073853,35.8121955;51.4222349,36.6506071?overview=full&alternatives=true&steps=true&hints=;",
function (data) {
// console.log(data.routes[0].geometry)
// console.log("decoooooooode",decode(data.routes[0].geometry, 6));
resolve(decode(data.routes[0].geometry, 6));
}
);
} else if (num == 5) {
$.get(
"https://testmap.141.ir/route/v1/driving/51.4013785,35.7006177;53.3882906,35.5834074?overview=full&alternatives=true&steps=true",
function (data) {
console.log(data.routes[0].geometry);
// console.log("decoooooooode",decode(data.routes[0].geometry, 6));
resolve(decode(data.routes[0].geometry, 6));
}
);
} else if (num == 6) {
$.get(
"https://testmap.141.ir/route/v1/driving/51.4013785,35.7006177;46.2961952,38.0739964?overview=full&alternatives=true&steps=true&hints=C9UogA3VKIAAAAAARQAAAAAAAAAAAAAAAAAAADdAN0IAAAAAAAAAAAAAAABFAAAAAAAAAAAAAAC_AQAAIlIQA7-_IAKjUhADir8gAgAAbwARLKj6;2hQHgP___38EAAAACAAAABgAAAAIAAAAVh5JQJxEEkCgQ4NBl56tQAQAAAAIAAAAGAAAAAgAAAC_AQAAcmzCAm32RAKDbMICjPZEAgMADwcRLKj6",
function (data) {
console.log(data.routes[0].geometry);
// console.log("decoooooooode",decode(data.routes[0].geometry, 6));
resolve(decode(data.routes[0].geometry, 6));
}
);
} else if (num == 7) {
$.get(
"https://testmap.141.ir/route/v1/driving/51.4013785,35.7006177;50.21301269531251,35.00862766620555;49.531173706054695,35.12440157992044;48.740158081054695,35.09463077862675;47.0735891,34.3239414?overview=full&alternatives=true&steps=true&hints=C9UogA3VKIAAAAAARQAAAAAAAAAAAAAAAAAAADdAN0IAAAAAAAAAAAAAAABFAAAAAAAAAAAAAAC_AQAAIlIQA7-_IAKjUhADir8gAgAAbwARLKj6;2Gw8gOJsPIBuBAAAGAAAAHQNAAAiBQAArgQWRW_mRUJ3juNF-68tRW4EAAAYAAAAdA0AACIFAAC_AQAAVyX-Anj-FQKVMP4CdDAWAgYATwYRLKj6;TNQ1gP___38AAAAAUgAAAHYAAACIAAAAAAAAAEuuiUH4AsRBuhvjQQAAAAApAAAAOwAAAEQAAAC_AQAAS8TzAvvtFwImyfMCsvQXAgEALxIRLKj6;x54JgP___38hAAAARwEAADkCAAAAAAAAgJKhQoW-M0TRFq5EAAAAACEAAABHAQAAOQIAAAAAAAC_AQAArcbnAmxrFwI-t-cCZ4AXAgIA7w4RLKj6;idQHgP___38DAAAABwAAAA4AAAAHAAAAFW7OQAhf0UCc5s5BBL9OQQMAAAAHAAAADgAAAAcAAAC_AQAAVEnOAvi7CwI1Sc4C5b0LAgIAfwURLKj6",
function (data) {
// console.log(data.routes[0].geometry)
// console.log("decoooooooode",decode(data.routes[0].geometry, 6));
resolve(decode(data.routes[0].geometry, 6));
}
);
} else {
console.log("else milad");
$.get(
"https://testmap.141.ir" +
"/route/v1/driving/" +
first[1] +
"," +
first[0] +
";" +
last[1] +
"," +
last[0] +
"?overview=full&alternatives=false",
function (data) {
// console.log(data.routes[0].geometry)
// console.log("decoooooooode",decode(data.routes[0].geometry, 6));
resolve(decode(data.routes[0].geometry, 6));
}
);
}
});
result
.then((response) => {
// alert("hiii")
routeArray = response;
// console.log("routeArray" , routeArray);
showCoridorLayer(routeArray, num);
if (num == 0) {
var myarray = [];
for (i = 0; i < routeArray.length; i++) {
myarray.push(
new L.LatLng(routeArray[i][0] * 10, routeArray[i][1] * 10)
);
}
// var pointA = new L.LatLng(35.635308, 51.22496);
// var pointB = new L.LatLng(33.984461, 62.70641);
// var pointList = [pointA, pointB];
console.log("myarray ", myarray);
firoozpoly = new L.Polyline(myarray, {
color: "blue",
weight: 5,
opacity: 0.5,
smoothFactor: 1,
});
firoozpoly.addTo(map);
}
if (num == 1) {
var myarray = [];
for (i = 0; i < routeArray.length; i++) {
myarray.push(
new L.LatLng(routeArray[i][0] * 10, routeArray[i][1] * 10)
);
}
// var pointA = new L.LatLng(35.635308, 51.22496);
// var pointB = new L.LatLng(33.984461, 62.70641);
// var pointList = [pointA, pointB];
console.log("myarray ", myarray);
amolpoly = new L.Polyline(myarray, {
color: "blue",
weight: 5,
opacity: 0.5,
smoothFactor: 1,
});
amolpoly.addTo(map);
} else if (num == 2) {
var myarray = [];
for (i = 0; i < routeArray.length; i++) {
myarray.push(
new L.LatLng(routeArray[i][0] * 10, routeArray[i][1] * 10)
);
}
// var pointA = new L.LatLng(35.635308, 51.22496);
// var pointB = new L.LatLng(33.984461, 62.70641);
// var pointList = [pointA, pointB];
console.log("myarray ", myarray);
firstpolyline = new L.Polyline(myarray, {
color: "blue",
weight: 5,
opacity: 0.5,
smoothFactor: 1,
});
firstpolyline.addTo(map);
} else if (num == 3) {
var myarray = [];
for (i = 0; i < routeArray.length; i++) {
myarray.push(
new L.LatLng(routeArray[i][0] * 10, routeArray[i][1] * 10)
);
}
// var pointA = new L.LatLng(35.635308, 51.22496);
// var pointB = new L.LatLng(33.984461, 62.70641);
// var pointList = [pointA, pointB];
console.log("myarray ", myarray);
rashtpoly = new L.Polyline(myarray, {
color: "blue",
weight: 5,
opacity: 0.5,
smoothFactor: 1,
});
rashtpoly.addTo(map);
} else if (num == 4) {
var myarray = [];
for (i = 0; i < routeArray.length; i++) {
myarray.push(
new L.LatLng(routeArray[i][0] * 10, routeArray[i][1] * 10)
);
}
// var pointA = new L.LatLng(35.635308, 51.22496);
// var pointB = new L.LatLng(33.984461, 62.70641);
// var pointList = [pointA, pointB];
console.log("myarray ", myarray);
forthpolyline = new L.Polyline(myarray, {
color: "blue",
weight: 5,
opacity: 0.5,
smoothFactor: 1,
});
forthpolyline.addTo(map);
} else if (num == 5) {
var myarray = [];
for (i = 0; i < routeArray.length; i++) {
myarray.push(
new L.LatLng(routeArray[i][0] * 10, routeArray[i][1] * 10)
);
}
// var pointA = new L.LatLng(35.635308, 51.22496);
// var pointB = new L.LatLng(33.984461, 62.70641);
// var pointList = [pointA, pointB];
console.log("myarray ", myarray);
fifthpolyline = new L.Polyline(myarray, {
color: "blue",
weight: 5,
opacity: 0.5,
smoothFactor: 1,
});
fifthpolyline.addTo(map);
} else if (num == 6) {
var myarray = [];
for (i = 0; i < routeArray.length; i++) {
myarray.push(
new L.LatLng(routeArray[i][0] * 10, routeArray[i][1] * 10)
);
}
// var pointA = new L.LatLng(35.635308, 51.22496);
// var pointB = new L.LatLng(33.984461, 62.70641);
// var pointList = [pointA, pointB];
console.log("myarray ", myarray);
tabrizpoly = new L.Polyline(myarray, {
color: "blue",
weight: 5,
opacity: 0.5,
smoothFactor: 1,
});
tabrizpoly.addTo(map);
} else if (num == 7) {
var myarray = [];
for (i = 0; i < routeArray.length; i++) {
myarray.push(
new L.LatLng(routeArray[i][0] * 10, routeArray[i][1] * 10)
);
}
// var pointA = new L.LatLng(35.635308, 51.22496);
// var pointB = new L.LatLng(33.984461, 62.70641);
// var pointList = [pointA, pointB];
console.log("myarray ", myarray);
seventhpolyline = new L.Polyline(myarray, {
color: "blue",
weight: 5,
opacity: 0.5,
smoothFactor: 1,
});
seventhpolyline.addTo(map);
}
})
.catch((error) => console.log(error));
if (
num != 0 &&
num != 1 &&
num != 2 &&
num != 6 &&
num != 7 &&
num != 5 &&
num != 4 &&
num != 3
) {
routeControls.push(
L.Routing.control({
routeWhileDragging: true,
reverseWaypoints: true,
addWaypoints: false,
waypoints: [L.latLng(first[0], first[1]), L.latLng(last[0], last[1])],
lineOptions: {
styles: [
{
color: "#5789f2",
opacity: 1,
weight: 5,
},
],
},
createMarker: function (i, wp) {
if (i == 0) {
return L.marker(wp.latLng, { icon: startAbrarDivIcon });
} else {
return L.marker(wp.latLng, { icon: endAbrarDivIcon });
}
},
}).addTo(map)
);
} else if (num == 0) {
smarkerfirooz = L.marker([first[0], first[1]], {
icon: startAbrarDivIcon,
}).addTo(map);
emarkerfirooz = L.marker([last[0], last[1]], {
icon: endAbrarDivIcon,
}).addTo(map);
} else if (num == 1) {
smarkeramol = L.marker([first[0], first[1]], {
icon: startAbrarDivIcon,
}).addTo(map);
emarkeramol = L.marker([last[0], last[1]], { icon: endAbrarDivIcon }).addTo(
map
);
} else if (num == 2) {
smarkerGhRa = L.marker([first[0], first[1]], {
icon: startAbrarDivIcon,
}).addTo(map);
emarkerGhRa = L.marker([last[0], last[1]], { icon: endAbrarDivIcon }).addTo(
map
);
} else if (num == 3) {
smarkerrasht = L.marker([first[0], first[1]], {
icon: startAbrarDivIcon,
}).addTo(map);
emarkerrasht = L.marker([last[0], last[1]], {
icon: endAbrarDivIcon,
}).addTo(map);
} else if (num == 4) {
smarkerKarCh = L.marker([35.8121955, 51.0073853], {
icon: startAbrarDivIcon,
}).addTo(map);
emarkerKarCh = L.marker([last[0], last[1]], {
icon: endAbrarDivIcon,
}).addTo(map);
} else if (num == 5) {
smarkerThSe = L.marker([first[0], first[1]], {
icon: startAbrarDivIcon,
}).addTo(map);
emarkerThSe = L.marker([last[0], last[1]], { icon: endAbrarDivIcon }).addTo(
map
);
} else if (num == 6) {
smarkertabriz = L.marker([first[0], first[1]], {
icon: startAbrarDivIcon,
}).addTo(map);
emarkertabriz = L.marker([last[0], last[1]], {
icon: endAbrarDivIcon,
}).addTo(map);
} else if (num == 7) {
smarkerThKer = L.marker([first[0], first[1]], {
icon: startAbrarDivIcon,
}).addTo(map);
emarkerThKer = L.marker([last[0], last[1]], {
icon: endAbrarDivIcon,
}).addTo(map);
}
// var pointA = new L.LatLng(28.635308, 77.22496);
// var pointB = new L.LatLng(28.984461, 77.70641);
// var pointList = [pointA, pointB];
for (var i = 0; i < routeControls.length; i++) {
console.log("routeControls", routeControls[i].options.waypoints[1].lat);
}
console.log("routeControls", routeControls);
if ($(".leaflet-routing-container").length) {
$(".leaflet-routing-container").remove();
}
}
function drawPath(update) {
if (routeControls.length) {
$(routeControls).each(function (index, control) {
mapradar.removeControl(control);
routeControls.splice(routeControls.indexOf(index), 1);
});
}
routeControls.push(
L.Routing.control({
waypoints: [
L.latLng(
parseFloat(startAbrarMarker.getLatLng().lat),
parseFloat(startAbrarMarker.getLatLng().lng)
),
L.latLng(
parseFloat(endAbrarMarker.getLatLng().lat),
parseFloat(endAbrarMarker.getLatLng().lng)
),
],
fitSelectedRoutes: false,
draggableWaypoints: true,
createMarker: function () {
return null;
},
lineOptions: {
addWaypoints: false,
styles: [
{
color: "#28a745",
opacity: 0.8,
weight: 5,
},
],
},
})
.on("routingstart ", function (e) {
console.log("eeeeee", e);
})
.addTo(mapradar)
);
console.log("routeControls", routeControls);
$(".leaflet-control-container").css("display", "none");
$(".leaflet-routing-container-hide").css("display", "none");
}
var greenIcon = L.divIcon({
className: "custom-div-icon",
html: " ",
iconSize: [30, 42],
// iconAnchor: [15, 42]
});
var redIcon = L.divIcon({
className: "custom-div-icon",
html: " ",
iconSize: [30, 42],
// iconAnchor: [15, 42]
});
var greenIconFix = L.divIcon({
className: "custom-div-icon",
html: " ",
iconSize: [30, 42],
// iconAnchor: [15, 42]
});
var redIconFix = L.divIcon({
className: "custom-div-icon",
html: " ",
iconSize: [30, 42],
// iconAnchor: [15, 42]
});
var rahdariIconO = L.icon({
iconUrl: "../../dist/images/icons/tollHouseO_pin.png",
iconSize: [22, 22],
});
var rahdariIconY = L.icon({
iconUrl: "../../dist/images/icons/tollHouse_pin.png",
iconSize: [26, 26],
});
var bounds = [
[42.9130026312, 75.6166317076],
[20.5782370061, 30.5092252948],
];
var map = L.map("map", {
maxBounds: bounds,
minZoom: MAP_MIN_ZOOM,
zoomControl: false,
}).setView([35.5468992, 51.7300532], 7);
L.tileLayer(MAP_ENDPOINT + "/141map/{z}/{x}/{y}.png", {}).addTo(map);
$(document).ready(function () {
var urlParams = new URLSearchParams(window.location.search);
console.log(urlParams.get("type"));
globalqueryparam = urlParams.get("type");
if (globalqueryparam == "allpoints") {
showallpoint();
}else if (globalqueryparam == "fastreact") {
showfastreaction();
}else if (globalqueryparam == "pro") {
getMaintenanceProjects();
$(".guid-custom-box").css("display", "block");
}else if (globalqueryparam == "rahdar") {
showrahdarkhane();
}else if (globalqueryparam == "251points") {
showAccident251Points();
}else if (globalqueryparam == "rahdari") {
showDailyRahdariActivity();
}else if (globalqueryparam == "barkhordari") {
$.ajax({
url: "https://rms.rmto.ir/public/contents/provinces",
type: "GET",
cache: false,
contentType: false,
processData: false,
success: function (result) {
provincesArray = result.data;
renderprovince(provincesArray);
},
error: function (error) {},
});
$.ajax({
url: "https://141.ir/api/provinces35geojson",
type: "GET",
success: function (response) {
iranGeoJSON = JSON.parse(response);
},
});
$.ajax({
url: "https://141.ir/api/cities430geojson",
type: "GET",
success: function (response) {
fullCityGeoJSON = JSON.parse(response);
},
});
function addCityFeaturesToMap() {
keepMapFeatureColor = null;
if (fullCityGeoJSONTemp) {
iranCityMapGeo = L.geoJson(fullCityGeoJSONTemp, {
style: initStyleCityMapFeatures,
onEachFeature: onEachCityFeature,
});
iranCityMapGeo.addTo(map);
}
}
function getForArrayFeatureColor(arrayNum) {
if (keepMapFeatureColor) {
return { num: -1, color: keepMapFeatureColor };
} else {
return arrayNum >= 83
? { num: arrayNum, color: "#a366ff" }
: arrayNum >= 67
? { num: arrayNum, color: "#80b3ff" }
: arrayNum >= 50
? { num: arrayNum, color: "#66cc66" }
: arrayNum >= 31
? { num: arrayNum, color: "#ffeda0" }
: { num: arrayNum, color: "#ff704d" };
}
}
function fillcolorme(featureRow) {
for (let i = 0; i < provincesArray.length; i++) {
if (i == featureRow) {
return provincesArray[i].abrar_process;
}
}
}
function initStyleMapFeatures() {
let getRandom = null;
getRandom = getForArrayFeatureColor(fillcolorme(iranArrayCount));
let makeStyle = {
fillColor: getRandom.color,
weight: 2,
opacity: 1,
color: "white",
fillOpacity: 0.7,
};
if (getRandom.num != -1) {
if (iranArrayCount == 35) {
iranArrayCount = 0;
}
iranArrayCount++;
}
return makeStyle;
}
function highlightMapFeature(e) {
let targetAtt = e.target.feature.properties;
let featureLayer = null;
if (e.target) {
featureLayer = e.target;
} else {
featureLayer = e;
}
keepMapFeatureColor = featureLayer.options.fillColor;
featureLayer.setStyle({
weight: 4,
color: "#666",
fillOpacity: 0.85,
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
featureLayer.bringToFront();
}
if (e.target) {
if (flagProvince == 0) {
let popup = L.popup();
for (let i = 0; i < provincesArray.length; i++) {
if (targetAtt.province_id == provincesArray[i].id) {
popup
.setLatLng([
provincesArray[i].center_lat,
provincesArray[i].center_long,
])
.setContent(
`
`
)
.openOn(map);
}
}
//Start Province
$(`#target${targetAtt.province_id}`)
.css("transform", "scale(1.1)")
.animate({
marginTop: "10px",
marginBottom: "10px",
});
$("html .list-province")
.stop()
.animate({
scrollTop:
$(`#target${targetAtt.province_id}`).offset().top - 380.59,
});
//End Province
}
//Start City
//End City
}
if (targetAtt.city_id) {
if (flagCity == 0) {
let popup = L.popup();
for (let i = 0; i < citiesArray.length; i++) {
if (targetAtt.city_id == citiesArray[i].id) {
popup
.setLatLng(e.latlng)
.setContent(
`
`
)
.openOn(map);
}
}
}
$(`#target${targetAtt.city_id}`)
.css("transform", "scale(1.1)")
.animate({
marginTop: "10px",
marginBottom: "10px",
});
$("html .list-province")
.stop()
.animate({
scrollTop: $(`#target${targetAtt.city_id}`).offset().top - 380.59,
});
}
}
function resetMapFeatureHighlight(e) {
let targetAtt = e.target.feature.properties;
let featureLayer = null;
if (e.target) {
featureLayer = e.target;
} else {
featureLayer = e;
}
iranMapGeo.resetStyle(featureLayer);
keepMapFeatureColor = null;
$(`#target${targetAtt.province_id}`).css("transform", "").animate({
marginTop: "",
marginBottom: "",
});
$(`#target${targetAtt.city_id}`).css("transform", "").animate({
marginTop: "",
marginBottom: "",
});
$("html .list-province").stop().animate({
scrollTop: 0,
});
}
function zoomMapToFeature(e) {
if ($(".backStack").has("d-none")) {
$(".backStack")
.removeClass("d-none")
.addClass("animate__animated animate__backInLeft");
} else {
$(".backStack")
.addClass("d-none")
.removeClass("animate__animated animate__backInLeft");
}
let IdProvince = e.target.feature.properties.province_id;
$.ajax({
url: "https://rms.rmto.ir/public/contents/provinces/" + IdProvince,
type: "GET",
cache: false,
contentType: false,
processData: false,
success: function (result) {
citiesArray = result.data;
},
error: function (error) {},
});
let featureLayer = null;
let featuresLayerCity = [];
if (e.target) {
featureLayer = e.target;
} else {
featureLayer = e;
}
map.flyToBounds(featureLayer.getBounds());
showLoaderScreen();
removeFeaturesFromMap();
// removeCityFeaturesFromMap();
fullCityGeoJSONTemp.type = "FeatureCollection";
$.each(fullCityGeoJSON.features, function (key, value) {
if (
value &&
featureLayer.feature.properties.province_id ===
value.properties.province_id
) {
featuresLayerCity.push(value);
} else {
//
}
});
setTimeout(function () {
//todo pooria
fullCityGeoJSONTemp.features = featuresLayerCity;
for (let i = 0; i < fullCityGeoJSONTemp.features.length; i++) {
for (let j = 0; j < citiesArray.length; j++) {
if (
fullCityGeoJSONTemp.features[i].properties.city_id ==
citiesArray[j].id
) {
fullCityGeoJSONTemp.features[i].properties["abrar_process"] =
citiesArray[j].abrar_process;
}
}
}
statusSet = true;
renderprovince(fullCityGeoJSONTemp.features, statusSet);
addCityFeaturesToMap();
}, 1000);
setTimeout(function () {
hideLoaderScreen();
}, 1500);
flagProvince = 1;
iranCityCount = 0;
}
$(".backStack").on("click", function () {
removeFeaturesCity();
});
function onEachFeature(feature, featureLayer) {
featureLayer.on({
mouseover: highlightMapFeature,
mouseout: resetMapFeatureHighlight,
click: zoomMapToFeature,
});
}
function onEachCityFeature(feature, featureLayer) {
featureLayer.on({
mouseover: highlightMapFeature,
mouseout: resetMapFeatureHighlight,
//click: zoomMapToFeature
});
}
function getRandomFeatureColor(arrayNum) {
if (keepMapFeatureColor) {
return { num: -1, color: keepMapFeatureColor };
} else {
return arrayNum.abrar_process >= 83
? { num: arrayNum, color: "#a366ff" }
: arrayNum.abrar_process >= 67
? { num: arrayNum, color: "#80b3ff" }
: arrayNum.abrar_process >= 50
? { num: arrayNum, color: "#66cc66" }
: arrayNum.abrar_process >= 31
? { num: arrayNum, color: "#ffeda0" }
: { num: arrayNum, color: "#ff704d" };
}
}
function fillcolorCity(featureRow) {
console.log(featureRow);
for (let i = 0; i < fullCityGeoJSONTemp.features.length; i++) {
if (i == featureRow) {
console.log(fullCityGeoJSONTemp.features[i].properties);
return fullCityGeoJSONTemp.features[i].properties;
}
}
}
function initStyleCityMapFeatures(feature) {
// let getRandom = getRandomFeatureColor(fillcolorCity(iranCityCount));
let getRandom = getRandomFeatureColor(fillcolorCity(iranCityCount));
let makeStyle = {
fillColor: getRandom.color,
weight: 2,
opacity: 1,
color: "white",
fillOpacity: 0.5,
};
if (iranCityCount == fullCityGeoJSONTemp.features.length) {
iranCityCount = 0;
}
iranCityCount++;
return makeStyle;
}
function removeFeaturesFromMap() {
if (iranMapGeo) {
map.removeLayer(iranMapGeo);
}
}
function removeFeaturesCity() {
if (fullCityGeoJSONTemp.features) {
map.removeLayer(iranCityMapGeo);
statusSet = false;
flagProvince = 0;
}
setTimeout(() => {
iranMapGeo = L.geoJson(iranGeoJSON, {
style: initStyleMapFeatures,
onEachFeature: onEachFeature,
});
iranMapGeo.addTo(map);
}, 1000);
renderprovince(provincesArray);
}
setTimeout(() => {
iranMapGeo = L.geoJson(iranGeoJSON, {
style: initStyleMapFeatures,
onEachFeature: onEachFeature,
});
iranMapGeo.addTo(map);
}, 1000);
function renderprovince(data, ajaze) {
if ($(".province-data").children().length) {
$(".province-data").children().remove();
}
data.forEach((element) => {
if (ajaze) {
$(".province-data").append(`
`);
} else {
$(".province-data").append(`
`);
}
});
$(".progressBar-province span").each(function (index, element) {
if ($(element).text() >= "83") {
$(element).parent().css({
backgroundColor: "#a366ff",
height: "100%",
borderRadius: "10px",
});
} else if ($(element).text() >= "67") {
$(element).parent().css({
backgroundColor: "#80b3ff",
height: "100%",
borderRadius: "10px",
});
} else if ($(element).text() >= "50") {
$(element).parent().css({
backgroundColor: "#66cc66",
height: "100%",
borderRadius: "10px",
});
} else if ($(element).text() >= "31") {
$(element).parent().css({
backgroundColor: "#ffeda0",
height: "100%",
borderRadius: "10px",
});
} else {
$(element).parent().css({
backgroundColor: "#ff704d",
height: "100%",
borderRadius: "10px",
});
}
});
}
}
});
$(document).mouseup(function (e) {
var container = $(".left-menu-view-chartt");
if (!container.is(e.target) && container.has(e.target).length === 0) {
$(".left-menu-view-chartt").css("left", "-1600px");
}
});
function showrahdarkhane() {
remove141Layer();
showLoaderScreen();
$.get(API_TEST + "/rahdari-points", function (result) {
console.log("ressss", result);
data = result.data;
let markerG = [];
marker141Layers = L.markerClusterGroup();
for (let i = 0; i < data.length; i++) {
if (result.edit_id == data[i].province_id) {
setIcon = rahdariIconO;
} else {
setIcon = rahdariIconY;
}
if (
data[i].lat == "-" ||
data[i].lng == "-" ||
data[i].lat == "0" ||
data[i].lng == "0"
) {
continue;
}
let marker = L.marker([data[i].lat, data[i].lng], {
icon: setIcon,
content: data[i],
})
.on("click", function (e) {
console.log("eeeeeee", e);
$("[data-mask]").inputmask();
console.log("test", this.options.content);
let datatext = this.options.content;
$("#houserahdar").val(datatext.name);
$("#rahdarid").val(datatext.id);
$("#edarekol").val(datatext.province_name);
$("#mainCity").val(datatext.city_name);
$("#sit").val(datatext.status); //action
$("#type").val(datatext.type);
$("#phone").val(datatext.phone);
$("#ekipnum").val(datatext.team_num);
$("#personelnum").val(datatext.staff_num);
$("#masol").val(datatext.responsible_name);
$("#masolmobile").val(datatext.responsible_mobile);
$("#janeshin").val(datatext.successor_name);
$("#janeshinmobile").val(datatext.successor_mobile);
$("#lightmachine").val(datatext.machines_light);
$("#meduimachin").val(datatext.machines_sheavy);
$("#bigmachin").val(datatext.machines_heavy);
$("#lat-rahdar").val(datatext.lat);
$("#lng-rahdar").val(datatext.lng);
})
.bindPopup(getPopupContentRahdar(data[i], result.edit_id), {
className: "customPopupStyle",
});
if (result.edit_id == data[i].province_id) {
markerG.push(marker);
} else {
marker141List.push(marker);
}
}
marker141LayersWithoutCluster = L.layerGroup(markerG);
marker141Layers.addLayers(marker141List);
map.addLayer(marker141Layers);
map.addLayer(marker141LayersWithoutCluster);
hideLoaderScreen();
});
}
function showAccident251Points() {
remove141Layer();
showLoaderScreen();
$.get(API_TEST + "/accident-251-points", function (result) {
let roadAccidentPoints = result.data;
console.log("|test" ,roadAccidentPoints )
let markerG = [];
for (let i = 0; i < roadAccidentPoints.length; i++) {
try {
let setIcon = null;
if (roadAccidentPoints[i].progress == "100") {
if (result.edit_id == roadAccidentPoints[i].province_id) {
console.log("testtt" ,result.edit_id )
setIcon = greenIcon;
} else {
setIcon = greenIconFix;
}
} else {
if (result.edit_id == roadAccidentPoints[i].province_id) {
setIcon = redIcon;
} else {
setIcon = redIconFix;
}
}
let marker = L.marker(
[roadAccidentPoints[i].lat, roadAccidentPoints[i].lng],
{
icon: setIcon,
content: roadAccidentPoints[i],
}
)
// console
// .log("nn", marker)
.on("click", function (e) {
$("[data-mask]").inputmask();
let valueprogress = "";
let datatext = this.options.content;
$("#pointid").val(datatext.id);
$("#opration").val(datatext.operation); //oparation
$("#target").val(datatext.target); //target
$("#action").val(datatext.actions); //action
$("#ac-point-lat").val(datatext.lat);
$("#ac-point-lng").val(datatext.lng);
valueprogress = datatext.progress;
let test =
'\
';
$("#sliderphysici").empty();
$("#sliderphysici").append(
' پیشرفت فیزیکی '
);
$("#sliderphysici").append(test);
$(".ex2").slider({
min: 0,
max: 100,
formatter: function (value) {
return value + "٪";
},
tooltip: "always",
tooltip_position: "bottom",
});
$("#end-date").persianDatepicker({
format: "MMMM YYY",
autoClose: true,
viewMode: "month",
dayPicker: {
enabled: false,
},
});
$("#cost").val(datatext.cost); //cost
//$("#cost").attr('min', datatext.cost);//cost
$("#end-date").val(datatext.end_date); //end-date
})
.bindPopup(
getPopupContentAccident_251(roadAccidentPoints[i], result.edit_id),
{ className: "customPopupStyle" }
);
console.log("mm" ,marker )
markerG.push(marker);
console.log("mmerkerg", markerG);
} catch (e) {}
}
marker141Layers = L.layerGroup(markerG);
map.addLayer(marker141Layers);
hideLoaderScreen();
});
}
function showfastreaction() {
$("#modal-fastreact").modal("show");
toDate = $("#fastreact-todate").persianDatepicker({
format: "YYYY/MM/DD",
autoClose: true,
format: "YYYY/MM/DD",
autoClose: true,
onSelect: function (unix) {
toDate.touched = true;
},
});
let test = moment(
toDate.getState().selected.year +
"/" +
toDate.getState().selected.month +
"/" +
toDate.getState().selected.date,
"jYYYY/jM/jD"
).format("YYYY-MM-DD");
console.log("hh", test);
frommDate = $("#fastreact-fromdate").persianDatepicker({
observer: true,
format: "YYYY/MM/DD",
altField: ".observer-example-alt",
autoClose: true,
onSelect: function (unix) {
frommDate.touched = true;
if (
frommDate.getState().selected.unixDate >=
toDate.getState().selected.unixDate
) {
toDate.setDate(frommDate.getState().selected.unixDate);
}
if (toDate && toDate.options && toDate.options.minDate != unix) {
let cachedValue = toDate.getState().selected.unixDate;
toDate.options = { minDate: unix };
if (toDate.touched) {
toDate.setDate(cachedValue);
}
}
},
});
// //search option for date of fastreact
var showFastReactionPoint = true;
$("#fastreact_search_option").on("click", function () {
$("#modal-fastreact").modal("hide");
if (
$("#fastreact-fromdate").val() != " " &&
$("#fastreact-todate").val() != " "
) {
let startDate = moment(
frommDate.getState().selected.year +
"/" +
frommDate.getState().selected.month +
"/" +
frommDate.getState().selected.date,
"jYYYY/jM/jD"
).format("YYYY-MM-DD");
console.log("lll", startDate);
let endDate = moment(
toDate.getState().selected.year +
"/" +
toDate.getState().selected.month +
"/" +
toDate.getState().selected.date,
"jYYYY/jM/jD"
).format("YYYY-MM-DD");
console.log("lll", endDate);
if (showFastReactionPoint) {
showFastFunction(startDate, endDate);
} else {
console.log(startDate, endDate);
$.ajax({
url:
API_TEST +
"/public/homeprojects/fast/points" +
"?end-date=" +
endDate +
"&start-date=" +
startDate,
type: "GET",
success: function (result) {
console.log("resssss", result.data);
// show_point(result.data);
},
error: function (error) {
console.log(error);
},
});
}
}
});
function showFastFunction(startDate, endDate) {
showLoaderScreen();
$.ajax({
url:
API_TEST +
"/public/homeprojects/fast/points" +
"?end-date=" +
endDate +
"&start-date=" +
startDate,
type: "GET",
cache: false,
contentType: false,
processData: false,
success: function (result) {
console.log(result);
hideLoaderScreen();
// showFastReactionPoint = false;
let roadMaintenancePoints = result.data;
let markerG = [];
for (let i = 0; i < roadMaintenancePoints.length; i++) {
try {
let setIcon = null;
let pos = null;
if (roadMaintenancePoints[i].rms_status == 0) {
setIcon = redIcon;
pos = [
roadMaintenancePoints[i].lat,
roadMaintenancePoints[i].lng,
];
console.log("pos", pos);
} else {
setIcon = greenIcon;
pos = roadMaintenancePoints[i].rms_start_latlng;
}
if (pos != null) {
let marker = L.marker(pos, {
icon: setIcon,
content: roadMaintenancePoints[i],
}).bindPopup(
getPopupContentFastReaction(roadMaintenancePoints[i]),
{
className: "customPopupStyle",
}
);
markerG.push(marker);
} else {
console.log("Number of null coordinates!");
}
//marker141Layers.push(marker);
//map.addLayer(marker)
} catch (e) {
//
}
}
marker141Layers = L.layerGroup(markerG);
// marker141Layers.addLayers(marker141List);
map.addLayer(marker141Layers);
},
error: function (error) {
console.log(error);
},
});
}
}
function showallpoint() {
remove141Layer();
showLoaderScreen();
if (marker141Layers != null) {
marker141List = [];
map.removeLayer(marker141Layers);
}
if (marker141LayersWithoutCluster != null) {
map.removeLayer(marker141LayersWithoutCluster);
}
$.ajax({
url: API_TEST + "/accident-points",
type: "GET",
success: function (result) {
console.log(result);
let roadAccidentPoints = result.data;
hideLoaderScreen();
//console.log(roadAccidentPoints);
let markerG = [];
for (let i = 0; i < roadAccidentPoints.length; i++) {
if (
roadAccidentPoints[i].progress == "100" ||
(roadAccidentPoints[i].accident251_point &&
roadAccidentPoints[i].accident251_point.progress == "100")
) {
if (result.edit_id == roadAccidentPoints[i].province_id) {
setIcon = greenIcon;
} else {
setIcon = "#28a745";
}
} else {
if (result.edit_id == roadAccidentPoints[i].province_id) {
setIcon = redIcon;
} else {
setIcon = "#dc3545";
}
}
try {
let marker = null;
if (result.edit_id == roadAccidentPoints[i].province_id) {
marker = L.marker(
[roadAccidentPoints[i].lat, roadAccidentPoints[i].lng],
{
icon: setIcon,
content: roadAccidentPoints[i],
}
)
.on("click", function (e) {
$("[data-mask]").inputmask();
//console.log(this.options.content)
let valueprogress = "";
let contentData = this.options.content;
$("#allpointid").val(contentData.id);
$("#allend-date").persianDatepicker({
format: "MMMM YYY",
autoClose: true,
viewMode: "month",
dayPicker: {
enabled: false,
},
});
if (contentData.accident251_point) {
$("#alloperation").val(
contentData.accident251_point.operation
);
$("#alltarget").val(contentData.accident251_point.target);
$("#allaction").val(contentData.accident251_point.actions);
$("#allcost").val(contentData.accident251_point.cost);
//$("#allcost").attr('min', contentData.accident251_point.cost);
$("#allend-date").val(contentData.accident251_point.end_date);
valueprogress = contentData.accident251_point.progress;
} else {
$("#alloperation").val("-");
$("#alltarget").val("-");
$("#allaction").val("-");
$("#allcost").val(contentData.cost);
$("#allcost").val(contentData.cost);
//$("#allcost").attr('min', contentData.cost);
$("#allend-date").val("-");
valueprogress = contentData.progress;
}
$("#allac-point-lat").val(contentData.lat);
$("#allac-point-lng").val(contentData.lng);
let test =
'\
';
$("#allsliderphysici").empty();
$("#allsliderphysici").append(
' پیشرفت فیزیکی '
);
$("#allsliderphysici").append(test);
$(".allex2").slider({
min: 0,
max: 100,
formatter: function (value) {
return value + "٪";
},
tooltip: "always",
tooltip_position: "bottom",
});
})
.bindPopup(
getPopupContentAccident(roadAccidentPoints[i], result.edit_id),
{ className: "customPopupStyle" }
);
} else {
marker = L.circleMarker(
[roadAccidentPoints[i].lat, roadAccidentPoints[i].lng],
{
color: setIcon,
stroke: false,
radius: 3,
fillOpacity: 1,
}
).bindPopup(
getPopupContentAccident(roadAccidentPoints[i], result.edit_id),
{ className: "customPopupStyle" }
);
}
markerG.push(marker);
} catch (e) {
console.log(e);
}
}
marker141Layers = L.layerGroup(markerG);
map.addLayer(marker141Layers);
},
error: function (error) {
//console.log(error);
},
});
}
function getPopupContentAccident(data, edit_id) {
let popupTitle251 = "";
if (data.accident251_point) {
popupTitle251 = " (اولویت ۲۵۱ نقطه)";
}
if (edit_id == data.province_id) {
if (data.accident251_point) {
return (
'\
\
'
);
} else if (
(data.target && data.target != "-") ||
(data.operation && data.operation != "-")
) {
return (
'\
\
'
);
} else {
return (
'\