var list_item_api = "/v2/items"; var list_sub_item_api = "/v2/sub_items/"; var add_road_items = "/v2/road_items/operator/store"; var observed_items_api = "/v2/observed_items/"; var search_by_filter_api = "/v2/observed_items?"; var mapZoom = getWidth() < 508 ? 5 : 6; var mapUrl = `https://rmsmap.rmto.ir/141map/`; // base map variables var addMap = null; var startMarkerAdd = null; var endMarkerAdd = null; var isSetStartMarkerAdd = false; var isSetEndMarkerAdd = false; var routeControlsAddMap = []; var addMapFoundItem = null; var startMarkerAddFoundItem = null; var endMarkerAddFoundItem = null; var isSetStartMarkerAddFoundItem = false; var isSetEndMarkerAddFoundItem = false; var routeControlsAddMapFoundItem = []; var markerFoundItem; // var project_distance; // var project_distance_found_item; var project_date; var project_timer; var date_from_filter; var date_to_filter; var FoundItem_project_date; var FoundItem_project_timer; var observed_item_id; var bounds = [ [42.9130026312, 75.6166317076], [20.5782370061, 35.5092252948], ]; var road_items_ditance; // end base map variables // resize func function getWidth() { return Math.max( document.body.scrollWidth, document.documentElement.scrollWidth, document.body.offsetWidth, document.documentElement.offsetWidth, document.documentElement.clientWidth ); } // end resize func // map start and end icon var startDivIcon = L.divIcon({ html: `
شروع
`, iconSize: [55, 75], iconAnchor: [33, 64], }); var endDivIcon = L.divIcon({ html: `
پایان
`, iconSize: [55, 75], iconAnchor: [33, 64], }); var item_icon = L.icon({ iconUrl: "/dist/images/icons/item_location.png", iconSize: [30, 30], iconAnchor: [9, 19], }); var startDivIconFoundItem = L.divIcon({ html: `
شروع
`, iconSize: [55, 75], iconAnchor: [33, 64], }); var endDivIconFoundItem = L.divIcon({ html: `
پایان
`, iconSize: [55, 75], iconAnchor: [33, 64], }); // end map start and end icon // datepicker date_from_filter = $("#road_items_filter_date_from").persianDatepicker({ format: "YYYY/MM/DD", initialValue: false, autoClose: true, initialValueType: "persian", onSelect: function (unix) { date_from_filter.touched = true; if ( date_from_filter.getState().selected.unixDate >= date_to_filter.getState().selected.unixDate ) { date_to_filter.setDate( date_from_filter.getState().selected.unixDate ); } if ( date_to_filter && date_to_filter.options && date_to_filter.options.minDate != unix ) { let cachedValue = date_to_filter.getState().selected.unixDate; date_to_filter.options = { minDate: unix }; if (date_from_filter.touched) { date_to_filter.setDate(cachedValue); } } }, }); date_to_filter = $("#road_items_filter_date_to").persianDatepicker({ format: "YYYY/MM/DD", initialValue: false, autoClose: true, initialValueType: "persian", }); project_date = $("#project_date").persianDatepicker({ format: "YYYY/MM/DD", initialValue: false, autoClose: true, initialValueType: "persian", }); project_timer = $("#project_time").persianDatepicker({ format: "HH:mm", initialValue: false, autoClose: true, initialValueType: "persian", onlyTimePicker: true, timePicker: { enabled: true, step: 1, hour: { enabled: true, step: null }, minute: { enabled: true, step: null }, second: { enabled: false, step: null }, }, }); FoundItem_project_date = $("#FoundItem_project_date").persianDatepicker({ format: "YYYY/MM/DD", initialValue: false, autoClose: true, initialValueType: "persian", }); FoundItem_project_timer = $("#FoundItem_project_time").persianDatepicker({ format: "HH:mm", initialValue: false, autoClose: true, initialValueType: "persian", onlyTimePicker: true, timePicker: { enabled: true, step: 1, hour: { enabled: true, step: null }, minute: { enabled: true, step: null }, second: { enabled: false, step: null }, }, }); // end datepicker // ready $(() => { $("[data-mask]").inputmask(); getWidth() < 508 ? '' : $('[data-toggle="tooltip"]').tooltip(); // get item list $.ajax({ url: list_item_api, type: "GET", beforeSend: function () { showLoaderScreen(); }, success: function (result) { const data = result.data; let content = ``; let selectContent = ``; for (let i = 0; i < data.length; i++) { selectContent += ``; content += `
${data[i].name}
`; } $(".fill-item").append(content); $("#item_id").append(selectContent); hideLoaderScreen(); }, error: function (error) { ajax_error(request.responseJSON, request.status); hideLoaderScreen(); }, }); // end get item list }); // end ready // empty tag checker function isEmpty(el) { return !$.trim(el.html()) } // end empty tag checker // get sub item list function subItemData(status, id) { $.ajax({ url: list_sub_item_api + id, type: "GET", beforeSend: function () { showLoaderScreen(); }, success: function (result) { const data = result.data; if (status == 2) { $(".fill-sub-item").empty(); let content = ``; for (let i = 0; i < data.length; i++) { content += `
${data[i].name}
`; } $(".fill-sub-item").append(content); } else if (status == 1) { $("#FoundItem_sub_item").empty(); $("#FoundItem_sub_item").append(''); $("#FoundItem_sub_item").prop("disabled", false); for (let i = 0; i < data.length; i++) { $("#FoundItem_sub_item").append(``); } $("#FoundItem_sub_item").val($("#accept_item").data("subItemId")); $("#FoundItemData_modal").find(".sub-item-unit").text(`(${$("#FoundItem_sub_item").find("option:selected").data("subUnit")})`) if ($("#FoundItem_sub_item").find("option:selected").data("subImage") == 1) { $("#FoundItemData_modal").find(".upload-box").removeClass("d-none"); } else { $("#FoundItemData_modal").find(".upload-box").addClass("d-none"); } } hideLoaderScreen(); }, error: function (request) { ajax_error(request.responseJSON, request.status); hideLoaderScreen(); }, }); } // end sub item list // uploading file input $(document).on("change", ".img-input", function () { var input = this; var parent = $(input).parents(".img-box"); if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { parent.find(".img-title").css("display", "none"); parent.find(".btn-delete-img").removeAttr("disabled"); parent.find(".img-preview").attr("src", e.target.result); }; reader.readAsDataURL(input.files[0]); } }); $(".btn-delete-img").on("click", function () { var parent = $(this).parents(".img-box"); parent.find(".img-input").val(""); parent.find(".img-preview").removeAttr("src"); parent.find(".img-title").css("display", ""); $(this).attr("disabled", "disabled"); }); // end uploading file input // item choosed $(".item-box").on("click", ".item", function () { $(".item-box").find(".item").removeClass("active-item"); $(this).addClass("active-item"); subItemData(2, $(this).data("itemId")); }); // end item choosed // sub item choosed $(".sub-item-box").on("click", ".item", function () { $(this).addClass("active-item"); const modal = $("#itemData_modal"); if ($(this).data("image") == 1) { modal.find(".upload-box").removeClass("d-none"); } else { modal.find(".upload-box").addClass("d-none"); } const image_box_parent = modal.find(".upload-box"); image_box_parent.find(".img-input").val(""); image_box_parent.find(".img-preview").removeAttr("src"); image_box_parent.find(".img-title").css("display", ""); image_box_parent.find(".btn-delete-img").attr("disabled", "disabled"); modal.find(".clean-input").val(""); modal.find(".value-important").removeClass("invalid").removeClass("valid"); modal.find(".imgbox").removeClass("invalid").removeClass("valid"); $(".sub-item-box").find(".item").removeClass("active-item"); modal.find("#item").val($(".fill-item").find(".item.active-item").data("value")); modal.find("#item").data("itemId", $(".fill-item").find(".item.active-item").data("itemId")); modal.find("#sub_item").val($(this).data("value")); modal.find("#sub_item").data("subItemId", $(this).data("subItemId")); modal.find("#sub_item").data("endPoint", $(this).data("endPoint")); modal.find("#sub_item").data("subImage", $(this).data("image")); modal.find(".sub-item-unit").text(`(${$(this).data("unit")})`); modal.find("#add_coordinates_end").addClass("d-none").removeClass("value-important"); if (addMap == null) { setTimeout(() => { createAddMap(); }, 400); } else { setTimeout(() => { clearAddMap(); }, 400); } modal.modal("show"); }); // all about map [add] // clear add map function clearAddMap() { isSetStartMarkerAdd = false; isSetEndMarkerAdd = false; addMap.removeLayer(startMarkerAdd); if (routeControlsAddMap.length) { $(routeControlsAddMap).each(function (index, control) { addMap.removeControl(control); routeControlsAddMap.splice(routeControlsAddMap.indexOf(index), 1); }); } if (endMarkerAdd != null) { addMap.removeLayer(endMarkerAdd); } addMap.setView([35.7065, 51.3477], mapZoom); setMarkerDefaultAdd(); } // end clear add map // add map functions function createAddMap() { var bounds = [ [42.9130026312, 75.6166317076], [20.5782370061, 35.5092252948], ]; addMap = L.map("add_map", { maxBounds: bounds, minZoom: mapZoom, zoomControl: false, }).setView([35.7065, 51.3477], mapZoom); addMap.addLayer(L.tileLayer(`${mapUrl}{z}/{x}/{y}.png`, { attributionControl: false, })); setMarkerDefaultAdd(); } function setMarkerDefaultAdd() { isSetStartMarkerAdd = false; isSetEndMarkerAdd = false; $("#add-pin-marker-end").removeClass("pin-set"); $("#add-pin-marker-start").removeClass("pin-set"); startMarkerAdd = new L.marker(L.latLng(addMap.getCenter()), { icon: startDivIcon, draggable: true, }).addTo(addMap); endMarkerAdd = new L.marker(L.latLng(addMap.getCenter()), { icon: endDivIcon, draggable: true, }); addMap.on("move", function () { if (!isSetStartMarkerAdd && !isSetEndMarkerAdd) { startMarkerAdd.setLatLng(L.latLng(addMap.getCenter())); $("#add-pin-marker-start").removeClass("pin-set").addClass("pin-move"); } if (isSetStartMarkerAdd && !isSetEndMarkerAdd) { endMarkerAdd.setLatLng(L.latLng(addMap.getCenter())); $("#add-pin-marker-end").removeClass("pin-set").addClass("pin-move"); } }); addMap.on("moveend", function () { if (!isSetStartMarkerAdd && !isSetEndMarkerAdd) { startMarkerAdd.setLatLng(L.latLng(addMap.getCenter())); $("#add-pin-marker-start").removeClass("pin-move pin-set"); } if (isSetStartMarkerAdd && !isSetEndMarkerAdd) { endMarkerAdd.setLatLng(L.latLng(addMap.getCenter())); $("#add-pin-marker-end").removeClass("pin-move pin-set"); } }); startMarkerAdd.on("click", function () { if (addMap.getZoom() >= 14) { if (!isSetStartMarkerAdd) { startMarkerAdd.setLatLng(L.latLng(addMap.getCenter())); endMarkerAdd.setLatLng(L.latLng(addMap.getCenter())); isSetStartMarkerAdd = true; $("#add-pin-marker-start").removeClass("pin-move pin-warn").addClass("pin-set"); } if ($("#itemData_modal").find("#sub_item").data("endPoint") == 1) { $("#add_coordinates_end").removeClass("d-none").addClass("value-important"); endMarkerAdd.setLatLng(startMarkerAdd.getLatLng(), { draggable: true, }).addTo(addMap); addMap.panBy(L.point(10, 10)); } $("#add_coordinates_start").val(startMarkerAdd.getLatLng().lat.toFixed(6) + startMarkerAdd.getLatLng().lng.toFixed(6)); $("#add_coordinates_start").addClass("valid").removeClass("invalid"); $(this).hide(); $("#add-pin-marker-start").removeClass("pin-move pin-warn").addClass("pin-set"); } else { Swal.fire({ icon: "warning", title: "خطا", text: "لطفا زوم نقشه خود را بیشتر کنید", cancelButtonText: "بستن", showConfirmButton: false, showCancelButton: true, }); } }); startMarkerAdd.on("drag", function () { $("#add-pin-marker-start").addClass("pin-move"); }); startMarkerAdd.on("dragend", function () { $("#add-pin-marker-start").removeClass("pin-move"); $("#add_coordinates_start").val(startMarkerAdd.getLatLng().lat.toFixed(6) + startMarkerAdd.getLatLng().lng.toFixed(6)); if ($("#add-pin-marker-start").hasClass("pin-set") || isSetStartMarkerAdd) { $("#add-pin-marker-start").addClass("pin-set"); if ($("#itemData_modal").find("#sub_item").data("endPoint") == 1) { drawPathAddMap() } } else { addMap.setView(startMarkerAdd.getLatLng()); } }); endMarkerAdd.on("click", function () { if (addMap.getZoom() >= 14) { if (!isSetEndMarkerAdd) { isSetEndMarkerAdd = true; $("#add-pin-marker-end").removeClass("pin-move pin-warn").addClass("pin-set"); } $("#add_coordinates_end").addClass("valid").removeClass("invalid"); $("#add_coordinates_end").val(endMarkerAdd.getLatLng().lat.toFixed(6) + endMarkerAdd.getLatLng().lng.toFixed(6)); drawPathAddMap(); } else { Swal.fire({ icon: "warning", title: "خطا", text: "لطفا زوم نقشه خود را بیشتر کنید", cancelButtonText: "بستن", showConfirmButton: false, showCancelButton: true, }); } }); endMarkerAdd.on("drag", function () { $("#add-pin-marker-end").addClass("pin-move"); }); endMarkerAdd.on("dragend", function () { $("#add-pin-marker-end").removeClass("pin-move"); if ($("#add-pin-marker-end").hasClass("pin-set") || isSetEndMarkerAdd) { $("#add-pin-marker-end").addClass("pin-set"); $("#add_coordinates_end").val(endMarkerAdd.getLatLng().lat.toFixed(6) + endMarkerAdd.getLatLng().lng.toFixed(6)); drawPathAddMap(); } else { addMap.setView(endMarkerAdd.getLatLng()); } }); } // end add map functions // draw path function drawPathAddMap() { if (routeControlsAddMap.length) { $(routeControlsAddMap).each(function (index, control) { addMap.removeControl(control); routeControlsAddMap.splice(routeControlsAddMap.indexOf(index), 1); }); } routeControlsAddMap.push( L.Routing.control({ waypoints: [ L.latLng( parseFloat(startMarkerAdd.getLatLng().lat), parseFloat(startMarkerAdd.getLatLng().lng) ), L.latLng( parseFloat(endMarkerAdd.getLatLng().lat), parseFloat(endMarkerAdd.getLatLng().lng) ), ], fitSelectedRoutes: false, draggableWaypoints: true, createMarker: function () { return null; }, lineOptions: { addWaypoints: false, styles: [{ color: "#28a745", opacity: 0.8, weight: 5, },], }, }).on("routesfound", function (e) { // project_distance = parseFloat(e.routes[0].summary.totalDistance / 1000.0).toFixed(2); }).addTo(addMap) ); addMap.flyToBounds([startMarkerAdd.getLatLng(), endMarkerAdd.getLatLng()], { padding: [30, 30], duration: 0.5 }); $(".leaflet-control-container").css("display", "none"); $(".leaflet-routing-container-hide").css("display", "none"); hideLoaderScreen(); } // end draw path // end all about map [add] $("#itemData_modal").on("click", "#send_item_data_cta", function () { const modal = $(this).parents(".modal"); modal.find("input.value-important").each(function () { $(this).val() == "" ? $(this).removeClass("valid").addClass("invalid") : $(this).removeClass("invalid").addClass("valid"); }); modal.find(".upload-box").each(function () { $(this).find(".img-input").get(0).files[0] == undefined ? $(this).find(".imgbox").removeClass("valid").addClass("invalid") : $(this).find(".imgbox").removeClass("invalid").addClass("valid") }); if (modal.find(".upload-box").hasClass("d-none")) { modal.find(".upload-box").find(".imgbox").removeClass("invalid").addClass("valid") } if (!isSetStartMarkerAdd) { $("#add-pin-marker-start").addClass("pin-warn"); Swal.fire({ icon: "warning", title: "خطا", text: "لطفا موقعیت فعالیت را روی نقشه مشخص کنید! (شروع)", cancelButtonText: "بستن", showConfirmButton: false, showCancelButton: true, }); } else { $("#add-pin-marker-start").removeClass("pin-warn") } if ((isSetStartMarkerAdd && !isSetEndMarkerAdd) && modal.find("#sub_item").data("endPoint") == 1) { $("#add-pin-marker-end").addClass("pin-warn"); Swal.fire({ icon: "warning", title: "خطا", text: "لطفا موقعیت فعالیت را روی نقشه مشخص کنید! (پایان)", cancelButtonText: "بستن", showConfirmButton: false, showCancelButton: true, }); } else { $("#add-pin-marker-end").removeClass("pin-warn") } if (modal.find(".invalid").length != 0 || modal.find(".pin-warn").length != 0) { return } else { let formData = new FormData(); const item_id = modal.find("#item").data("itemId"); const sub_item_id = modal.find("#sub_item").data("subItemId"); const amount = modal.find("#item_amount").val(); const before_image = modal.find("#deviceImg1").get(0).files[0]; const after_image = modal.find("#deviceImg2").get(0).files[0]; const activity_date = moment(project_date.getState().selected.unixDate).format("YYYY-MM-DD"); const activity_time = moment(project_timer.getState().selected.unixDate).format("HH:mm"); const start_point = `${startMarkerAdd.getLatLng().lat.toFixed(6)},${startMarkerAdd.getLatLng().lng.toFixed(6)}`; if (isSetEndMarkerAdd) { const end_point = `${endMarkerAdd.getLatLng().lat.toFixed(6)},${endMarkerAdd.getLatLng().lng.toFixed(6)}`; formData.append("end_point", end_point); // formData.append("project_distance", project_distance); } formData.append("item_id", item_id); formData.append("sub_item_id", sub_item_id); formData.append("amount", amount); if (modal.find("#sub_item").data("subImage") == 1) { formData.append("before_image", before_image); formData.append("after_image", after_image); } formData.append("activity_date", activity_date); formData.append("activity_time", activity_time); formData.append("start_point", start_point); $.ajax({ url: add_road_items, type: "POST", headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), }, data: formData, cache: false, contentType: false, processData: false, beforeSend: function () { showLoaderScreen() }, success: function (result) { hideLoaderScreen(); Swal.fire({ icon: "success", title: "فعالیت با موفقیت ثبت شد", showCancelButton: false, confirmButtonColor: "#2d7c23", confirmButtonText: "اتمام عملیات", showLoaderOnConfirm: true, preConfirm: () => { modal.modal("hide"); getSideBarActivity() }, }); }, error: function (request) { hideLoaderScreen(); ajax_error(request.responseJSON, request.status); }, }); } }); $(document).on("click", "#search_item", function () { const modal = $("#searchItem_modal"); modal.find(".clean-input").val(""); modal.find(".clean-select").val(0); modal.find(".value-important").removeClass("invalid").removeClass("valid"); modal.find(".observed-item-data").empty(); modal.find("#accept_item").addClass("d-none"); modal.find("#accept_item").prop("disabled", false); modal.find("#item_unique_id").prop("disabled", true); modal.find("#search").prop("disabled", true); modal.find("input").removeClass("invalid").removeClass("valid"); modal.find("select").removeClass("invalid").removeClass("valid"); modal.modal("show"); }); $(document).on("change", "#item_unique_id", function () { const parent = $(this).parents(".search-box"); parent.find("select.value-important").each(function () { $(this).find("option:selected").val() == 0 ? $(this).removeClass("valid").addClass("invalid") : $(this).removeClass("invalid").addClass("valid"); }); const unique_id = parent.find("#item_unique_id option:selected").val(); if (parent.find(".invalid").length != 0) { return } else { showLoaderScreen(); $.ajax({ url: observed_items_api + unique_id, type: "GET", headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), }, cache: false, contentType: false, processData: false, success: function (result) { $(".observed-item-data").empty(); $("#searchItem_modal").find("#accept_item").data("itemId", result.item_id); $("#searchItem_modal").find("#accept_item").data("itemName", result.item_name); $("#searchItem_modal").find("#accept_item").data("subItemId", result.sub_item_id); let content = ``; content += `

کد یکتای آیتم :

${result.id}


نام آیتم :

${result.item_name}

موضوع مشاهده شده :

${result.sub_item_name}

نام محلی :

${result.local_name}

عرض جغرافیایی طول جغرافیایی
${result.start_lat} ${result.start_lon}
`; $(".observed-item-data").append(content); const filterMap = L.map("map_filter", { maxBounds: bounds, zoomControl: false, attributionControl: false }).setView([35.7065, 51.3477], 10); filterMap.addLayer(L.tileLayer(`${mapUrl}{z}/{x}/{y}.png`)); L.marker([result.start_lat, result.start_lon], { icon: item_icon }).addTo(filterMap); setTimeout(() => { filterMap.flyTo([result.start_lat, result.start_lon], 14, { duration: 0.5 }) }, 500) $("#searchItem_modal").find("#accept_item").removeClass("d-none"); $("#searchItem_modal").find("#accept_item").prop("disabled", false); hideLoaderScreen(); }, error: function (request) { hideLoaderScreen(); ajax_error(request.responseJSON, request.status); }, }); } }); $(document).on("click", "#filter_date", function () { const modal = $("#searchItem_modal"); const parent = $(this).parents(".filter-box"); parent.find("input.least-one-fill").each(function () { $(this).val() == "" ? $(this).removeClass("valid").addClass("invalid") : $(this).removeClass("invalid").addClass("valid"); }); parent.find("select.least-one-fill").each(function () { $(this).find("option:selected").val() == 0 ? $(this).removeClass("valid").addClass("invalid") : $(this).removeClass("invalid").addClass("valid"); }); if (parent.find(".least-one-fill").hasClass("valid")) { parent.find(".least-one-fill").addClass("valid").removeClass("invalid") } if (parent.find("input.date-from-filter").val() != "" && parent.find("input.date-to-filter").val() == "") { parent.find("input.date-to-filter").addClass("invalid").removeClass("valid"); } if (parent.find(".invalid").length != 0) { return } else { let queryParems = []; const date_from = moment(date_from_filter.getState().selected.unixDate).format("YYYY-MM-DD"); const date_to = moment(date_to_filter.getState().selected.unixDate).format("YYYY-MM-DD"); const item_id = $("#item_id").val(); const road_patrol_id = $("#road_patrol_id").val(); if (parent.find("input.date-from-filter").val() != "" && parent.find("input.date-to-filter").val() != "") { queryParems.push(`start_date=${date_from}`); queryParems.push(`end_date=${date_to}`); } if ($("#item_id").find("option:selected").val() != 0) { queryParems.push(`item_id=${item_id}`) } if ($("#road_patrol_id").val() != "") { queryParems.push(`road_patrol_id=${road_patrol_id}`) } showLoaderScreen(); $.ajax({ url: `${search_by_filter_api}${queryParems.join("&")}`, type: "GET", headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), }, cache: false, contentType: false, processData: false, success: function (result) { hideLoaderScreen(); console.log(result); modal.find("#item_unique_id").empty(); modal.find("#item_unique_id").append(''); for (let index = 0; index < result.length; index++) { modal.find("#item_unique_id").append(``); } modal.find("#item_unique_id").prop("disabled", false); modal.find("#search").prop("disabled", false); modal.find(".observed-item-data").empty(); $(".search-box").addClass("active"); }, error: function (request) { hideLoaderScreen(); ajax_error(request.responseJSON, request.status); }, }); } }); $(document).on("click", "#accept_item", function () { const pervModal = $(this).parents(".modal"); const nextModal = $("#FoundItemData_modal"); pervModal.find("input.value-important").each(function () { $(this).val() == "" ? $(this).removeClass("valid").addClass("invalid") : $(this).removeClass("invalid").addClass("valid"); }); pervModal.find("select.value-important").each(function () { $(this).find("option:selected").val() == 0 ? $(this).removeClass("valid").addClass("invalid") : $(this).removeClass("invalid").addClass("valid"); }); if (pervModal.find(".invalid").length != 0 || isEmpty($('.observed-item-data'))) { return } else { Swal.fire({ icon: "warning", title: "آیا از تطابق اطلاعات مشاهده شده اطمینان دارید؟", showCancelButton: true, confirmButtonColor: "#2d7c23", cancelButtonColor: "#971b1b", confirmButtonText: "بله اطمینان دارم", cancelButtonText: "خیر!", showLoaderOnConfirm: true, preConfirm: () => { observed_item_id = null; nextModal.find(".clean-input").val(""); nextModal.find(".clean-select").val(0); const image_box_parent = nextModal.find(".upload-box"); image_box_parent.find(".img-input").val(""); image_box_parent.find(".img-preview").removeAttr("src"); image_box_parent.find(".img-title").css("display", ""); image_box_parent.find(".btn-delete-img").attr("disabled", "disabled"); nextModal.find(".value-important").removeClass("invalid").removeClass("valid"); nextModal.find(".imgbox").removeClass("invalid").removeClass("valid"); const itemId = pervModal.find("#accept_item").data("itemId"); nextModal.find("#FoundItem_item").data("itemId", pervModal.find("#accept_item").data("itemId")); nextModal.find("#FoundItem_item").val(pervModal.find("#accept_item").data("itemName")); nextModal.find("#add_coordinates_end_found_item").addClass("d-none") observed_item_id = pervModal.find("#item_unique_id").val(); subItemData(1, itemId); pervModal.modal("hide"); setTimeout(() => { nextModal.modal("show"); if (addMapFoundItem == null) { setTimeout(() => { createAddMapFoundItem(); }, 400); } else { setTimeout(() => { clearAddMapFoundItem(); }, 400); } }, 500) }, }); } }); // all about map [add] // clear add map function clearAddMapFoundItem() { isSetStartMarkerAddFoundItem = false; isSetEndMarkerAddFoundItem = false; addMapFoundItem.removeLayer(startMarkerAddFoundItem); if (routeControlsAddMapFoundItem.length) { $(routeControlsAddMapFoundItem).each(function (index, control) { addMapFoundItem.removeControl(control); routeControlsAddMapFoundItem.splice(routeControlsAddMapFoundItem.indexOf(index), 1); }); } if (endMarkerAddFoundItem != null) { addMapFoundItem.removeLayer(endMarkerAddFoundItem); } addMapFoundItem.removeLayer(markerFoundItem); addMapFoundItem.setView([35.7065, 51.3477], mapZoom); setMarkerDefaultAddFoundItem(); } // end clear add map // add map functions function createAddMapFoundItem() { var bounds = [ [42.9130026312, 75.6166317076], [20.5782370061, 35.5092252948], ]; addMapFoundItem = L.map("FoundItem_add_map", { maxBounds: bounds, minZoom: 6, zoomControl: false, }).setView([35.7065, 51.3477], 10); addMapFoundItem.addLayer(L.tileLayer(`${mapUrl}{z}/{x}/{y}.png`, { attributionControl: false })); setMarkerDefaultAddFoundItem(); } function setMarkerDefaultAddFoundItem() { isSetStartMarkerAddFoundItem = false; isSetEndMarkerAddFoundItem = false; markerFoundItem = L.marker([$("#searchItem_modal").find("#item_lat_found").data("itemLat"), $("#searchItem_modal").find("#item_lon_found").data("itemLon")], { icon: item_icon }).addTo(addMapFoundItem); setTimeout(() => { addMapFoundItem.flyTo([$("#searchItem_modal").find("#item_lat_found").data("itemLat"), $("#searchItem_modal").find("#item_lon_found").data("itemLon")], 14, { duration: 0.5 }) }, 500) $("#add-pin-marker-end-found-item").removeClass("pin-set"); $("#add-pin-marker-start-found-item").removeClass("pin-set"); startMarkerAddFoundItem = new L.marker(L.latLng(addMapFoundItem.getCenter()), { icon: startDivIconFoundItem, draggable: true, }).addTo(addMapFoundItem); endMarkerAddFoundItem = new L.marker(L.latLng(addMapFoundItem.getCenter()), { icon: endDivIconFoundItem, draggable: true, }); addMapFoundItem.on("move", function () { if (!isSetStartMarkerAddFoundItem && !isSetEndMarkerAddFoundItem) { startMarkerAddFoundItem.setLatLng(L.latLng(addMapFoundItem.getCenter())); $("#add-pin-marker-start-found-item").removeClass("pin-set").addClass("pin-move"); } if (isSetStartMarkerAddFoundItem && !isSetEndMarkerAddFoundItem) { endMarkerAddFoundItem.setLatLng(L.latLng(addMapFoundItem.getCenter())); $("#add-pin-marker-end-found-item").removeClass("pin-set").addClass("pin-move"); } }); addMapFoundItem.on("moveend", function () { if (!isSetStartMarkerAddFoundItem && !isSetEndMarkerAddFoundItem) { startMarkerAddFoundItem.setLatLng(L.latLng(addMapFoundItem.getCenter())); $("#add-pin-marker-start-found-item").removeClass("pin-move pin-set"); } if (isSetStartMarkerAddFoundItem && !isSetEndMarkerAddFoundItem) { endMarkerAddFoundItem.setLatLng(L.latLng(addMapFoundItem.getCenter())); $("#add-pin-marker-end-found-item").removeClass("pin-move pin-set"); } }); startMarkerAddFoundItem.on("click", function () { if (addMapFoundItem.getZoom() >= 14) { if (!isSetStartMarkerAddFoundItem) { startMarkerAddFoundItem.setLatLng(L.latLng(addMapFoundItem.getCenter())); endMarkerAddFoundItem.setLatLng(L.latLng(addMapFoundItem.getCenter())); isSetStartMarkerAddFoundItem = true; $("#add-pin-marker-start-found-item").removeClass("pin-move pin-warn").addClass("pin-set"); } if ($("#FoundItemData_modal").find("#FoundItem_sub_item option:selected").data("subEndpoint") == 1) { $("#add_coordinates_end_found_item").removeClass("d-none").addClass("value-important"); endMarkerAddFoundItem.setLatLng(startMarkerAddFoundItem.getLatLng(), { draggable: true, }).addTo(addMapFoundItem); addMapFoundItem.panBy(L.point(10, 10)); } $("#add_coordinates_start_found_item").val(startMarkerAddFoundItem.getLatLng().lat.toFixed(6) + startMarkerAddFoundItem.getLatLng().lng.toFixed(6)); $("#add_coordinates_start_found_item").addClass("valid").removeClass("invalid"); $(this).hide(); $("#add-pin-marker-start-found-item").removeClass("pin-move pin-warn").addClass("pin-set"); } else { Swal.fire({ icon: "warning", title: "خطا", text: "لطفا زوم نقشه خود را بیشتر کنید", cancelButtonText: "بستن", showConfirmButton: false, showCancelButton: true, }); } }); startMarkerAddFoundItem.on("drag", function () { $("#add-pin-marker-start-found-item").addClass("pin-move"); }); startMarkerAddFoundItem.on("dragend", function () { $("#add-pin-marker-start-found-item").removeClass("pin-move"); $("#add_coordinates_start_found_item").val(startMarkerAddFoundItem.getLatLng().lat.toFixed(6) + startMarkerAddFoundItem.getLatLng().lng.toFixed(6)); if ($("#add-pin-marker-start-found-item").hasClass("pin-set") || isSetStartMarkerAddFoundItem) { if ($("#FoundItem_sub_item").find("option:selected").data("subEndpoint") == 0) { isSetEndMarkerAddFoundItem = false; addMapFoundItem.removeLayer(endMarkerAddFoundItem); $("#add_coordinates_end_found_item").addClass("d-none").removeClass("value-important"); if (routeControlsAddMapFoundItem.length) { $(routeControlsAddMapFoundItem).each(function (index, control) { addMapFoundItem.removeControl(control); routeControlsAddMapFoundItem.splice(routeControlsAddMapFoundItem.indexOf(index), 1); }); } } else { drawPathAddMapFoundItem() } $("#add-pin-marker-start-found-item").addClass("pin-set"); } else { addMapFoundItem.setView(startMarkerAddFoundItem.getLatLng()); } }); endMarkerAddFoundItem.on("click", function () { if (addMapFoundItem.getZoom() >= 14) { if (!isSetEndMarkerAddFoundItem) { isSetEndMarkerAddFoundItem = true; $("#add-pin-marker-end-found-item").removeClass("pin-move pin-warn").addClass("pin-set"); } $("#add_coordinates_end_found_item").val(endMarkerAddFoundItem.getLatLng().lat.toFixed(6) + endMarkerAddFoundItem.getLatLng().lng.toFixed(6)); $("#add_coordinates_end_found_item").addClass("valid").removeClass("invalid"); drawPathAddMapFoundItem(); } else { Swal.fire({ icon: "warning", title: "خطا", text: "لطفا زوم نقشه خود را بیشتر کنید", cancelButtonText: "بستن", showConfirmButton: false, showCancelButton: true, }); } }); endMarkerAddFoundItem.on("drag", function () { $("#add-pin-marker-end-found-item").addClass("pin-move"); }); endMarkerAddFoundItem.on("dragend", function () { $("#add-pin-marker-end-found-item").removeClass("pin-move"); if ($("#add-pin-marker-end-found-item").hasClass("pin-set") || isSetEndMarkerAddFoundItem) { $("#add-pin-marker-end-found-item").addClass("pin-set"); $("#add_coordinates_end_found_item").val(endMarkerAddFoundItem.getLatLng().lat.toFixed(6) + endMarkerAddFoundItem.getLatLng().lng.toFixed(6)); drawPathAddMapFoundItem(); } else { addMapFoundItem.setView(endMarkerAddFoundItem.getLatLng()); } }); } // end add map functions // draw path function drawPathAddMapFoundItem() { if (routeControlsAddMapFoundItem.length) { $(routeControlsAddMapFoundItem).each(function (index, control) { addMapFoundItem.removeControl(control); routeControlsAddMapFoundItem.splice(routeControlsAddMapFoundItem.indexOf(index), 1); }); } routeControlsAddMapFoundItem.push( L.Routing.control({ waypoints: [ L.latLng( parseFloat(startMarkerAddFoundItem.getLatLng().lat), parseFloat(startMarkerAddFoundItem.getLatLng().lng) ), L.latLng( parseFloat(endMarkerAddFoundItem.getLatLng().lat), parseFloat(endMarkerAddFoundItem.getLatLng().lng) ), ], fitSelectedRoutes: false, draggableWaypoints: true, createMarker: function () { return null; }, lineOptions: { addWaypoints: false, styles: [{ color: "#28a745", opacity: 0.8, weight: 5, },], }, }).on("routesfound", function (e) { // project_distance_found_item = parseFloat(e.routes[0].summary.totalDistance / 1000.0).toFixed(2); }).addTo(addMapFoundItem) ); addMapFoundItem.flyToBounds([startMarkerAddFoundItem.getLatLng(), endMarkerAddFoundItem.getLatLng()], { padding: [20, 20], duration: 0.5 }); $(".leaflet-control-container").css("display", "none"); $(".leaflet-routing-container-hide").css("display", "none"); hideLoaderScreen(); } // end draw path // end all about map [add] $(document).on("click", "#FoundItem_send_item_data_cta", function () { const modal = $(this).parents(".modal"); modal.find("input.value-important").each(function () { $(this).val() == "" ? $(this).removeClass("valid").addClass("invalid") : $(this).removeClass("invalid").addClass("valid"); }); modal.find(".upload-box").each(function () { $(this).find(".img-input").get(0).files[0] == undefined ? $(this).find(".imgbox").removeClass("valid").addClass("invalid") : $(this).find(".imgbox").removeClass("invalid").addClass("valid") }); modal.find("select.value-important").each(function () { $(this).find("option:selected").val() == 0 ? $(this).removeClass("valid").addClass("invalid") : $(this).removeClass("invalid").addClass("valid"); }); if (modal.find(".upload-box").hasClass("d-none")) { modal.find(".upload-box").find(".imgbox").removeClass("invalid").addClass("valid") } if (!isSetStartMarkerAddFoundItem) { $("#add-pin-marker-start-found-item").addClass("pin-warn"); Swal.fire({ icon: "warning", title: "خطا", text: "لطفا موقعیت فعالیت را روی نقشه مشخص کنید! (شروع)", cancelButtonText: "بستن", showConfirmButton: false, showCancelButton: true, }); } else { $("#add-pin-marker-start-found-item").removeClass("pin-warn") } if ((isSetStartMarkerAddFoundItem && !isSetEndMarkerAddFoundItem) && modal.find("#FoundItem_sub_item option:selected").data("subEndpoint") == 1) { $("#add-pin-marker-end-found-item").addClass("pin-warn"); Swal.fire({ icon: "warning", title: "خطا", text: "لطفا موقعیت فعالیت را روی نقشه مشخص کنید! (پایان)", cancelButtonText: "بستن", showConfirmButton: false, showCancelButton: true, }); } else { $("#add-pin-marker-end-found-item").removeClass("pin-warn") } if (modal.find(".invalid").length != 0 || modal.find(".pin-warn").length != 0) { return } else { let formData = new FormData(); const item_id = modal.find("#FoundItem_item").data("itemId"); const sub_item_id = modal.find("#FoundItem_sub_item option:selected").val(); const amount = modal.find("#FoundItem_item_amount").val(); const activity_date = moment(FoundItem_project_date.getState().selected.unixDate).format("YYYY-MM-DD"); const activity_time = moment(FoundItem_project_timer.getState().selected.unixDate).format("HH:mm"); const start_point = `${startMarkerAddFoundItem.getLatLng().lat.toFixed(6)},${startMarkerAddFoundItem.getLatLng().lng.toFixed(6)}`; if (modal.find("#FoundItem_sub_item option:selected").data("subImage") == 1) { const before_image = modal.find("#FoundItem_deviceImg1").get(0).files[0]; const after_image = modal.find("#FoundItem_deviceImg2").get(0).files[0]; formData.append("before_image", before_image); formData.append("after_image", after_image); } formData.append("start_point", start_point); if (isSetEndMarkerAddFoundItem) { const end_point = `${endMarkerAddFoundItem.getLatLng().lat.toFixed(6)},${endMarkerAddFoundItem.getLatLng().lng.toFixed(6)}`; formData.append("end_point", end_point); // formData.append("project_distance", project_distance_found_item); } formData.append("item_id", item_id); formData.append("sub_item_id", sub_item_id); formData.append("amount", amount); formData.append("activity_date", activity_date); formData.append("activity_time", activity_time); formData.append("observed_item_id", observed_item_id); $.ajax({ url: add_road_items, type: "POST", headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), }, data: formData, cache: false, contentType: false, processData: false, beforeSend: function () { showLoaderScreen() }, success: function (result) { hideLoaderScreen(); Swal.fire({ icon: "success", title: "فعالیت با موفقیت ثبت شد", showCancelButton: false, confirmButtonColor: "#2d7c23", confirmButtonText: "اتمام عملیات", showLoaderOnConfirm: true, preConfirm: () => { modal.modal("hide"); getSideBarActivity() }, }); }, error: function (request) { hideLoaderScreen(); ajax_error(request.responseJSON, request.status); }, }); } }); $("#FoundItemData_modal").on("change", "#FoundItem_sub_item", function () { const parent = $(this).parents(".modal"); parent.find(".sub-item-unit").text(`(${$(this).find("option:selected").data("subUnit")})`); if ($(this).find("option:selected").data("subImage") == 1) { parent.find(".upload-box").removeClass("d-none"); } else { parent.find(".upload-box").addClass("d-none"); } if (isSetStartMarkerAddFoundItem) { if ($(this).find("option:selected").data("subEndpoint") == 1) { isSetEndMarkerAddFoundItem = false; $("#add_coordinates_end_found_item").removeClass("d-none").addClass("value-important"); addMapFoundItem.flyTo(startMarkerAddFoundItem.getLatLng(), 15); if (routeControlsAddMapFoundItem.length) { $(routeControlsAddMapFoundItem).each(function (index, control) { addMapFoundItem.removeControl(control); routeControlsAddMapFoundItem.splice(routeControlsAddMapFoundItem.indexOf(index), 1); }); } parent.find("#add_coordinates_end_found_item").removeClass("d-none").addClass("value-important"); endMarkerAddFoundItem.setLatLng(startMarkerAddFoundItem.getLatLng(), { draggable: true, }).addTo(addMapFoundItem); $("#add-pin-marker-end-found-item").removeClass("pin-set"); } else { isSetEndMarkerAddFoundItem = false; if (routeControlsAddMapFoundItem.length) { $(routeControlsAddMapFoundItem).each(function (index, control) { addMapFoundItem.removeControl(control); routeControlsAddMapFoundItem.splice(routeControlsAddMapFoundItem.indexOf(index), 1); }); } parent.find("#add_coordinates_end_found_item").addClass("d-none").removeClass("value-important"); addMapFoundItem.removeLayer(endMarkerAddFoundItem); } } else { addMapFoundItem.removeLayer(endMarkerAddFoundItem); } }); // coordinate manually [add] $("#itemData_modal").on("keyup", "#add_coordinates_start", function () { checkStartMarkerValidation(); }); $("#itemData_modal").on("keyup", "#add_coordinates_end", function () { checkEndMarkerValidation(); }); //// start coordinate function checkStartMarkerValidation(forSaveData = false, pageOnLoad = false) { let reg = /^([0-9]){2}\.([0-9])+$/; let startLatLngVal = $("#itemData_modal #add_coordinates_start").val().split(" - "); let startLatLng = startLatLngVal.map(function (e) { e = e.replace(/_/g, ""); return parseFloat(e.slice(1, -1)) }); if (isNaN(startLatLng[0])) { if (routeControlsAddMap.length) { $(routeControlsAddMap).each(function (index, control) { addMap.removeControl(control); routeControlsAddMap.splice(routeControlsAddMap.indexOf(index), 1); }); } if (!forSaveData) { $("#itemData_modal #add_coordinates_start").removeClass("invalid").addClass("valid"); } else { $("#itemData_modal #add_coordinates_start").addClass("invalid").removeClass("valid"); } $("#add-pin-marker-start").removeClass("pin-move pin-set"); $("#itemData_modal #add_coordinates_start").val(""); $("#itemData_modal #add_coordinates_start").attr("placeholder", "(عرض جغرافیایی) - (طول جغرافیایی)"); return false; } else if (!startLatLng == 2 || !reg.test(startLatLng[0]) || !reg.test(startLatLng[1])) { $("#itemData_modal #add_coordinates_start").addClass("invalid").removeClass("valid"); $("#add-pin-marker-start").removeClass("pin-move pin-set"); return false; } else { if (!forSaveData) { $("#itemData_modal #add_coordinates_start").removeClass("invalid").addClass("valid"); startMarkerAdd.setLatLng(startLatLng); if (pageOnLoad) { setTimeout(() => { $("#add-pin-marker-start").removeClass("pin-move").addClass("pin-set"); startMarkerAdd.setLatLng(startLatLng); }, 10); } else { $("#add-pin-marker-start").removeClass("pin-move").addClass("pin-set"); } if (!isSetEndMarkerAdd && $("#itemData_modal").find("#sub_item").data("endPoint") == 1) { $("#add_coordinates_end").removeClass("d-none").addClass("value-important"); let markerLatLng = [startMarkerAdd.getLatLng().lat, startMarkerAdd.getLatLng().lng + 0.0008]; addMap.setView(markerLatLng); endMarkerAdd.setLatLng(markerLatLng); if (!isSetStartMarkerAdd) { endMarkerAdd.addTo(addMap); } } isSetStartMarkerAdd = true; } checkMarkersAndDrawPath(); return true; } } //// end start coordinate //// end coordinate function checkEndMarkerValidation(forSaveData = false, pageOnLoad = false) { let reg = /^([0-9]){2}\.([0-9])+$/; let endLatLngVal = $("#itemData_modal #add_coordinates_end").val().split(" - "); let endLatLng = endLatLngVal.map(function (e) { e = e.replace(/_/g, ""); return parseFloat(e.slice(1, -1)) }); if (isNaN(endLatLng[0])) { if (routeControlsAddMap.length) { $(routeControlsAddMap).each(function (index, control) { addMap.removeControl(control); routeControlsAddMap.splice(routeControlsAddMap.indexOf(index), 1); }); } if (!forSaveData) { $("#itemData_modal #add_coordinates_end").removeClass("invalid").addClass("valid"); } else { $("#itemData_modal #add_coordinates_end").addClass("invalid").removeClass("valid"); } $("#add-pin-marker-end").removeClass("pin-move pin-set"); $("#itemData_modal #add_coordinates_end").val(""); $("#itemData_modal #add_coordinates_end").attr("placeholder", "(عرض جغرافیایی) - (طول جغرافیایی)"); return false; } else if (!endLatLng == 2 || !reg.test(endLatLng[0]) || !reg.test(endLatLng[1])) { $("#itemData_modal #add_coordinates_end").addClass("invalid").removeClass("valid"); $("#add-pin-marker-end").removeClass("pin-move pin-set"); return false; } else { if (!forSaveData) { $("#itemData_modal #add_coordinates_end").removeClass("invalid").addClass("valid"); endMarkerAdd.setLatLng(endLatLng); isSetEndMarkerAdd = true; if (pageOnLoad) { setTimeout(() => { $("#add-pin-marker-end").removeClass("pin-move").addClass("pin-set"); endMarkerAdd.setLatLng(endLatLng); }, 10); } else { $("#add-pin-marker-end").removeClass("pin-move").addClass("pin-set"); } } checkMarkersAndDrawPath(); return true; } } //// end end coordinate //// check markers function checkMarkersAndDrawPath() { if ( $("#add-pin-marker-start").hasClass("pin-set") && !$("#add-pin-marker-start").hasClass("pin-move") && $("#add-pin-marker-end").hasClass("pin-set") && !$("#add-pin-marker-end").hasClass("pin-move") ) { drawPathAddMap(); } } //// end check markers // end coordinate manually // coordinate manually [found add] $("#FoundItemData_modal").on("keyup", "#add_coordinates_start_found_item", function () { checkStartMarkerValidationFound(); }); $("#FoundItemData_modal").on("keyup", "#add_coordinates_end_found_item", function () { checkEndMarkerValidationFound(); }); //// start coordinate function checkStartMarkerValidationFound(forSaveData = false, pageOnLoad = false) { let reg = /^([0-9]){2}\.([0-9])+$/; let startLatLngVal = $("#FoundItemData_modal #add_coordinates_start_found_item").val().split(" - "); let startLatLng = startLatLngVal.map(function (e) { e = e.replace(/_/g, ""); return parseFloat(e.slice(1, -1)) }); if (isNaN(startLatLng[0])) { if (routeControlsAddMapFoundItem.length) { $(routeControlsAddMapFoundItem).each(function (index, control) { addMapFoundItem.removeControl(control); routeControlsAddMapFoundItem.splice(routeControlsAddMapFoundItem.indexOf(index), 1); }); } if (!forSaveData) { $("#FoundItemData_modal #add_coordinates_start_found_item").removeClass("invalid").addClass("valid"); } else { $("#FoundItemData_modal #add_coordinates_start_found_item").addClass("invalid").removeClass("valid"); } $("#add-pin-marker-start-found-item").removeClass("pin-move pin-set"); $("#FoundItemData_modal #add_coordinates_start_found_item").val(""); $("#FoundItemData_modal #add_coordinates_start_found_item").attr("placeholder", "(عرض جغرافیایی) - (طول جغرافیایی)"); return false; } else if (!startLatLng == 2 || !reg.test(startLatLng[0]) || !reg.test(startLatLng[1])) { $("#FoundItemData_modal #add_coordinates_start_found_item").addClass("invalid").removeClass("valid"); $("#add-pin-marker-start-found-item").removeClass("pin-move pin-set"); return false; } else { if (!forSaveData) { $("#FoundItemData_modal #add_coordinates_start_found_item").removeClass("invalid").addClass("valid"); startMarkerAddFoundItem.setLatLng(startLatLng); if (pageOnLoad) { setTimeout(() => { $("#add-pin-marker-start-found-item").removeClass("pin-move").addClass("pin-set"); startMarkerAddFoundItem.setLatLng(startLatLng); }, 10); } else { $("#add-pin-marker-start-found-item").removeClass("pin-move").addClass("pin-set"); } if (!isSetEndMarkerAddFoundItem && $("#FoundItemData_modal").find("#FoundItem_sub_item option:selected").data("subEndpoint") == 1) { $("#add_coordinates_end_found_item").removeClass("d-none").addClass("value-important"); let markerLatLng = [startMarkerAddFoundItem.getLatLng().lat, startMarkerAddFoundItem.getLatLng().lng + 0.0008]; addMapFoundItem.setView(markerLatLng); endMarkerAddFoundItem.setLatLng(markerLatLng); if (!isSetStartMarkerAddFoundItem) { endMarkerAddFoundItem.addTo(addMapFoundItem); } } isSetStartMarkerAddFoundItem = true; } checkMarkersAndDrawPathFound(); return true; } } //// end start coordinate //// end coordinate function checkEndMarkerValidationFound(forSaveData = false, pageOnLoad = false) { let reg = /^([0-9]){2}\.([0-9])+$/; let endLatLngVal = $("#FoundItemData_modal #add_coordinates_end_found_item").val().split(" - "); let endLatLng = endLatLngVal.map(function (e) { e = e.replace(/_/g, ""); return parseFloat(e.slice(1, -1)) }); if (isNaN(endLatLng[0])) { if (routeControlsAddMapFoundItem.length) { $(routeControlsAddMapFoundItem).each(function (index, control) { addMapFoundItem.removeControl(control); routeControlsAddMapFoundItem.splice(routeControlsAddMapFoundItem.indexOf(index), 1); }); } if (!forSaveData) { $("#FoundItemData_modal #add_coordinates_end_found_item").removeClass("invalid").addClass("valid"); } else { $("#FoundItemData_modal #add_coordinates_end_found_item").addClass("invalid").removeClass("valid"); } $("#add-pin-marker-end-found-item").removeClass("pin-move pin-set"); $("#FoundItemData_modal #add_coordinates_end_found_item").val(""); $("#FoundItemData_modal #add_coordinates_end_found_item").attr("placeholder", "(عرض جغرافیایی) - (طول جغرافیایی)"); return false; } else if (!endLatLng == 2 || !reg.test(endLatLng[0]) || !reg.test(endLatLng[1])) { $("#FoundItemData_modal #add_coordinates_end_found_item").addClass("invalid").removeClass("valid"); $("#add-pin-marker-end-found-item").removeClass("pin-move pin-set"); return false; } else { if (!forSaveData) { $("#FoundItemData_modal #add_coordinates_end_found_item").removeClass("invalid").addClass("valid"); endMarkerAddFoundItem.setLatLng(endLatLng); isSetEndMarkerAddFoundItem = true; if (pageOnLoad) { setTimeout(() => { $("#add-pin-marker-end-found-item").removeClass("pin-move").addClass("pin-set"); endMarkerAddFoundItem.setLatLng(endLatLng); }, 10); } else { $("#add-pin-marker-end-found-item").removeClass("pin-move").addClass("pin-set"); } } checkMarkersAndDrawPathFound(); return true; } } //// end end coordinate //// check markers function checkMarkersAndDrawPathFound() { if ( $("#add-pin-marker-start-found-item").hasClass("pin-set") && !$("#add-pin-marker-start-found-item").hasClass("pin-move") && $("#add-pin-marker-end-found-item").hasClass("pin-set") && !$("#add-pin-marker-end-found-item").hasClass("pin-move") ) { drawPathAddMapFoundItem(); } } //// end check markers // end coordinate manually