var list_sub; var sub_item_str; var list_sub_itemId; var toDateAxis, fromDateAxis; var currentDate = []; var excelParam = ""; //maps variable var startAbrarMarker = null; var isSetStartAbrarMarker = false; var endAbrarMarker = null; var isSetEndAbrarMarker = false; var saveTotalDistance = null; var sourceMarker; var sourceLat = ""; var sourceLng = ""; var destMarker; var destLat = ""; var destLng = ""; var routeControls = []; var popupArrays = []; var bounds = [ [46.9130026312, 77.6166317076], [17.5782370061, 32.5092252948], ]; var destinationCoordinates = null; var sourceCoordinates = null; var roadPatrolProject = []; var roadObserved = []; var contractSubItems = []; var roadItemsProject = []; var AxisMarkerList = []; var AxisMarkerLayer = null; var startP = [35.6892, 51.389]; var endP = [35.6892, 51.389]; var operation_res; (() => { const heightHeader = $('.header').height() document.getElementById('mymap').style.setProperty('height', `calc(100vh - ${heightHeader}px)`) })() function showLoaderScreen() { $(".divloader").css("display", "flex").hide().fadeIn(); } function hideLoaderScreen() { $(".divloader").fadeOut(); } var purpleIcon = L.divIcon({ className: "custom-div-icon", html: "", iconSize: [32, 44], }); var pinkIcon = L.divIcon({ className: "custom-div-icon", html: "", iconSize: [32, 44], }); var greenIcon = L.divIcon({ className: "custom-div-icon", html: "", iconSize: [32, 44], }); var redIcon = L.divIcon({ className: "custom-div-icon", html: "", iconSize: [32, 44], }); var blueIcon = L.divIcon({ className: "custom-div-icon", html: "", iconSize: [32, 44], }); var trafficLayer = L.tileLayer( "https://rmssatmap.rmto.ir/sat/{z}/{x}/{y}.jpg", {} ); var iranLayer = L.tileLayer( "https://rmsmap.rmto.ir/141map/{z}/{x}/{y}.png", {} ); $.ajax({ url: "/api/get-items-and-subs", type: "GET", async: false, success: function (data) { list_sub = data.items; for (index = 0; index < list_sub.length; index++) { var dailyActivity_subStr = list_sub[index].item_str; var dailyActivity_itemId = list_sub[index].item_id; $("#dailyActivity_sub").append( "
  • " ); } }, }); $.ajax({ url: "/csi/operation", type: "GET", cache: false, contentType: false, processData: false, success: function (res) { operation_res = res; $.each(operation_res, function (key, value) { $(".opration_natural").append( `
  • ${value.farsi}
  • ` ); }); }, error: function (error) { hideLoaderScreen(); Swal.fire({ icon: "error", title: "خطا", text: "مشکل در در دریافت ماهیت پروژه", confirmButtonText: "بستن", }); console.log(error); }, }); $.ajax({ url: "/api/get-items-and-subs", type: "GET", async: false, success: function (data) { list_sub_sub = data.data; for (i = 0; i < list_sub_sub.length; i++) { list_sub_itemId = list_sub_sub[i].item_id; $(document) .find(".myId" + list_sub_itemId) .append( "
  • " + list_sub_sub[i].sub_item_str + "
  • " ); } }, }); //items data //markers var startAbrarDivIcon = L.divIcon({ html: `
    شروع
    `, iconSize: [55, 75], iconAnchor: [33, 64], }); var endAbrarDivIcon = L.divIcon({ html: `
    پایان
    `, iconSize: [55, 75], iconAnchor: [33, 64], }); //markers //map start UncheckAll(); var mymap = L.map("mymap", { maxBounds: bounds, minZoom: 7, }).setView([35.5468992, 51.7300532], 6); mymap.addLayer(iranLayer); // map start //apending pin to map startAbrarMarker = new L.marker(L.latLng(mymap.getCenter()), { icon: startAbrarDivIcon, draggable: true, }).addTo(mymap); endAbrarMarker = new L.marker(L.latLng(mymap.getCenter()), { icon: endAbrarDivIcon, draggable: true, }); //apending pin to map //map move mymap.on("move", function () { if (!isSetStartAbrarMarker && !isSetEndAbrarMarker) { startAbrarMarker.setLatLng(L.latLng(mymap.getCenter())); $("#pin-marker-start").removeClass("pin-set").addClass("pin-move"); } if (isSetStartAbrarMarker && !isSetEndAbrarMarker) { endAbrarMarker.setLatLng(L.latLng(mymap.getCenter())); $("#pin-marker-end").removeClass("pin-set").addClass("pin-move"); } }); mymap.on("moveend", function () { if (!isSetStartAbrarMarker && !isSetEndAbrarMarker) { startAbrarMarker.setLatLng(L.latLng(mymap.getCenter())); $("#pin-marker-start").removeClass("pin-move pin-set"); } if (isSetStartAbrarMarker && !isSetEndAbrarMarker) { endAbrarMarker.setLatLng(L.latLng(mymap.getCenter())); $("#pin-marker-end").removeClass("pin-move pin-set"); } }); //map move // (start marker) //map click startAbrarMarker.on("click", function () { sourceLat = mymap.getCenter().lat; sourceLng = mymap.getCenter().lng; if (!isSetStartAbrarMarker) { startAbrarMarker.setLatLng(L.latLng(mymap.getCenter())); isSetStartAbrarMarker = true; $("#pin-marker-start").removeClass("pin-move pin-warn").addClass("pin-set"); } addSourceMarker(1); endAbrarMarker.addTo(mymap); showItemSelectionModal(); $(this).hide(); $("#pin-marker-start").removeClass("pin-move pin-warn").addClass("pin-set"); }); //map click //map drag start part startAbrarMarker.on("drag", function () { $("#pin-marker-start").addClass("pin-move"); }); //map drag start part // map drag end part startAbrarMarker.on("dragend", function () { $("#pin-marker-start").removeClass("pin-move"); if ($("#pin-marker-start").hasClass("pin-set") || isSetStartAbrarMarker) { $("#pin-marker-start").addClass("pin-set"); checkMarkersAndDrawPath(); } else { mymap.setView(startAbrarMarker.getLatLng()); } }); //map drag end part // (start marker) // (end marker) //map click endAbrarMarker.on("click", function () { destLat = mymap.getCenter().lat; destLng = mymap.getCenter().lng; addDestinationMarker(1); if (!isSetEndAbrarMarker) { endAbrarMarker.setLatLng(L.latLng(mymap.getCenter())); isSetEndAbrarMarker = true; $("#pin-marker-end").removeClass("pin-move").addClass("pin-set"); } checkMarkersAndDrawPath(); }); //map click //map drag start part endAbrarMarker.on("drag", function () { $("#pin-marker-end").addClass("pin-move"); checkMarkersAndDrawPath(); }); //map drag start part //map drag end part endAbrarMarker.on("dragend", function () { $("#pin-marker-end").removeClass("pin-move"); if ($("#pin-marker-end").hasClass("pin-set") || isSetEndAbrarMarker) { $("#pin-marker-end").addClass("pin-set"); checkMarkersAndDrawPath(); } else { mymap.setView(endAbrarMarker.getLatLng()); } }); //map drag end part // (end marker) //functions refers map function addSourceMarker(type) { if (type == 1) { sourceCoordinates = L.latLng(mymap.getCenter()); } else if (type == 2) { sourceCoordinates = [sourceLat, sourceLng]; } } function addDestinationMarker(type) { if (type == 1) { destinationCoordinates = L.latLng(mymap.getCenter()); } else if (type == 2) { destinationCoordinates = [destLat, destLng]; } } function checkMarkersAndDrawPath() { if ( $("#pin-marker-start").hasClass("pin-set") && !$("#pin-marker-start").hasClass("pin-move") && $("#pin-marker-end").hasClass("pin-set") && !$("#pin-marker-end").hasClass("pin-move") ) { showLoaderScreen(); routing( startAbrarMarker.getLatLng().lat, startAbrarMarker.getLatLng().lng, endAbrarMarker.getLatLng().lat, endAbrarMarker.getLatLng().lng ); } } $(".filter-happend").attr("disabled", true); $(".filter-happend").text("ثبت موقعیت اجباریست"); $(".filter-happend").addClass("btn-warning"); $(".filter-happend").removeClass("btn-primary"); $(".excel-happend").attr("disabled", true); function showItemSelectionModal() { if (destLat != "") { if ( $(".guid-custom-box-AxisReport input[type=checkbox]:checked").length != 0 ) { $(".filter-happend").attr("disabled", false); $(".filter-happend").text("اعمال"); $(".filter-happend").removeClass("btn-warning"); $(".filter-happend").addClass("btn-primary"); } else { $(".filter-happend").text("انتخاب آیتم ضروری است"); $(".filter-happend").attr("disabled", true); $(".filter-happend").addClass("btn-warning"); $(".filter-happend").removeClass("btn-primary"); } } } $(".guid-custom-box-AxisReport input[type=checkbox]").change(function () { if ($(this).is(":checked")) { showItemSelectionModal(); } else { showItemSelectionModal(); } }); //functions refers map //date givinchi fromDateAxis = $("#Axis-fromdate").persianDatepicker({ observer: true, format: "YYYY/MM/DD", altField: ".observer-example-alt", autoClose: true, onSelect: function (unix) { fromDateAxis.touched = true; $("#Axis-todate").prop("disabled", ""); if ( fromDateAxis.getState().selected.unixDate >= toDateAxis.getState().selected.unixDate ) { toDateAxis.setDate(fromDateAxis.getState().selected.unixDate); } if ( toDateAxis && toDateAxis.options && toDateAxis.options.minDate != unix ) { let cachedValue = toDateAxis.getState().selected.unixDate; toDateAxis.options = { minDate: unix }; if (toDateAxis.touched) { toDateAxis.setDate(cachedValue); } } }, }); toDateAxis = $("#Axis-todate").persianDatepicker({ format: "YYYY/MM/DD", autoClose: true, format: "YYYY/MM/DD", autoClose: true, onSelect: function (unix) { toDateAxis.touched = true; }, }); // date givinchi // lateral $(document).on("click", ".iran-change-layer", function () { changelayer(); }); $(document).on("click", ".dropdownstart", function () { var dropdown = $(this).parents(".layerButton1"); $(dropdown).find(".layerbuttonparent").slideToggle(500); }); $(document).on("click", ".dropdownstart_sub", function () { var dropdown = $(this).parents(".layerButton2"); $(dropdown).find(".layerbuttonparent_sub").slideToggle(500); }); $(document).on("click", ".All_button", function () { var button_parent = $(this).parents(".layerButton1"); if ($(this).text() == "انتخاب همه") { $(this).text("لغو همه"); $(button_parent) .find(".layerbuttonparent input[type=checkbox]") .prop("checked", true); $(button_parent).find(".layerbuttonparent").slideDown(500); $(button_parent).find(".layerbuttonparent_sub").slideDown(500); $(button_parent).find(".All_button_sub").attr("disabled", true); } else { $(this).text("انتخاب همه"); $(button_parent) .find(".layerbuttonparent input[type=checkbox]") .prop("checked", false); $(button_parent).find(".layerbuttonparent").slideUp(500); $(button_parent).find(".layerbuttonparent_sub").slideUp(500); $(button_parent).find(".All_button_sub").attr("disabled", false); } showItemSelectionModal(); }); $(document).on("click", ".All_button_sub", function () { var button_parent = $(this).parents(".layerButton2"); if ($(this).text() == "انتخاب همه") { $(this).text("لغو همه"); $(button_parent) .find(".layerbuttonparent_sub input[type=checkbox]") .prop("checked", true); $(button_parent).find(".layerbuttonparent_sub").slideDown(500); } else { $(this).text("انتخاب همه"); $(button_parent) .find(".layerbuttonparent_sub input[type=checkbox]") .prop("checked", false); $(button_parent).find(".layerbuttonparent_sub").slideUp(500); } showItemSelectionModal(); }); // lateral // change layer function changelayer() { if (mymap.hasLayer(iranLayer)) { var currZoom = mymap.getZoom(); if (currZoom < 8) { mymap.setZoom(8); } mymap.removeLayer(iranLayer); mymap.addLayer(trafficLayer); mymap.options.minZoom = 8; mymap.options.maxZoom = 14; } else if (mymap.hasLayer(trafficLayer)) { mymap.removeLayer(trafficLayer); mymap.addLayer(iranLayer); mymap.options.minZoom = 6; } } //chamge layer // points start $("#filterEnd").on("click", function () { currentDate.from = moment( fromDateAxis.getState().selected.year + "/" + fromDateAxis.getState().selected.month + "/" + fromDateAxis.getState().selected.date, "jYYYY/jM/jD" ).format("YYYY-MM-DD"); currentDate.to = moment( toDateAxis.getState().selected.year + "/" + toDateAxis.getState().selected.month + "/" + toDateAxis.getState().selected.date, "jYYYY/jM/jD" ).format("YYYY-MM-DD"); let url = "/api/axis-report?"; let param = ""; param += `slat=${startAbrarMarker.getLatLng().lat.toFixed(6)}`; param += `&slng=${startAbrarMarker.getLatLng().lng.toFixed(6)}`; param += `&dlat=${endAbrarMarker.getLatLng().lat.toFixed(6)}`; param += `&dlng=${endAbrarMarker.getLatLng().lng.toFixed(6)}`; param += `&date_from=${currentDate.from}`; param += `&date_to=${currentDate.to}`; if ($(".input-daily-activity:checked").length != 0) param += `&type[]=1`; if ($(".input-road-patrol:checked").length != 0) param += `&type[]=2`; if ( $(".input-contract-status:checked").length != 0 || $(".input-project-type:checked").length != 0 ) param += `&type[]=3`; if ($(".input-road-type:checked").length != 0) param += `&type[]=4`; $(".input-daily-activity:checked").each(function (index, element) { param += `&daily_activity[]=${$(element).val()}`; }); $(".input-contract-status:checked").each(function (index, element) { param += `&contract_status[]=${$(element).val()}`; }); $(".input-project-type:checked").each(function (index, element) { param += `&project_type[]=${$(element).val()}`; }); $(".input-road-type:checked").each(function (index, element) { param += `&road_type[]=${$(element).val()}`; }); url += param; $.ajax({ url: url, type: "GET", beforeSend: function () { showLoaderScreen(); }, success: function (res) { showPointsOnMap(res); if ( res.data.roadItemsProject == null && res.data.contractSubItems == null && res.data.roadObserved == null && res.data.roadPatrolProject == null ) { $(".excel-happend").attr("disabled", true); } else { $(".excel-happend").attr("disabled", false); } excelParam = param; hideLoaderScreen(); }, error: function (err) { hideLoaderScreen(); Swal.fire({ icon: "error", title: "خطا سرور", text: err.responseJSON.message, showConfirmButton: false, cancelButtonText: "بستن", }); }, }); }); $("#excelEnd").on("click", function () { console.log(excelParam); const url = `/api/axis-report-excel${excelParam != "" ? `?${excelParam}` : "" }`; window.open(url, "_blank"); }); // start show points on map function showPointsOnMap(res) { removeAxisMarker(); roadPatrolProject = res.data.roadPatrolProject; roadObserved = res.data.roadObserved; contractSubItems = res.data.contractSubItems; roadItemsProject = res.data.roadItemsProject; AxisMarkerLayer = L.markerClusterGroup(); if (roadPatrolProject != null) { for (let i = 0; i < roadPatrolProject.length; i++) { setIcon = redIcon; let marker = L.marker( [roadPatrolProject[i].start_lat, roadPatrolProject[i].start_lng], { icon: setIcon, } ).on("click", function (e) { showModalPoints(roadPatrolProject[i].id, 2); }); AxisMarkerList.push(marker); } } if (roadObserved != null) { for (let i = 0; i < roadObserved.length; i++) { setIcon = blueIcon; let marker = L.marker( [roadObserved[i].start_lat, roadObserved[i].start_lng], { icon: setIcon, } ).on("click", function (e) { showModalPoints(roadObserved[i].id, 4); }); AxisMarkerList.push(marker); } } if (roadItemsProject != null) { for (let i = 0; i < roadItemsProject.length; i++) { setIcon = pinkIcon; let marker = L.marker( [roadItemsProject[i].start_lat, roadItemsProject[i].start_lng], { icon: setIcon, } ).on("click", function (e) { showModalPoints(roadItemsProject[i].id, 1); }); AxisMarkerList.push(marker); } } if (contractSubItems != null) { for (let i = 0; i < contractSubItems.length; i++) { setIcon = purpleIcon; let marker = L.marker( [contractSubItems[i].start_lat, contractSubItems[i].start_lng], { icon: setIcon, } ).on("click", function (e) { showModalPoints(contractSubItems[i].id, 3); }); AxisMarkerList.push(marker); } } AxisMarkerLayer.addLayers(AxisMarkerList); mymap.addLayer(AxisMarkerLayer); } // end show points on map // points end // clear map from marker function removeAxisMarker() { if (AxisMarkerLayer != null) { AxisMarkerList = []; mymap.removeLayer(AxisMarkerLayer); } } function showModalPoints(id, type) { $.ajax({ url: "/api/axis-report/single?id=" + id + "&type=" + type, type: "GET", success: function (data) { $("#points-data").modal("show"); completeModalWithData(data, type); }, }); } function completeModalWithData(data, id) { $(".modalBody").empty(); $(".title-points").empty(); var modalBody = ""; switch (id) { case 2: $(".title-points").append("گشت راهداری "); modalBody += `
    `; break; case 1: $(".title-points").append("فعالیت روزانه و جاری "); modalBody += `
    ${showHeaderRoadItem()}${showBodyRoadItem( data.data )}
    عکس 1عکس 2
    `; break; case 4: $(".title-points").append("واکنش سریع"); modalBody += `
    ${fastPhoto( data.data.files )}
    `; break; case 3: $(".title-points").append("قراردادها "); modalBody += `
    ${showHeaderFin( data.data[0].project_type_id )}${showBodyFin( data.data[0].operation, data.data[0].project_type_id )}
    عکس 1عکس 2
    `; break; } $(".modalBody").append(modalBody); } function showHeaderRoadItem(num) { var headertext = ""; headertext = `نوع عملیاتریز فعالیتمقدار واحد `; return headertext; } function fastPhoto(data) { if (data.length > 0) { var tablebody = ` ${showBodyFast(data)}
    عکس 1عکس 2
    `; return tablebody; } else { return ""; } } function showBodyFast(data) { $(".fast-react-td").empty(); var bodycol = ""; for (var i = 0; i < data.length; i++) { bodycol += ``; } return bodycol; } function showHeaderFin(num) { var headertext = ""; if (num == 1) { headertext = `نوع عملیات مقدارواحد پیشرفت تناژ `; } else { headertext = `نوع عملیات مقدارواحد پیشرفت `; } return headertext; } function showBodyRoadItem(data) { var tbody = ""; tbody += `${data.item_fa}${data.sub_item_fa}${data.sub_item_data}${data.unit_fa}`; return tbody; } function showBodyFin(array, num) { var tbody = ""; for (var i = 0; i < array.length; i++) { if (array[i].hasOperation != 0 && num == 1) { if (i + 1 == 1) { tbody += `${array[i].operation_type_fa1}${array[i].operation_type_amount1}${array[i].operation_type_unit1}${array[i].operation_type_progress1}${array[i].operation_type_tonaj1}`; } else if (i + 1 == 2) { tbody += `${array[i].operation_type_fa2}${array[i].operation_type_amount2}${array[i].operation_type_unit2}${array[i].operation_type_progress2}${array[i].operation_type_tonaj2}`; } else if (i + 1 == 3) { tbody += `${array[i].operation_type_fa3}${array[i].operation_type_amount3}${array[i].operation_type_unit3}${array[i].operation_type_progress3}${array[i].operation_type_tonaj3}`; } else if (i + 1 == 4) { tbody += `${array[i].operation_type_fa4}${array[i].operation_type_amount4}${array[i].operation_type_unit4}${array[i].operation_type_progress4}${array[i].operation_type_tonaj4}`; } } else if (array[i].hasOperation != 0 && num != 1) { if (i + 1 == 1) { tbody += `${array[i].operation_type_fa1}${array[i].operation_type_amount1}${array[i].operation_type_unit1}${array[i].operation_type_progress1}`; } else if (i + 1 == 2) { tbody += `${array[i].operation_type_fa2}${array[i].operation_type_amount2}${array[i].operation_type_unit2}${array[i].operation_type_progress2}`; } else if (i + 1 == 3) { tbody += `${array[i].operation_type_fa3}${array[i].operation_type_amount3}${array[i].operation_type_unit3}${array[i].operation_type_progress3}`; } else if (i + 1 == 4) { tbody += `${array[i].operation_type_fa4}${array[i].operation_type_amount4}${array[i].operation_type_unit4}${array[i].operation_type_progress4}`; } } } return tbody; } // UncheckAll function UncheckAll() { var w = document.getElementsByTagName("input"); for (var i = 0; i < w.length; i++) { if (w[i].type == "checkbox") { w[i].checked = false; } } } // routing function routing(lat, lng, latsecond, lngsecond) { if (routeControls.length) { $(routeControls).each(function (index, control) { mymap.removeControl(control); routeControls.splice(routeControls.indexOf(index), 1); }); } routeArray = []; let result = new Promise(function (resolve, reject) { $.get( "https://rmsmap.rmto.ir" + "/route/v1/driving/" + lng + "," + lat + ";" + lngsecond + "," + latsecond + "?overview=full&alternatives=true&steps=true", function (data) { if (data.routes.length > 1) { if ( parseInt(data.routes[0].distance) > parseInt(data.routes[1].distance) ) { resolve(decode(data.routes[1].geometry, 6)); } else { resolve(decode(data.routes[0].geometry, 6)); } } else { resolve(decode(data.routes[0].geometry, 6)); } } ); }); result .then((response) => { hideLoaderScreen(); routeArray = response; }) .catch((error) => { console.log(error); hideLoaderScreen(); }); routeControls.push( L.Routing.control({ routeWhileDragging: true, reverseWaypoints: true, addWaypoints: false, waypoints: [L.latLng(lat, lng), L.latLng(latsecond, lngsecond)], lineOptions: { styles: [ { color: "#28a745", opacity: 1, weight: 5, }, ], }, createMarker: function () { return null; }, }).addTo(mymap) ); showItemSelectionModal(); if ($(".leaflet-routing-container").length) { $(".leaflet-routing-container").remove(); } } function decode(str, precision) { var index = 0, lat = 0, lng = 0, coordinates = [], shift = 0, result = 0, byte = null, latitude_change, longitude_change, factor = Math.pow(10, Number.isInteger(precision) ? precision : 5); while (index < str.length) { byte = null; shift = 0; result = 0; do { byte = str.charCodeAt(index++) - 63; result |= (byte & 0x1f) << shift; shift += 5; } while (byte >= 0x20); latitude_change = result & 1 ? ~(result >> 1) : result >> 1; shift = result = 0; do { byte = str.charCodeAt(index++) - 63; result |= (byte & 0x1f) << shift; shift += 5; } while (byte >= 0x20); longitude_change = result & 1 ? ~(result >> 1) : result >> 1; lat += latitude_change; lng += longitude_change; coordinates.push([lat / factor, lng / factor]); } return coordinates; } // routing