$(document).ready(function () { /* * Mapping Variable Declarations */ var map; var ft_to_m = 3.28084; var yd_to_m = 1.09361; // Location position var originalLat = $("#locationLat").val(); var originalLng = $("#locationLng").val(); var originalPosition = new google.maps.LatLng(originalLat, originalLng); // Default Options var defaultOptions = { zoom: 18, minZoom: 15, panControl: false, streetViewControl: false, mapTypeControl: false, rotateControl: true, mapTypeId: google.maps.MapTypeId.SATELLITE, rotateControlOptions: { position: google.maps.ControlPosition.LEFT_CENTER }, zoomControlOptions: { position: google.maps.ControlPosition.LEFT_CENTER }, tilt: 0, gestureHandling: 'greedy', fullscreenControl: false }; //Markers var markers = {}; var markerCounter = 0; var markerZindex = 500; var currentMarker; var goBackPosition; var triggeredMarker; //polygons var polygons = {}; var polygonCounter = 0; var polygonZindex = 100; var currentPolygon; var newPolygonMarkers = []; var newPolygon; var newPolyOptions = { strokeColor: '#F00', strokeOpacity: 1.0, strokeWeight: 1 }; var lines = {}; var lineCounter = 0; var newLine; var currentLine; var newLineOptions = { strokeColor: '#F00', strokeOpacity: 1.0, strokeWeight: 1 }; //other stuff var jsonData = {}; var infoWindow = new google.maps.InfoWindow({ content: 'Content Undefined', maxWidth: '600', zIndex: 300 }); var drawingMode = 0; var markerIcon = { url: "", size: new google.maps.Size(32, 32), origin: new google.maps.Point(0, 0), anchor: new google.maps.Point(16, 16), scaledSize: new google.maps.Size(24, 24) }; var positionIcon = { url: "http://prositeaudit.com/manmap.png", size: new google.maps.Size(32, 32), origin: new google.maps.Point(0, 0), anchor: new google.maps.Point(16, 16), scaledSize: new google.maps.Size(24, 24) }; var markerIcon_small = { url: "", size: new google.maps.Size(32, 32), origin: new google.maps.Point(0, 0), anchor: new google.maps.Point(8, 8), scaledSize: new google.maps.Size(16, 16) }; var type; var score; var imagePath = '/uploads/reviews/' + companyId + '/' + assessmentId + '/'; var helperPolygon; var showTutorial = 1; var firstMarker = 0; var firstPolygonMarker; var newPolygonCornerCounter = 0; var newZoneTypeId = $("#defaultZoneTypeId").val(); var mouseHandler = null; // an handler to move infowindow --> by preeti var reportlastPosition = null; var newLineTypeId; var firstLineMarker; var firstLine; var newLineCornerCounter = 0; // flag for new or existing marker when using mobile interface var newMarker = true; // flag for new or existing zone when using mobile interface var newZone = true; // flag for new or existing line when using mobile interface var newLineFlag = true; // Flag for first load var firstLoad = true; /* Change the default to be the first zone type */ for (var a in zoneTypes) break; newZoneTypeId = a; function isMobile() { if ($("#mobileDetector").is(':visible')) { return true; } return false; } function isTabletOrSmaller() { if($("#tabletDetector").is(":visible")) { return true; } return false; } /* * General Mapping functions * */ $(".markerOptions").hide(); /**************************** * Marker Functions & Stuff * ****************************/ function addMarker(markerInfo, reportMarker, noUpdate) { markerCounter++; var icon = markerInfo.icon; originalIcon = icon['url']; icon['url'] = '/icon/' + addMarkerNumber(markerInfo.markerTypeId, markerCounter); var id = null; if (typeof(markerInfo.id) != 'undefined') { id = markerInfo.id; } var showIssue = true; if (reportFilter) { var markerTypeId = markerInfo.markerTypeId; if (filteredIssues.indexOf(markerTypeId) < 0) { showIssue = false; } } smallIcon = markerIcon_small; smallIcon['url'] = icon['url']; var markerOptions = { map: showIssue ? map : null, draggable: true, crossOnDrag: false, animation: null, raiseOnDrag: false, markerID: markerCounter, title: 'Issue #' + markerCounter, position: markerInfo.position, icon: icon, id: id, markerType: markerInfo.markerType, markerTypeId: markerInfo.markerTypeId, markerDescription: markerInfo.description, severity: markerInfo.severity, image1: (markerInfo.image1) ? markerInfo.image1 : '', image2: (markerInfo.image2) ? markerInfo.image2 : '', zIndex: (markerZindex + markerCounter), originalIcon: originalIcon, saved: markerInfo.saved }; markers[markerCounter] = new google.maps.Marker(markerOptions); if (!reportMarker) { google.maps.event.addListener(markers[markerCounter], 'click', function () { loadMarkerWindow(this.markerID, this); }); google.maps.event.addListener(markers[markerCounter], 'dragend', function () { this.saved = false; if (this.poppedUp !== true) { // Load the info window var windowOpen = ($("#mapInfoWindow" + this.markerID).length); // get the infowindow if already clicked if (windowOpen) { } else { var marker = this; var markerID = this.markerID; setTimeout(function () { loadMarkerWindow(markerID, marker); // open infowindow on 1st time dragend. }, 200); } this.poppedUp = true; } else { this.saved = false; syncMapData(); } }); // if (typeof noUpdate == 'undefined') { updateIssuesTable(); } } else { google.maps.event.addListener(markers[markerCounter], 'dragstart', function () { reportlastPosition = this.getPosition(); }); google.maps.event.addListener(markers[markerCounter], 'dragend', function () { this.setPosition(reportlastPosition); }); google.maps.event.addListener(markers[markerCounter], 'click', function () { loadReportMarkerWindow(this.markerID); }); } } function updateMarkerCounter() { var counter = 0; for (i in markers) { counter++; markers[i].markerCounter = counter; // If we've delete an earlier one, we need to shift the position in the array if (markers[i].markerCounter !== markers[i].markerID) { markers[counter] = markers[i]; markers[counter].markerID = counter; delete markers[i]; } else { var icon = markers[i].getIcon(); icon['url'] = addMarkerNumber(markers[i].originalIcon, counter); var smallIcon = markerIcon_small; smallIcon['url'] = icon['url']; markers[i].setIcon(icon); markers[i].setTitle('Issue #' + counter); } } markerCounter = counter; } function issueCount() { var numMarkers = Object.keys(markers).length; var numZones = Object.keys(polygons).length; var numLines = Object.keys(lines).length; return numMarkers + numZones + numLines; } /*Remove Marker*/ function removeMarker(removeMarkerId) { var marker = markers[removeMarkerId]; if (markers[removeMarkerId].id != null) { $.ajax({ url: '/audit/deleteIssue/' + markers[removeMarkerId].id, method: 'get' }) .done(function (response) { marker.setMap(null); $("#marker-" + marker.markerID).fadeOut(300, function () { $(this).remove(); }); $("#marker-card-" + marker.markerID).fadeOut(300, function () { $(this).remove(); }); delete markers[removeMarkerId]; updateMarkerCounter(); hideInfoWindowToolbar(); updateIssuesTable(); }) .error(function() { bootbox.alert('There was an error deleting the issue'); }); } else { marker.setMap(null); delete markers[removeMarkerId]; updateMarkerCounter(); hideInfoWindowToolbar(); updateIssuesTable(); } } function loadMobileZoneScreen(polygon) { var zoneLetter = String.fromCharCode(64 + polygon.polygonID); var zoneTypeId = polygon.typeId; var zoneTypeName = zoneTypes[zoneTypeId]; var infoColor = zoneColors[zoneTypeId][0]; var infoTextColor = zoneColors[zoneTypeId][2]; $('div.mobileInfoCardInner').scrollTop(0); // Scroll DIV To Top $("#mobileZoneInfo").find('.bg-info').css('background-color', infoColor); $("#mobileZoneInfo").find('.bg-info').css('color', infoTextColor); $("#mobileZoneId").text(zoneLetter); $("#mobileZoneName").text(zoneTypeName); $("#mobileZoneSelect").val(zoneTypeId); $("#mobileZoneDescription").val(polygon.polygonDescription); $("#mobileZoneAreaFt").text(commaSeparateNumber(polygon.area_ft)); $("#mobileZoneAreaYds").text(commaSeparateNumber(polygon.area_yd)); $("#saveZoneMobile").data('zone-id', polygon.polygonID); $("#deleteZoneMobile").data('zone-id', polygon.polygonID); $("#mobileZoneInfo").data('zone-id', polygon.polygonID); $("#mobileZoneSelect").data('zone-id', polygon.polygonID); $("#mobileZoneDescription").data('zone-id', polygon.polygonID); $("#saveZoneMobile").data('zone-id', polygon.polygonID); $("#saveZoneMobileNew").data('zone-id', polygon.polygonID); var content = ''; var previewSrc1 = '/addImage.png'; var image1 = false; var previewSrc2 = '/addImage.png'; var image2 = false; var preview1 = $("#previewPolygon-" + polygon.polygonID + "-1").attr('src'); var preview2 = $("#previewPolygon-" + polygon.polygonID + "-2").attr('src'); if (preview1) { previewSrc1 = preview1; var image1 = true; } if (preview2) { previewSrc2 = true; var image2 = true; } if (image1) { content = content + '
' + '
' + '
' + 'X' + '' + '
' + '
'; } else { content = content + '
' + '
' + '
' + '' + '
' + '
'; } if (image2) { content = content + '
' + '
' + 'X' + '' + '
' + '
' + '
'; } else { content = content + '
' + '
' + '' + '
' + '
' + '
'; } $("#mobileZoneImages").html(content); // Show step interface if new zone// // Clear the steps and dropdown $(".mobileZoneNavStep").hide(); $("#mobileZoneSelectContainer").hide(); if (newZone) { $(".mobileZoneStep").hide(); $("#mobileZoneStep1").show(); $("#mobileZoneStep1Next").show(); } else { $(".mobileZoneStep").show(); $("#mobileZoneSelectContainer").show(); } $("#mobileZoneInfo").addClass('showMe'); } function loadMobileLineScreen(line) { var lineLetter = String.fromCharCode(64 + line.lineID); var lineTypeId = line.typeId; var lineTypeName = lineTypes[lineTypeId]; var infoColor = lineColors[lineTypeId][0]; var infoTextColor = lineColors[lineTypeId][1]; $('div.mobileInfoCardInner').scrollTop(0); // Scroll DIV To Top $("#mobileLineInfo").find('.bg-info').css('background-color', infoColor); $("#mobileLineInfo").find('.bg-info').css('color', infoTextColor); $("#mobileLineId").text(lineLetter); $("#mobileLineName").text(lineTypeName); $("#mobileLineSelect").val(lineTypeId); $("#mobileLineDescription").val(line.lineDescription); $("#mobileLineLengthFt").text(commaSeparateNumber(line.length_ft)); $("#mobileLineLengthYds").text(commaSeparateNumber(line.length_yd)); $("#saveLineMobile").data('line-id', line.lineID); $("#saveLineMobileNew").data('line-id', line.lineID); $("#deleteLineMobile").data('line-id', line.lineID); $("#mobileLineInfo").data('line-id', line.lineID); $("#mobileLineSelect").data('line-id', line.lineID); $("#mobileLineDescription").data('line-id', line.lineID); var content = ''; var previewSrc1 = '/addImage.png'; var image1 = false; var previewSrc2 = '/addImage.png'; var image2 = false; var preview1 = $("#previewLine-" + line.lineID + "-1").attr('src'); var preview2 = $("#previewLine-" + line.lineID + "-2").attr('src'); if (preview1) { previewSrc1 = preview1; var image1 = true; } if (preview2) { previewSrc2 = true; var image2 = true; } if (image1) { content = content + '
' + '
' + '
' + 'X' + '' + '
' + '
'; } else { content = content + '
' + '
' + '
' + '' + '
' + '
'; } if (image2) { content = content + '
' + '
' + 'X' + '' + '
' + '
' + '
'; } else { content = content + '
' + '
' + '' + '
' + '
' + '
'; } $("#mobileLineImages").html(content); $("#mobileLineImages").html(content); $(".mobileLineNavStep").hide(); $("#mobileLineSelectContainer").hide(); if (newLineFlag) { $(".mobileLineStep").hide(); $("#mobileLineStep1").show(); $("#mobileLineStep1Next").show(); } else { $(".mobileLineStep").show(); $("#mobileLineSelectContainer").show(); } $("#mobileLineInfo").addClass('showMe'); } function loadMobileMarkerScreen(markerId, image) { var marker = markers[markerId]; if (severityOff) { marker.severity = 4; } var markerTypeName = markerTypes[marker.markerType]; var severityId = marker.severity; var infoColor = markerColors[marker.markerTypeId]['color']; var infoTextColor = markerColors[marker.markerTypeId]['text_color']; $('div.mobileInfoCardInner').scrollTop(0); // Scroll DIV To Top $("#mobileMarkerInfo").find('.bg-info').css('background-color', infoColor); $("#mobileMarkerInfo").find('.bg-info').css('color', infoTextColor); $("#mobileMarkerId").text(marker.markerID); $("#mobileMarkerName").text(markerTypeName); $("#mobileMarkerSeveritySelect").val(severityId); $("#mobileMarkerSeveritySelect").data('marker-id', markerId); $("#mobileMarkerDescription").val(marker.markerDescription); $("#saveMarkerMobileNew").data('marker-id', marker.markerID); $("#deleteMarkerMobile").data('marker-id', marker.markerID); $("#mobileMarkerInfo").data('marker-id', marker.markerID); $("#mobileMarkerType").data('marker-id', marker.markerID); var content = ''; var previewSrc1 = '/addImage.png'; var image1 = false; var previewSrc2 = '/addImage.png'; var image2 = false; if (marker.image1) { if (isBase64(marker.image1)) { previewSrc1 = marker.image1; } else { previewSrc1 = imagePath + marker.image1; } image1 = true; } if (marker.image2) { if (isBase64(marker.image2)) { previewSrc2 = marker.image2; } else { previewSrc2 = imagePath + marker.image2; } image2 = true; } if (image1) { content = content + '
' + '
' + '
' + 'X' + '' + '
' + '
'; } else { content = content + '
' + '
' + '
' + '' + '
' + '
'; } if (image2) { content = content + '
' + '
' + 'X' + '' + '
' + '
' + '
'; } else { content = content + '
' + '
' + '' + '
' + '
' + '
'; } $("#mobileMarkerImages").html(content); // A new marker will have a severity of 0 if (marker.severity === 0 || severityOff) { newMarker = true; $("#mobileMarkerSeveritySelect").prepend(new Option('-- Please Select', 0)) $(".mobileIssueStep").hide(); $("#mobileIssueStep1").show(); $(".mobileIssueNavStep").show(); $("#mobileIssueStep1Next").hide(); $("#markerSeveritySelectContainer").hide(); $("#severityOptions").show(); $(".severityOption").removeClass('selected'); } else { $("#markerSeveritySelectContainer").show(); $("#severityOptions").hide(); if (image) { $(".mobileIssueStep").hide(); $("#mobileIssueStep2").show(); $(".mobileIssueNavStep").show(); } else { newMarker = false; $(".mobileIssueStep").show(); $(".mobileIssueNavStep").hide(); } } if (severityOff) { $("#mobileIssueStep1").hide(); $("#mobileIssueStep2").show(); $("#markerSeveritySelectContainer").hide(); $("#severityOptions").hide(); $("#mobileIssueStep2Prev").hide(); $("#mobileIssueStep2").find(".mobileStepPrefix").text('Step 1: '); $("#mobileIssueStep3").find(".mobileStepPrefix").text('Step 2: '); } $("#mobileIssueStep3Prev").hide(); $("#mobileMarkerInfo").addClass('showMe'); } /* Mobile issue severity dropdown */ $("#mobileMarkerSeveritySelect").change(function () { // Show the next button once a positive option is selected if ($(this).val() > 0) { // Once selected, remove the default option $(this).find('[value="0"]').remove(); if (newMarker) { $("#mobileIssueStep1Next").show(); } } }); /* Mobile issue step 1 next button for step 1 */ $("#mobileIssueStep1Next").click(function () { $("#mobileIssueStep1").hide(); $("#mobileIssueStep2").show(); return false; }); /* Mobile issue step 2 previous button */ $("#mobileIssueStep2Prev").click(function () { $("#mobileIssueStep2").hide(); $("#mobileIssueStep1").show(); return false; }); /* Mobile issue step 2 next button */ $("#mobileIssueStep2Next").click(function () { $("#mobileIssueStep2").hide(); $("#mobileIssueStep3").show(); $("#mobileIssueStep3Prev").show(); return false; }); /* Mobile issue step 3 prev button */ $("#mobileIssueStep3Prev").click(function () { $("#mobileIssueStep3").hide(); $("#mobileIssueStep2").show(); $("#mobileIssueStep3Prev").hide(); return false; }); /*--- Mobile Zone Steps ---*/ /* Mobile zone step 1 next button for step 1 */ $("#mobileZoneStep1Next").click(function () { $("#mobileZoneStep1").hide(); $("#mobileZoneStep2").show(); $("#mobileZoneStep2Prev").show(); return false; }); /* Mobile zone step 1 next button for step 1 */ $("#mobileZoneStep2Prev").click(function () { $("#mobileZoneStep2").hide(); $("#mobileZoneStep1").show(); return false; }); /*--- Mobile Line Steps ---*/ /* Mobile line step 1 next button for step 1 */ $("#mobileLineStep1Next").click(function () { $("#mobileLineStep1").hide(); $("#mobileLineStep2").show(); $("#mobileLineStep2Prev").show(); return false; }); /* Mobile line step 1 next button for step 1 */ $("#mobileLineStep2Prev").click(function () { $("#mobileLineStep2").hide(); $("#mobileLineStep1").show(); return false; }); function styleMobileMarkerScreen(marker) { var markerTypeName = markerTypes[marker.markerType]; var infoColor = markerColors[marker.markerTypeId]['color']; var infoTextColor = markerColors[marker.markerTypeId]['text_color']; $("#mobileMarkerInfo").find('.bg-info').css('background-color', infoColor); $("#mobileMarkerInfo").find('.bg-info').css('color', infoTextColor); $("#mobileMarkerId").text(marker.markerID); $("#mobileMarkerName").text(markerTypeName); } function loadMarkerWindow(id, marker) { if (isMobile()) { loadMobileMarkerScreen(id); return; } // Remember the position of this marker to return to goBackPosition = marker.position; // Move map center based on position and heading var markerLat = marker.position.lat(); var markerLng = marker.position.lng(); var heading = map.getHeading(); var offsetLat; var offsetLng; var offsetDistance; var mapZoom = map.getZoom(); switch (mapZoom) { case 20: offsetDistance = 0.00028; break; case 19: offsetDistance = 0.00048; break; case 18: offsetDistance = 0.00078; break; case 17: offsetDistance = 0.00158; break; case 16: offsetDistance = 0.00288; break; } switch (heading) { case 90: offsetLat = markerLat; offsetLng = markerLng + offsetDistance; break; case 180: offsetLat = markerLat - offsetDistance; offsetLng = markerLng; break; case 270: offsetLat = markerLat; offsetLng = markerLng - offsetDistance; break; default: offsetLat = markerLat + offsetDistance; offsetLng = markerLng; break; } var newCenter = new google.maps.LatLng(offsetLat, offsetLng); map.setCenter(newCenter); var previewSrc1 = '/addImage.png'; var image1 = false; var previewSrc2 = '/addImage.png'; var image2 = false; var preview1 = $("#preview-" + id + "-1").attr('src'); var preview2 = $("#preview-" + id + "-2").attr('src'); if (preview1) { previewSrc1 = preview1; var image1 = true; } if (preview2) { previewSrc2 = true; var image2 = true; } var windowMarkerIcon = ''; var markerTypeName = markerTypes[marker.markerType]; var content = '
' + '
' + '
' + '
' + '' + windowMarkerIcon + '' + markerTypeName + '' + '
' + '
' + '
' + '
' + '

Change to New Issue:

'; content = content + ''; content = content + '
' + '
'; //SEVERITY OPTION START if (severityOff) { content = content + ''; } else { content = content + '
' + '
' + '
' + 'Type:' + '' + '
' + '
' + '
'; } //SEVERITY OPTION END content = content + '
'; if (image1) { content = content + '
' + '
' + '
' + 'X' + '' + '
' + '
'; } else { content = content + ''; } else { content = content + '
' + '
' + '' + '
' + '
' + '
'; } content = content + '
' + '
' + '
' + '' + '
' + '
' + '
' + '
' + ' Save ' + '
' + '
' + ' Remove' + '
' + '
' + '
'; /*First imageAttachment... */ content = content + '
' + ''; infoWindow.setContent(content); infoWindow.setOptions({pixelOffset: new google.maps.Size(0, 0)}); // THis gets adjusted by opening polygon windows infoWindow.open(map, marker); currentMarker = marker.markerID; } /************************* * Polygon Stuff & Stuff * *************************/ function refreshImages() { $(".imageAttachment").each(function () { var markerId = $(this).data('markerid'); var imageNum = $(this).data('image-num'); var marker = markers[markerId]; var imageWrapper = $(this).find('.imageWrapper'); var fileWrapper = $(this).find('.fileWrapper'); var theImage = $(this).find('.image'); var encodeImage = $(this).find('.encodeImage'); var remove = $(this).find('.remove'); var cancel = $(this).find('.cancel'); var fileName = $(this).find('.fileName'); var lightbox = $(this).find('.lightbox-image'); var parentRow = $(this).parents('tr'); // Cards for mobile var cardImageAttachment = $("#marker-card-attachment-" + markerId + '-' + imageNum); var cardImageWrapper = cardImageAttachment.find('.cardImageWrapper'); var cardFileWrapper = cardImageAttachment.find('.cardFileWrapper'); var cardImage = cardImageWrapper.find('.image'); var cardLightbox = cardImageWrapper.find('.lightbox-card-image'); if (marker) { var selectedImage = null; switch (imageNum) { case 1: selectedImage = marker.image1; break; case 2: selectedImage = marker.image2; break; } if (selectedImage) { var imgSrc = null; // If not base64 if (isBase64(selectedImage)) { imgSrc = selectedImage; } else { imgSrc = imagePath + selectedImage; } // Hide the uploads and show the image fileWrapper.hide(); cardFileWrapper.hide(); imageWrapper.show(); cardImageWrapper.show(); theImage.attr('src', imgSrc); cardImage.attr('src', imgSrc); lightbox.attr('href', imgSrc); cardLightbox.attr('href', imgSrc); } else { fileWrapper.show(); cardFileWrapper.show(); imageWrapper.hide(); cardImageWrapper.hide(); } } else { // Remove rows from the table of any non existent items parentRow.remove(); $('#marker-card-' + markerId).remove(); } var windowOpen = ($("#mapInfoWindow" + markerId).length); if (windowOpen) { infoWindow.close(); //hideInfoWindowToolbar(); setTimeout(function () { new google.maps.event.trigger(markers[markerId], 'click'); }, 500) } }); if ($("#mobileMarkerInfo").is(':visible')) { var marker = markers[$("#mobileMarkerInfo").data('marker-id')]; if (marker && (marker.markerID == triggeredMarker)) { $(".imageLoading").show(); setTimeout(function () { $(".imageLoading").hide(); if ($("#mobileMarkerInfo").hasClass('showMe')) { loadMobileMarkerScreen(marker.markerID, newMarker); } }, 1500); } } } /*Build hidden inputs to be sent to server*/ function addHiddenInput(name, value, quote) { quote = quote || '"'; $("#hiddenInputs").append(''); } /*Save trigger*/ $("#saveReview, #sendReview").on('click', function () { var sendValue = $(this).data('save'); var completeValue = $(this).data('complete'); // Hide the confirmation modals $('#modalSaved').modal('hide'); $('#modalSubmitted').modal('hide'); // How the saving modal $('#savingModal').modal('show'); prepareFormData(sendValue, completeValue); $('#savingModal').modal('hide'); }); function updateIssuesTable(refresh) { updateMarkerCounter(); var counter = 0; var html; $("#markerCards").html(''); $("#issues tbody").html(''); //add new markers to the table for (i in markers) { //add for new markers counter++; marker = markers[i]; var category = ''; if (combined) { category = auditTypes[typeCategories[marker.markerTypeId]].name; } html = '' + '' + marker.markerCounter + '' + '' + category+ '' + '' + markerTypes[marker.markerType] + '' + '' + severity_types[marker.severity] + '' + '' + '
' + '
' + /* First ImageAttachment DIV */ '
' + '
' + '' + '' + 'X' + '
' + '
' + '' + /*File 1*/ '' + '
' + '
' + '
' + '
' + /*Second imageAttachment... */ '
' + '
' + '' + '' + 'X' + '
' + '
' + '' + /* File 2 */ '' + '
' + '
' + '
' + '
' + '' + '' + '' + '' + '' + '
' + '' + '' + ' Save' + '
' + '
' + marker.markerDescription + '
' + '' + ''; $("#issues tbody").append(html); if (combined) { category = auditTypes[typeCategories[marker.markerTypeId]].name + ' | '; } // Update the mobile cards cardHtml = '
' + '' + '
' + '
' + '
' + '
' + '

' + marker.markerDescription + '

'; cardHtml += '
' + '
' + '
' + '
' + '
' + '
' + '
' + '' + '' + '' + '
' + '' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '' + '' + '' + '
' + '' + '
' + '
' + '
' + '
' + '
' + '
' + ' Edit' + '
' + '
' + '' + '
' + '
' + '
' + '
' + '
'; $("#markerCards").append(cardHtml); $('[data-toggle="tooltip"]').tooltip(); } $("#cardIssueCount").text(counter); refreshImages(); if (counter > 0) { $("#markerIssues").show(); } else { $("#markerIssues").hide(); } // if (refresh !== false) { // updateInitialMessage(); // } } /******************* * Polygons * *******************/ function pointInPolygon(point, polygon) { //point = LatLng //polygon = google maps polygon return google.maps.geometry.poly.containsLocation(point, polygon); } function addPolygon(data, reportPolygon, noUpdate) { var id = null; var areaRaw; if (typeof(data.id) != 'undefined') { id = data.id; } var showZone = true; if (reportFilter) { var zoneTypeId = data.typeId; if (filteredZones.indexOf(zoneTypeId) < 0) { showZone = false; } } newZone = true; polygonCounter++; if (data.areaRaw) { areaRaw = data.areaRaw; } else { areaRaw = google.maps.geometry.spherical.computeArea(data.path); } console.log(areaRaw); var area_ft = areaRaw * 10.764; var area_yd = areaRaw * 1.1960; data.image1 = (data.image1) ? data.image1 : ''; data.image2 = (data.image2) ? data.image2 : ''; data.polygonDescription = (data.polygonDescription) ? data.polygonDescription : ''; var bounds = new google.maps.LatLngBounds(); var path = data.path.getArray(); for (i in path) { bounds.extend(path[i]); } var center = bounds.getCenter(); var infoBoxOptions = { content: 'Zone:' + String.fromCharCode(64 + polygonCounter) + '', boxStyle: { fontSize: "8pt", width: "50px", zIndex: 200 }, disableAutoPan: true, pixelOffset: new google.maps.Size(-25, 0), position: center, closeBoxURL: "", isHidden: !showZone, enableEventPropagation: true }; var polygonOptions = { id: id, paths: data.path, strokeOpacity: 0.8, strokeWeight: 1, fillColor: zoneColors[data.typeId][0], strokeColor: zoneColors[data.typeId][1], fillOpacity: 0.35, map: showZone ? map : null, //stuff polygonID: polygonCounter, areaRaw: areaRaw, area_ft: area_ft.toFixed(0), area_yd: area_yd.toFixed(0), polygonDescription: data.polygonDescription, typeId: data.typeId, polygonCounter: polygonCounter, image1: data.image1, image2: data.image2, center: center, label: new InfoBox(infoBoxOptions), saved: data.saved }; polygons[polygonCounter] = new google.maps.Polygon(polygonOptions); var returnPolygon = polygons[polygonCounter]; polygons[polygonCounter].label.open(map); if (!pointInPolygon(polygons[polygonCounter].center, polygons[polygonCounter])) { //calculate the new center point centerLat = center.lat(); centerLng = center.lng(); var newCenter; var increment = 0.00013; var increment_x = 0.00010; var maxTries = 25; var found = 0; var directions = [ //clockwise x/y increments [-increment_x, 0], //left [0, increment], //top [increment_x, 0], //right [0, -increment], //bottom [-increment_x, increment], //top left [increment_x, increment], //top right [increment_x, -increment], //bottom right [-increment_x, -increment] //bottom left ]; for (i = 1; i <= maxTries; i++) { if (!found) { //remove || 1 later for (k in directions) { if (!found) { //remove || 1 later var testLat = (centerLat + (directions[k][0] * i)); var testLng = (centerLng + (directions[k][1] * i)); newCenter = new google.maps.LatLng(testLat, testLng); if (pointInPolygon(newCenter, polygons[polygonCounter])) { if (!found) { found = 1; //find the middle of the shape var startPoint = i; i++; while (pointInPolygon(new google.maps.LatLng(centerLat + (directions[k][0] * i), centerLng + (directions[k][1] * i)), polygons[polygonCounter])) { i++; } i--; finalIteration = Math.floor((startPoint + i) / 2); newCenter = new google.maps.LatLng(centerLat + (directions[k][0] * finalIteration), centerLng + (directions[k][1] * finalIteration)); //set new center polygons[polygonCounter].center = newCenter; polygons[polygonCounter].label.setPosition(newCenter); } } } } } } } if (!reportPolygon) { google.maps.event.addListener(polygons[polygonCounter], 'click', function () { newZone = false; loadPolygonWindow(this.polygonID, this); }); if (typeof noUpdate == 'undefined') { updatePolygonIssuesTable(); } } else { google.maps.event.addListener(polygons[polygonCounter], 'click', function () { loadReportPolygonWindow(this.polygonID); }); } return returnPolygon; } function addLine(data, reportLine, noUpdate) { var id = null; if (typeof(data.id) != 'undefined') { id = data.id; } var showLine = true; if (reportFilter) { var lineTypeId = data.typeId; if (filteredLines.indexOf(lineTypeId) < 0) { showLine = false; } } newLineFlag = true; // Increment Counter lineCounter++; // Retrieve length var lengthRaw; if (data.lengthRaw) { lengthRaw = data.lengthRaw; } else { lengthRaw = google.maps.geometry.spherical.computeLength(data.path); } // Convert Length var length_ft = lengthRaw * 3.28084; var length_yd = lengthRaw * 1.09361; // Handle any images and descripton data.image1 = (data.image1) ? data.image1 : ''; data.image2 = (data.image2) ? data.image2 : ''; data.lineDescription = (data.lineDescription) ? data.lineDescription : ''; var lineIndex = 1; if (isEven(newLineCornerCounter)) { lineIndex = (newLineCornerCounter / 2); } else { lineIndex = ((newLineCornerCounter + 1) / 2); } lineIndex--; if (lineIndex < 0) { lineIndex = 0; } var path = data.path.getArray(); var center = new google.maps.LatLng(path[lineIndex].lat(), path[lineIndex].lng()); var lineColor = lineColors[data.typeId][0]; var lineWidth = lineColors[data.typeId][2]; var infoBoxOptions = { content: 'Line:' + String.fromCharCode(64 + lineCounter) + '', boxStyle: { fontSize: "8pt", padding: "3px", zIndex: 200 }, disableAutoPan: true, pixelOffset: new google.maps.Size(-25, 0), position: center, closeBoxURL: "", isHidden: !showLine, enableEventPropagation: true }; var lineOptions = { id: id, path: path, strokeOpacity: 0.8, strokeWeight: lineWidth, strokeColor: lineColor, map: showLine ? map : null, geodesic: true, //stuff lineID: lineCounter, lengthRaw: lengthRaw, length_ft: length_ft.toFixed(0), length_yd: length_yd.toFixed(0), lineDescription: data.lineDescription, typeId: data.typeId, lineCounter: lineCounter, image1: data.image1, image2: data.image2, center: center, label: new InfoBox(infoBoxOptions), saved: data.saved }; lines[lineCounter] = new google.maps.Polyline(lineOptions); var returnLine = lines[lineCounter]; lines[lineCounter].label.open(map); // Audit Lines if (!reportLine) { google.maps.event.addListener(lines[lineCounter], 'click', function () { newLineFlag = false; loadLineWindow(this.lineID); }); if (typeof noUpdate == 'undefined') { updateLinesTable(); } } else { // Report Lines google.maps.event.addListener(lines[lineCounter], 'click', function () { loadReportLineWindow(this.lineID); }); } return returnLine; } function loadLineWindow(id) { updateLineCounter(); currentLine = id; var line = lines[id]; if (isMobile()) { loadMobileLineScreen(line); return; } var offsetDistance; var mapZoom = map.getZoom(); var offsetLat; var offsetLng; var lineLat = line.center.lat(); var lineLng = line.center.lng(); goBackPosition = new google.maps.LatLng(lineLat, lineLng); switch (mapZoom) { case 20: offsetDistance = 0.0002; break; case 19: offsetDistance = 0.0004; break; case 18: offsetDistance = 0.0007; break; case 17: offsetDistance = 0.0015; break; case 16: offsetDistance = 0.0028; break; } switch (heading) { case 90: offsetLat = lineLat; offsetLng = lineLng + offsetDistance; break; case 180: offsetLat = lineLat - offsetDistance; offsetLng = lineLng; break; case 270: offsetLat = lineLat; offsetLng = lineLng - offsetDistance; break; default: offsetLat = lineLat + offsetDistance; offsetLng = lineLng; break; } var newCenter = new google.maps.LatLng(offsetLat, offsetLng); map.setCenter(newCenter); var previewSrc1 = '/addImage.png'; var image1 = false; var previewSrc2 = '/addImage.png'; var image2 = false; var preview1 = $("#previewLine-" + id + "-1").attr('src'); var preview2 = $("#previewLine-" + id + "-2").attr('src'); if (preview1) { previewSrc1 = preview1; var image1 = true; } if (preview2) { previewSrc2 = true; var image2 = true; } var content = '
' + '
' + '
' + '
' + 'Line ' + String.fromCharCode(64 + line.lineCounter) + '' + '
' + '
' + '
' + '
' + '
' + 'Type:' + '' + '
' + '
' + '
'; content += '
' + '
' + 'Length: ' + commaSeparateNumber(line.length_ft) + ' ft' + ' / ' + commaSeparateNumber(line.length_yd) + ' yds' + '
' + '
'; if (image1) { content = content + '
' + '
' + '
' + 'X' + '' + '
' + '
'; } else { content = content + '
' + '
' + '
' + '' + '
' + '
'; } if (image2) { content = content + '
' + '
' + 'X' + '' + '
' + '
'; } else { content = content + '
' + '
' + '' + '
' + '
'; } content = content + '
'; content += '
' + '
' + '' + '
' + '
' + '
' + '
' + ' Save' + '
' + '
' + ' Move Window' + //add move button '
' + '
' + 'Remove
' + '
' + '
' + '
' + '
'; infoWindow.setContent(content); infoWindow.setPosition(line.center); infoWindow.setOptions({pixelOffset: new google.maps.Size(-25, 0)}); // set the offset to get the clickable map --> by preeti infoWindow.open(map); } function updateLinesTable(refresh) { var counter = 0; var html; var category = ''; $("#issues-lines tbody").html(''); $("#lineCards").html(''); for (i in lines) { counter++; var lineLetter = String.fromCharCode(64 + counter); // Update the label with the correct letter var line = lines[i]; if (combined) { category = auditTypes[lineCategories[line.typeId]].name + ' | '; } line.label.setContent('Line:' + String.fromCharCode(64 + counter) + ''); html = '' + '' + lineLetter + '' + '' + category + '' + '' + lineTypes[line.typeId] + '' + '' + '' + commaSeparateNumber(line.length_ft) + '' + '' + '' + '' + commaSeparateNumber(line.length_yd) + '' + '' + '' + '
' + '
' + /*First line Attachment div*/ '
' + /*Filename 1*/ '' + '
' + '' + 'X' + '
' + '
' + '' + /*File 1*/ '' + '
' + '
' + '
' + '
' + /*Second line Attachment div*/ '
' + /*Filename 2*/ '' + '
' + '' + 'X' + '
' + '
' + '' + /*File 2*/ '' + '
' + '
' + '
' + '
' + '' + '' + '' + '' + '' + '
' + '' + '' + ' Save' + '
' + '
' + line.lineDescription + '
' + '' + ''; $("#issues-lines tbody").append(html); $('[data-toggle="tooltip"]').tooltip(); // Update the mobile cards var cardsHtml = '
' + '' + '
' + '
' + '
' + '
' + '

' + '' + commaSeparateNumber(line.length_ft) + '' + ' ft | ' + '' + commaSeparateNumber(line.length_yd) + '' + ' yds' + '

' + '

' + line.lineDescription + '

' + '
' + '
' + '
' + '
' + /*First ImageAttachment DIV*/ '
' + '
' + '' + '' + '
' + '
' + '
' + '
' + '
' + '
' + '' + '' + '
' + '
' + '
' + '
' + '
' + '
' + ' Edit' + '
' + '
' + '' + '
' + '
' + '
' + '
' + '
'; $("#lineCards").append(cardsHtml); } $("#cardLineCount").text(counter); refreshLineImages(); if (counter > 0) { $("#lineIssues").show(); } else { $("#lineIssues").hide(); } // if (refresh !== false) { // updateInitialMessage(); // } } function loadReportLineWindow(lineId) { if (isMobile()) { loadMobileReportLineWindow(lineId) return; } updateLineCounter(); currentPolygon = lineId; var line = lines[lineId]; var offsetDistance; var mapZoom = map.getZoom(); var offsetLat; var offsetLng; var heading = map.getHeading(); var lineLat = line.center.lat(); var lineLng = line.center.lng(); goBackPosition = new google.maps.LatLng(lineLat, lineLng); switch (mapZoom) { case 20: offsetDistance = 0.0002; break; case 19: offsetDistance = 0.0004; break; case 18: offsetDistance = 0.0007; break; case 17: offsetDistance = 0.0015; break; case 16: offsetDistance = 0.0028; break; } switch (heading) { case 90: offsetLat = lineLat; offsetLng = lineLng + offsetDistance; break; case 180: offsetLat = lineLat - offsetDistance; offsetLng = lineLng; break; case 270: offsetLat = lineLat; offsetLng = lineLng - offsetDistance; break; default: offsetLat = lineLat + offsetDistance; offsetLng = lineLng; break; } var newCenter = new google.maps.LatLng(offsetLat, offsetLng); map.setCenter(newCenter); var previewSrc1 = '/addImage.png'; var image1 = false; var previewSrc2 = '/addImage.png'; var image2 = false; var preview1 = $("#previewLine-" + lineId + "-1").attr('src'); var preview2 = $("#previewLine-" + lineId + "-2").attr('src'); if (preview1) { previewSrc1 = preview1; var image1 = true; } if (preview2) { previewSrc2 = true; var image2 = true; } var content = '
' + '
' + '
' + '
' + 'Line ' + String.fromCharCode(64 + line.lineCounter) + ': ' + lineTypes[line.typeId] + '' + '
' + '
'; content += '
' + '
' + '

Length: ' + commaSeparateNumber(line.length_ft) + ' ft


' + '
' + '
'; if (image1) { content = content + '
' + '
' + '
' + '' + '
' + '
'; } if (image2) { content = content + '
' + '
' + '' + '
' + '
'; } if (!line.image1 && !line.image2) { content = content + '

No images were uploaded for this line.

'; } var descriptionContent; if (line.lineDescription) { descriptionContent = line.lineDescription; } else { descriptionContent = 'No description was given for this line'; } content += '
' + '

' + '

' + descriptionContent + '

' + '
' + '
' + '
' + '
' + '
'; infoWindow.setContent(content); infoWindow.setPosition(line.center); infoWindow.setOptions({pixelOffset: new google.maps.Size(-25, 0)}); // set the offset to get the clickable map --> by preeti infoWindow.open(map); } function loadPolygonWindow(id, polygon) { updatePolygonCounter(); currentPolygon = id; var polygon = polygons[id]; if (isMobile()) { loadMobileZoneScreen(polygon); return; } var offsetDistance; var mapZoom = map.getZoom(); var offsetLat; var offsetLng; var polygonLat = polygon.center.lat(); var polygonLng = polygon.center.lng(); goBackPosition = new google.maps.LatLng(polygonLat, polygonLng); switch (mapZoom) { case 20: offsetDistance = 0.0002; break; case 19: offsetDistance = 0.0004; break; case 18: offsetDistance = 0.0007; break; case 17: offsetDistance = 0.0015; break; case 16: offsetDistance = 0.0028; break; } switch (heading) { case 90: offsetLat = polygonLat; offsetLng = polygonLng + offsetDistance; break; case 180: offsetLat = polygonLat - offsetDistance; offsetLng = polygonLng; break; case 270: offsetLat = polygonLat; offsetLng = polygonLng - offsetDistance; break; default: offsetLat = polygonLat + offsetDistance; offsetLng = polygonLng; break; } var newCenter = new google.maps.LatLng(offsetLat, offsetLng); map.setCenter(newCenter); var previewSrc1 = '/addImage.png'; var image1 = false; var previewSrc2 = '/addImage.png'; var image2 = false; var preview1 = $("#previewPolygon-" + id + "-1").attr('src'); var preview2 = $("#previewPolygon-" + id + "-2").attr('src'); if (preview1) { previewSrc1 = preview1; var image1 = true; } if (preview2) { previewSrc2 = true; var image2 = true; } var content = '
' + '
' + '
' + '
' + 'Zone ' + String.fromCharCode(64 + polygon.polygonCounter) + '' + '
' + '
' + '
' + '
' + '
' + 'Type:' + '' + '
' + '
' + '
'; content += '
' + '
' + 'Area: ' + commaSeparateNumber(polygon.area_ft) + ' ft2 / ' + commaSeparateNumber(polygon.area_yd) + ' yds2' + '
' + '
'; if (image1) { content = content + '
' + '
' + '
' + 'X' + '' + '
' + '
'; } else { content = content + '
' + '
' + '
' + '' + '
' + '
'; } if (image2) { content = content + '
' + '
' + 'X' + '' + '
' + '
'; } else { content = content + '
' + '
' + '' + '
' + '
'; } content = content + '
'; content += '
' + '
' + '' + '
' + '
' + '
' + '
' + ' Save' + '
' + '
' + ' Move Window' + //add move button '
' + '
' + 'Remove
' + '
' + '
' + '
' + '
'; infoWindow.setContent(content); infoWindow.setPosition(polygon.center); infoWindow.setOptions({pixelOffset: new google.maps.Size(-25, 0)}); // set the offset to get the clickable map --> by preeti infoWindow.open(map); } function removePolygon(removePolygonId) { var polygon = polygons[removePolygonId]; if (polygon.id != null) { $.get('/audit/deleteZone/' + polygon.id, function (response) { if (response.success) { polygon.setMap(null); polygon.label.close(); delete polygons[removePolygonId]; infoWindow.close(); hideInfoWindowToolbar(); $("#polygon-" + polygon.polygonID).fadeOut(300, function () { $(this).remove(); }); $("#polygon-card-" + polygon.polygonID).fadeOut(300, function () { $(this).remove(); }); } else { bootbox.alert('There was an error deleting the zone'); } }); } else { polygon.setMap(null); polygon.label.close(); infoWindow.close(); hideInfoWindowToolbar(); delete polygons[removePolygonId]; } updatePolygonIssuesTable(); } function removeLine(removeLineId) { var line = lines[removeLineId]; if (line.id != null) { $.get('/audit/deleteLine/' + line.id, function (response) { if (response.success) { line.setMap(null); line.label.close(); delete lines[removeLineId]; infoWindow.close(); $("#line-" + line.lineID).fadeOut(300, function () { $(this).remove(); }); $("#line-card-" + line.lineID).fadeOut(300, function () { $(this).remove(); }); } else { bootbox.alert('There was an error deleting the line'); } }); } else { line.setMap(null); line.label.close(); delete lines[removeLineId]; infoWindow.close(); hideInfoWindowToolbar(); } updateLinesTable(); } function updatePolygonIssuesTable(refresh) { var counter = 0; var html; var category = ''; $("#issues-polygons tbody").html(''); $("#zoneCards").html(''); //add new markers to the table for (i in polygons) { //add for new markers counter++; polygon = polygons[i]; if (combined) { category = auditTypes[zoneCategories[polygon.typeId]].name; } polygon.label.setContent('Zone: ' + String.fromCharCode(64 + counter) + ''); html = '' + '' + String.fromCharCode(64 + counter) + '' + '' + category + '' + '' + zoneTypes[polygon.typeId] + '' + '' + '' + commaSeparateNumber(polygon.area_ft) + '' + '' + '' + '' + commaSeparateNumber(polygon.area_yd) + '' + '' + '
' + '
' + /*First Polygon Attachment div*/ '
' + /*Filename 1*/ '' + '
' + '' + 'X' + '
' + '
' + '' + /*File 1*/ '' + '
' + '
' + '
' + '
' + /*Second Polygon Attachment div*/ '
' + /*Filename 2*/ '' + '
' + '' + 'X' + '
' + '
' + '' + /*File 2*/ '' + '
' + '
' + '
' + '
' + '' + '' + '' + '' + '' + '
' + '' + '' + ' Save' + '
' + '
' + polygon.polygonDescription + '
' + '' + ''; $("#issues-polygons tbody").append(html); $('[data-toggle="tooltip"]').tooltip(); if (combined) { category = auditTypes[zoneCategories[polygon.typeId]].name + ' | '; } // Update the mobile cards var cardsHtml = '
' + '' + '
' + '
' + '
' + '
' + '

' + '' + commaSeparateNumber(polygon.area_ft) + '' + ' ft2 | ' + '' + commaSeparateNumber(polygon.area_yd) + '' + ' yds2' + '

' + polygon.polygonDescription + '

' + '
' + '
' + '
' + '
' + /*First ImageAttachment DIV*/ '
' + '
' + '' + '' + '
' + '
' + '
' + '
' + '
' + '
' + '' + '' + '
' + '
' + '
' + '
' + '
' + '
' + ' Edit' + '
' + '
' + '' + '
' + '
' + '
' + '
' + '
'; $("#zoneCards").append(cardsHtml); } $("#cardZoneCount").text(counter); refreshPolygonImages(); if (counter > 0) { $("#zoneIssues").show(); } else { $("#zoneIssues").hide(); } // if (refresh !== false) { // updateInitialMessage(); // } } function updatePolygonCounter() { var counter = 0; for (i in polygons) { counter++; polygons[i].polygonCounter = counter; } } function updateLineCounter() { var counter = 0; for (i in lines) { counter++; lines[i].lineCounter = counter; } } function addMarkerNumber(icon, number) { return icon + "_" + number + ".png"; } function commaSeparateNumber(val) { while (/(\d+)(\d{3})/.test(val.toString())) { val = val.toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2'); } return val; } function fitMap(zoomOut) { var counter = 0; var bounds = new google.maps.LatLngBounds(); for (i in markers) { counter++; bounds.extend(markers[i].getPosition()); } for (i in polygons) { counter++; var path = polygons[i].getPath().getArray(); for (i in path) { bounds.extend(path[i]); } } for (i in lines) { counter++; var path = lines[i].getPath().getArray(); for (i in path) { bounds.extend(path[i]); } } if (counter > 0) { map.fitBounds(bounds); } else { map.setCenter(originalPosition); } if (zoomOut != 'undefined') { var zoom = map.getZoom(); map.setZoom((zoom - 1)); } } function refreshLineImages() { $(".lineImageAttachment").each(function () { var lineId = $(this).data('lineid'); var imageNumber = $(this).data('line-image-num'); var imageWrapper = $(this).children('.imageWrapper'); var fileWrapper = $(this).children('.fileWrapper'); var image = $(this).find('.image'); var remove = $(this).find('.remove'); var cancel = $(this).find('.cancel'); var fileName = $(this).find('.fileName'); var lightbox = $(this).find('.lightbox-image'); // Cards for mobile var lineCardImageAttachment = $('#line-card-attachment-' + lineId + '-' + imageNumber); var lineCardImageWrapper = lineCardImageAttachment.find('.cardLineImageWrapper'); var lineCardFileWrapper = lineCardImageAttachment.find('.cardLineFileWrapper'); var lineCardImage = lineCardImageAttachment.find('.cardLineImage'); var lineCardLightbox = lineCardImageAttachment.find('.lightbox-card-image'); var line = lines[lineId]; var selectedImage = null; switch (imageNumber) { case 1: selectedImage = line.image1; break; case 2: selectedImage = line.image2; break; } if (selectedImage) { var imgSrc = null; // If not base64 if (isBase64(selectedImage)) { imgSrc = selectedImage; } else { imgSrc = imagePath + selectedImage; } fileWrapper.hide(); lineCardFileWrapper.hide(); imageWrapper.show(); lineCardImageWrapper.show(); image.attr('src', imgSrc); lineCardImage.attr('src', imgSrc); lightbox.attr('href', imgSrc); lineCardLightbox.attr('href', imgSrc); } else { fileWrapper.show(); lineCardFileWrapper.show(); imageWrapper.hide(); lineCardImageWrapper.hide(); // lineCardImage.attr('src', ''); } var windowOpen = ($("#mapInfoWindowLine" + lineId).length); if (windowOpen) { infoWindow.close(); setTimeout(function () { new google.maps.event.trigger(lines[lineId], 'click', {}); }, 500) } if ($("#mobileLineInfo").is(':visible')) { line = lines[$("#mobileLineInfo").data('line-id')]; if (line) { $(".imageLoading").show(); setTimeout(function () { $(".imageLoading").hide(); if ($("#mobileLineInfo").hasClass('showMe')) { loadMobileLineScreen(line); } }, 1500); } } }); } function refreshPolygonImages() { $(".polygonImageAttachment").each(function () { var polygonId = $(this).data('polygonid'); var imageNumber = $(this).data('polygon-image-num'); var imageWrapper = $(this).children('.imageWrapper'); var fileWrapper = $(this).children('.fileWrapper'); var image = $(this).find('.image'); var remove = $(this).find('.remove'); var cancel = $(this).find('.cancel'); var fileName = $(this).find('.fileName'); var lightbox = $(this).find('.lightbox-image'); // Cards for mobile var polygonCardImageAttachment = $('#polygon-card-attachment-' + polygonId + '-' + imageNumber); var polygonCardImageWrapper = polygonCardImageAttachment.find('.cardPolygonImageWrapper'); var polygonCardFileWrapper = polygonCardImageAttachment.find('.cardPolygonFileWrapper'); var polygonCardImage = polygonCardImageAttachment.find('.cardPolygonImage'); var polygonCardLightbox = polygonCardImageAttachment.find('.lightbox-card-image'); // The polygon var zone = polygons[polygonId]; var selectedImage = null; switch (imageNumber) { case 1: selectedImage = zone.image1; break; case 2: selectedImage = zone.image2; break; } if (selectedImage) { var imgSrc = null; // If not base64 if (isBase64(selectedImage)) { imgSrc = selectedImage; } else { imgSrc = imagePath + selectedImage; } fileWrapper.hide(); polygonCardFileWrapper.hide(); imageWrapper.show(); polygonCardImageWrapper.show(); image.attr('src', imgSrc); polygonCardImage.attr('src', imgSrc); lightbox.attr('href', imgSrc); polygonCardLightbox.attr('href', imgSrc); } else { fileWrapper.show(); polygonCardFileWrapper.show(); imageWrapper.hide(); polygonCardImageWrapper.hide(); } var windowOpen = ($("#mapInfoWindowPolygon" + polygonId).length); if (windowOpen) { infoWindow.close(); setTimeout(function () { new google.maps.event.trigger(polygons[polygonId], 'click', {}); }, 500) } }); if ($("#mobileZoneInfo").is(':visible')) { var polygon = polygons[$("#mobileZoneInfo").data('zone-id')]; if (polygon) { $(".imageLoading").show(); setTimeout(function () { $(".imageLoading").hide(); if ($("#mobileZoneInfo").hasClass('showMe')) { loadMobileZoneScreen(polygon); } }, 1500); } } } function updateToken(newToken) { $("._token").each(function () { $(this).val(newToken); }); } setInterval(function () { $.get("/generateToken", function (token) { updateToken(token); }); }, 1800000); // 1800 x 1000 miliseconds = a half hour token refresh rate google.maps.event.addListener(infoWindow, 'domready', function () { $("#removeMarker").on('click', function () { removeMarker(currentMarker); returnMap(); return false; }); $("#removePolygon").on('click', function () { removePolygon(currentPolygon); returnMap(); return false; }); $("#removeLine").on('click', function () { removeLine(currentLine); returnMap(); return false; }); $(".windowImgUpload").on('click', function () { var inputId = $(this).data('input-id'); $('#input-' + inputId).trigger('click'); return false; }); $(".windowPolygonImgUpload").on('click', function () { var inputId = $(this).data('input-id'); $('#polygonInput-' + inputId).trigger('click'); return false; }); $(".windowLineImgUpload").on('click', function () { var inputId = $(this).data('input-id'); $('#lineInput-' + inputId).trigger('click'); return false; }); // Make the draggable infowindow --> by preeti $("#moveInfowindow").on('click', function () { if ($("#moveInfowindow").attr('status') == 1) { $("#moveInfowindow").html('Stop'); $("#moveInfowindow").attr('status', 0); mouseHandler = google.maps.event.addListener(map, 'mousemove', function (e) { infoWindow.setPosition(e.latLng); }); google.maps.event.addListener(map, 'click', function (e) { if (mouseHandler != null) google.maps.event.removeListener(mouseHandler); $("#moveInfowindow").html('Move'); $("#moveInfowindow").attr('status', 1); }); } else { google.maps.event.removeListener(mouseHandler); $("#moveInfowindow").html('Move'); $("#moveInfowindow").attr('status', 1); } }); showInfoWindowToolbar(); // Handle infowindow being closed google.maps.event.addListener(infoWindow, 'closeclick', function () { hideInfoWindowToolbar(); returnMap(); }); //----- ends here--- }); $(".printThePreview").on('click', function () { printAuditPage(); }); $(".printReview").on('click', function () { //syncMaps(); setTimeout(function () { window.print(); }, 250); return false; }); $(".printPreview").on('click', function () { showPrintPreviewMap(); return false; }); $("#showFullMap").click(function () { showFullMap(); return false; }); $(".printReport").on('click', function () { showPrintPreviewMap(); $("#printPageButton").show(); $("#fullReportMap").show(); $(this).hide(); return false; }); $("#fullReportMap").click(function () { var mapCenter = map.getCenter(); $('#map').css('width', '100%'); google.maps.event.trigger(map, "resize"); map.setCenter(mapCenter); $(this).hide(); $("#printPageButton").hide(); $("#printButton").show(); }); $("#printPageButton").on('click', function () { newPrintReportPage(); return false; }); function returnMap() { if (goBackPosition) { map.setCenter(goBackPosition); } } function showPrintPreviewMap() { var mapCenter = map.getCenter(); $('#map').css('width', '600px'); $('#map').css('height', '700px'); google.maps.event.trigger(map, "resize"); //map.setCenter(mapCenter); fitMap(); // Hide the Preview Button $("#btnPrintPreview").hide(); // Show the Full Map Button $("#showFullMap").show(); // Hide Map Controls $("#mapControls, #mapSearchIcon").hide(); // Show the Load Document $("#printThePreview").show(); } function showFullMap() { var mapCenter = map.getCenter(); $('#map').css('width', '100%'); google.maps.event.trigger(map, "resize"); map.setCenter(mapCenter); // Show the Preview Button $("#btnPrintPreview").show(); // Hide the Full Map Button $("#showFullMap").hide(); // Hide the Load Document $("#printThePreview").hide(); // Show Map Controls $("#mapControls, #mapSearchIcon").show(); } function printAuditPage() { var dataUrl = []; var i = 0; var baseUrl = window.location.protocol + "//" + window.location.host + "/"; $("#map canvas").filter(function () { dataUrl.push(this.toDataURL("image/png")); }); var mapContainer = document.getElementById('map'); var printWindow = $(mapContainer).clone(); $(printWindow).find('canvas').each(function () { $(this).replaceWith(''); i++; }); var WindowObject = window.open('', "PrintMap", "width=750,height=800,resizable=no,top=200,left=200"); // Intro text var introText = $("#print-intro-text").html(); // Title var titleContent = $("#printTitle").html(); // Marker Issues var markerIssues = $("#print-marker-issues").html(); // Questions var questionContent = $("#auditQuestionsRadio").html(); // Loading Text var loadingText = $("#printLoading").html(); /* // WindowObject.document.writeln(''); // // */ WindowObject.document.writeln(''); WindowObject.document.writeln(''); WindowObject.document.writeln(''); WindowObject.document.writeln(''); WindowObject.document.writeln(''); WindowObject.document.writeln(''); WindowObject.document.writeln(loadingText); WindowObject.document.writeln(''); WindowObject.document.writeln(''); WindowObject.document.writeln(''); WindowObject.document.writeln(''); WindowObject.document.close(); WindowObject.focus(); setTimeout(function () { WindowObject.print(); WindowObject.close(); }, 3000); return false; } function newPrintReportPage() { var promise = encodeReportImage(); } function printReportPage() { var dataUrl = []; var i = 0; var baseUrl = window.location.protocol + "//" + window.location.host + "/"; $("#map canvas").filter(function () { dataUrl.push(this.toDataURL("image/png")); }); var mapContainer = document.getElementById('map'); var printWindow = $(mapContainer).clone(); $(printWindow).find('canvas').each(function () { $(this).replaceWith(''); i++; }); var WindowObject = window.open('', "PrintMap", "width=750,height=800resizable=no"); // Title var titleContent = $("#printTitle").html(); // Legend Content var legend = $("#legend").html(); // Markers var reportMapMarkers = $("#mapMarkers").html(); // Marker Images var reportMarkerImages = $("#mapMarkerImages").html(); // Zones var reportMapZones = $("#mapZones").html(); // Zone Images var mapZoneImages = $("#mapZoneImages").html(); // Lines var reportMapLines = $("#mapLines").html(); // Line Images var mapLineImages = $("#mapLineImages").html(); // Questions var auditQuestions = $("#auditQuestions").html(); // Audit Info var printAuditInfo = $("#printAuditInfo").html(); // Loading Text var loadingText = $("#printLoading").html(); WindowObject.document.writeln(''); WindowObject.document.writeln(''); WindowObject.document.writeln(''); WindowObject.document.writeln(loadingText); WindowObject.document.writeln(''); WindowObject.document.writeln(''); WindowObject.document.writeln(''); if (reportMapMarkers) { WindowObject.document.writeln(''); } if (reportMapZones) { WindowObject.document.writeln(''); WindowObject.document.writeln(''); } if (reportMapLines) { WindowObject.document.writeln(''); WindowObject.document.writeln(''); } if (auditQuestions) { WindowObject.document.writeln(''); } WindowObject.document.writeln(''); WindowObject.document.close(); WindowObject.focus(); setTimeout(function () { WindowObject.print(); WindowObject.close(); }, 3000); return false; } function clearImageInputs() { $(".imageFile").each(function () { $(this).replaceWith($(this).clone()); }); } function updateInitialMessage() { console.log("Update Initial Medssage"); toggleLocationMarker(); $('body').css('display', 'block'); if (isMobile()) { var totalCount = issueCount(); if (!firstLoad) { $("#startPage").removeClass('showMe'); $("#no-issues").hide(); $("#has-issues").show(); $("#issueCount").text(totalCount); } else { $("#startPage").addClass('showMe'); $("#no-issues").show(); $("#has-issues").hide(); firstLoad = false; } } } function loadReportMarkerWindow(id) { if (isMobile()) { loadMobileReportMarkerWindow(id) return; } marker = markers[id]; // Remember the position of this marker to return to goBackPosition = marker.position; // Move map center based on position and heading var markerLat = marker.position.lat(); var markerLng = marker.position.lng(); var heading = map.getHeading(); var offsetLat; var offsetLng; var offsetDistance; var mapZoom = map.getZoom(); switch (mapZoom) { case 20: offsetDistance = 0.00028; break; case 19: offsetDistance = 0.00048; break; case 18: offsetDistance = 0.00078; break; case 17: offsetDistance = 0.00158; break; case 16: offsetDistance = 0.00288; break; } switch (heading) { case 90: offsetLat = markerLat; offsetLng = markerLng + offsetDistance; break; case 180: offsetLat = markerLat - offsetDistance; offsetLng = markerLng; break; case 270: offsetLat = markerLat; offsetLng = markerLng - offsetDistance; break; default: offsetLat = markerLat + offsetDistance; offsetLng = markerLng; break; } var newCenter = new google.maps.LatLng(offsetLat, offsetLng); map.setCenter(newCenter); var image1 = marker.image1; var image2 = marker.image2; var preview1 = $("#preview-" + id + "-1").attr('src'); var preview2 = $("#preview-" + id + "-2").attr('src'); if (preview1) { previewSrc1 = preview1; } if (preview2) { previewSrc2 = preview2; } var windowMarkerIcon = ''; var markerTypeName = markerTypes[marker.markerType]; var content = '
' + '
' + '
' + '
' + '' + windowMarkerIcon + '' + markerTypeName + '' + '
' + '
' + '
' + '
' + '

Change to New Issue:

' + '' + '
' + '
' + '
' + '
' + '

Priority: ' + severity_types[marker.severity] + '

' + '
' + '

' + '
' + '
'; if (marker.image1) { content = content + '
' + '
' + '
' + '' + '
' + '
'; } if (marker.image2) { content = content + '
' + '
' + '' + '
' + '
' + '
'; } if (!marker.image1 && !marker.image2) { content = content + '

No images were uploaded for this issue

'; } var descriptionContent; if (marker.markerDescription) { descriptionContent = marker.markerDescription; } else { descriptionContent = 'No description was given for this issue'; } content = content + '
' + '
' + '
' + '
' + '
' + '

' + descriptionContent + '

' + '
' + '
' + '
'; content = content + '
' + ''; infoWindow.setContent(content); infoWindow.setOptions({pixelOffset: new google.maps.Size(0, 0)}); // THis gets adjusted by opening polygon windows infoWindow.open(map, marker); currentMarker = marker.markerID; } function loadMobileReportMarkerWindow(markerId) { var marker = markers[markerId]; var markerTypeName = markerTypes[marker.markerType]; var severityId = marker.severity; var infoColor = markerColors[marker.markerTypeId]['color']; var infoTextColor = markerColors[marker.markerTypeId]['text_color']; $("#mobileMarkerInfo").find('.bg-info').css('background-color', infoColor); $("#mobileMarkerInfo").find('.bg-info').css('color', infoTextColor); $("#mobileMarkerId").text(marker.markerID); $("#mobileMarkerName").text(markerTypeName); $("#reportMarkerType").text(severity_types[marker.severity]); var content = ''; var previewSrc1 = '/addImage.png'; var image1 = false; var previewSrc2 = '/addImage.png'; var image2 = false; var preview1 = $("#preview-" + marker.markerID + "-1").attr('src'); var preview2 = $("#preview-" + marker.markerID + "-2").attr('src'); if (preview1) { previewSrc1 = preview1; var image1 = true; } if (preview2) { previewSrc2 = true; var image2 = true; } content = content + '
'; if (image1) { content = content + '
' + '
' + '' + '
' + '
'; } if (image2) { content = content + '
' + '
' + '' + '
' + '
'; } if (!image1 && !image2) { content = content + '

No images were uploaded for this issue.

'; } content = content + '
'; $("#mobileMarkerImages").html(content); var markerDescription = 'No description was given for this issue'; if (marker.markerDescription) { markerDescription = marker.markerDescription; } $("#mobileReportMarkerDescription").text(markerDescription); $("#mobileMarkerInfo").addClass('showMe'); } function loadReportPolygonWindow(zoneId) { if (isMobile()) { loadMobileReportZoneWindow(zoneId) return; } updatePolygonCounter(); currentPolygon = zoneId; var polygon = polygons[zoneId]; var offsetDistance; var mapZoom = map.getZoom(); var offsetLat; var offsetLng; var heading = map.getHeading(); var polygonLat = polygon.center.lat(); var polygonLng = polygon.center.lng(); goBackPosition = new google.maps.LatLng(polygonLat, polygonLng); switch (mapZoom) { case 20: offsetDistance = 0.0002; break; case 19: offsetDistance = 0.0004; break; case 18: offsetDistance = 0.0007; break; case 17: offsetDistance = 0.0015; break; case 16: offsetDistance = 0.0028; break; } switch (heading) { case 90: offsetLat = polygonLat; offsetLng = polygonLng + offsetDistance; break; case 180: offsetLat = polygonLat - offsetDistance; offsetLng = polygonLng; break; case 270: offsetLat = polygonLat; offsetLng = polygonLng - offsetDistance; break; default: offsetLat = polygonLat + offsetDistance; offsetLng = polygonLng; break; } var newCenter = new google.maps.LatLng(offsetLat, offsetLng); map.setCenter(newCenter); var previewSrc1 = '/addImage.png'; var image1 = false; var previewSrc2 = '/addImage.png'; var image2 = false; var preview1 = $("#previewPolygon-" + zoneId + "-1").attr('src'); var preview2 = $("#previewPolygon-" + zoneId + "-2").attr('src'); if (preview1) { previewSrc1 = preview1; var image1 = true; } if (preview2) { previewSrc2 = true; var image2 = true; } var content = '
' + '
' + '
' + '
' + 'Zone ' + String.fromCharCode(64 + polygon.polygonCounter) + ': ' + zoneTypes[polygon.typeId] + '' + '
' + '
'; content += '
' + '
' + '

Area: ' + commaSeparateNumber(polygon.area_ft) + ' ft2 / ' + commaSeparateNumber(polygon.area_yd) + ' yds2


' + '
' + '
'; if (image1) { content = content + '
' + '
' + '
' + '' + '
' + '
'; } if (image2) { content = content + '
' + '
' + '' + '
' + '
'; } if (!polygon.image1 && !polygon.image2) { content = content + '

No images were uploaded for this zone.

'; } var descriptionContent; if (polygon.polygonDescription) { descriptionContent = polygon.polygonDescription; } else { descriptionContent = 'No description was given for this zone'; } content += '
' + '

' + '

' + descriptionContent + '

' + '
' + '
' + '
' + '
' + '
'; infoWindow.setContent(content); infoWindow.setPosition(polygon.center); infoWindow.setOptions({pixelOffset: new google.maps.Size(-25, 0)}); // set the offset to get the clickable map --> by preeti infoWindow.open(map); } function loadMobileReportZoneWindow(zoneId) { polygon = polygons[zoneId]; var zoneLetter = String.fromCharCode(64 + polygon.polygonID); var zoneTypeId = polygon.typeId; var zoneTypeName = zoneTypes[zoneTypeId]; var infoColor = zoneColors[zoneTypeId][0]; var infoTextColor = zoneColors[zoneTypeId][2]; $("#mobileZoneInfo").find('.bg-info').css('background-color', infoColor); $("#mobileZoneInfo").find('.bg-info').css('color', infoTextColor); $("#mobileZoneId").text(zoneLetter); $("#mobileZoneName").text(zoneTypeName); $("#mobileZoneSelect").val(zoneTypeId); $("#mobileZoneDescription").val(polygon.polygonDescription); $("#mobileZoneAreaFt").text(commaSeparateNumber(polygon.area_ft)); $("#mobileZoneAreaYds").text(commaSeparateNumber(polygon.area_yd)); var content = ''; var previewSrc1 = '/addImage.png'; var image1 = false; var previewSrc2 = '/addImage.png'; var image2 = false; var preview1 = $("#previewPolygon-" + polygon.polygonID + "-1").attr('src'); var preview2 = $("#previewPolygon-" + polygon.polygonID + "-2").attr('src'); if (preview1) { previewSrc1 = preview1; var image1 = true; } if (preview2) { previewSrc2 = true; var image2 = true; } if (image1) { content = content + '
' + '
' + '
' + '' + '
' + '
'; } if (image2) { content = content + '
' + '
' + '' + '
' + '
' + '
'; } if (!image1 && !image2) { content = content + '

No images were uploaded for this issue.

'; } $("#mobileZoneImages").html(content); var zoneDescription = 'No description was given for this zone'; if (polygon.polygonDescription) { zoneDescription = polygon.polygonDescription; } $("#mobileZoneReportDescription").text(zoneDescription); $("#mobileZoneImages").html(content); $("#mobileZoneInfo").addClass('showMe'); } function loadMobileReportLineWindow(lineId) { var line = lines[lineId]; var lineLetter = String.fromCharCode(64 + line.lineID); var lineTypeId = line.typeId; var lineTypeName = lineTypes[lineTypeId]; var infoColor = lineColors[lineTypeId][0]; var infoTextColor = lineColors[lineTypeId][2]; $("#mobileLineInfo").find('.bg-info').css('background-color', infoColor); $("#mobileLineInfo").find('.bg-info').css('color', infoTextColor); $("#mobileLineId").text(lineLetter); $("#mobileLineName").text(lineTypeName); $("#mobileLineDescription").val(line.lineDescription); $("#mobileLineLengthFt").text(commaSeparateNumber(line.length_ft)); $("#mobileLineLengthYds").text(commaSeparateNumber(line.length_yd)); var content = ''; var previewSrc1 = '/addImage.png'; var image1 = false; var previewSrc2 = '/addImage.png'; var image2 = false; var preview1 = $("#previewLine-" + line.lineID + "-1").attr('src'); var preview2 = $("#previewLine-" + line.lineID + "-2").attr('src'); if (preview1) { previewSrc1 = preview1; var image1 = true; } if (preview2) { previewSrc2 = true; var image2 = true; } if (image1) { content = content + '
' + '
' + '
' + '' + '
' + '
'; } if (image2) { content = content + '
' + '
' + '' + '
' + '
' + '
'; } if (!image1 && !image2) { content = content + '

No images were uploaded for this issue.

'; } $("#mobileLineImages").html(content); var lineDescription = 'No description was given for this line'; if (line.lineDescription) { lineDescription = line.lineDescription; } $("#mobileLineReportDescription").text(lineDescription); $("#mobileLineImages").html(content); $("#mobileLineInfo").addClass('showMe'); } function isEven(x) { return !( x & 1 ); } $(".auditAddressTitle").textfill({ maxFontPixels: 17 }); function encodeReportImage() { var auditKey = $("#auditKey").val(); var defer = $.Deferred(); $(".preReportImage").show(); $(".postReportImage").hide(); $("#modalReportImage").modal('show'); html2canvas([$("#map")[0]], { logging: false, useCORS: true, onrendered: function (canvas) { var extra_canvas = document.createElement("canvas"); extra_canvas.setAttribute('width', 600); extra_canvas.setAttribute('height', 700); var ctx = extra_canvas.getContext('2d'); ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height, 0, 0, 600, 700); var dataURL = extra_canvas.toDataURL(); // We have the base64 - now send it to server $.ajax({ url: "/report/saveImage/" + auditKey, method: 'POST', data: { encodedImage: dataURL }, dataType: "json", timeout: 20000 }) .done(function (data) { if (data.success) { $("#reportImageFeedback").text('Your report is being downloaded'); $(".preReportImage").hide(); $(".postReportImage").show(); var currentUrl = window.location.href.replace("#", ''); window.location.href = currentUrl + '/print'; } else { $("#reportImageFeedback").text('There was an error generating your report'); $(".preReportImage").hide(); $(".postReportImage").show(); } defer.resolve(); }) .error(function () { defer.resolve(); $("#reportImageFeedback").text = 'There was an error generating your report'; $(".preReportImage").hide(); $(".postReportImage").show(); }); } }); return defer.promise(); } function isBase64(text) { return (text.indexOf('data:image') !== -1); } /** * Functions specifically for the report page */ markers = {}; markerCounter = 0; $("#map").html(''); defaultOptions.center = originalPosition; map = new google.maps.Map(document.getElementById('map'), defaultOptions); google.maps.event.addListenerOnce(map, 'idle', function () { //populate if there are saved markers for (i in prepopulatedMarkers) { var markerInfo = {}; markerInfo.markerType = 'marker-' + prepopulatedMarkers[i].type_id; markerInfo.markerTypeId = prepopulatedMarkers[i].type_id; markerInfo.position = new google.maps.LatLng(prepopulatedMarkers[i].lat, prepopulatedMarkers[i].lng); markerInfo.icon = markerIcon; markerInfo.icon['url'] = '/icon/' + icons[markerInfo.markerType]; markerInfo.description = prepopulatedMarkers[i].description; markerInfo.severity = prepopulatedMarkers[i].severity; markerInfo.image1 = prepopulatedMarkers[i].image1; markerInfo.image2 = prepopulatedMarkers[i].image2; addMarker(markerInfo, true); } //populate zones for (i in prepopulatedPolygons) { var path = new google.maps.MVCArray; for (j in prepopulatedPolygons[i].path) { var latLngData = prepopulatedPolygons[i].path[j]; path.push(new google.maps.LatLng(latLngData[Object.keys(latLngData)[0]], latLngData[Object.keys(latLngData)[1]])); } prepopulatedPolygons[i].path = path; addPolygon(prepopulatedPolygons[i], true); } // Lines for (i in prepopulatedLines) { var path = new google.maps.MVCArray; for (j in prepopulatedLines[i].path) { var latLngData = prepopulatedLines[i].path[j]; path.push(new google.maps.LatLng(latLngData[Object.keys(latLngData)[0]], latLngData[Object.keys(latLngData)[1]])); } prepopulatedLines[i].path = path; addLine(prepopulatedLines[i], true); } fitMap(); }); $("#setBounds").on('click', function () { fitMap(); return false; }); /* Toggle show/hide of "view" Dropdown */ $(document).ready(function(){ $('.listToggleHeader').delegate('input,label', 'click', function(e){ e.stopImmediatePropagation(); }).click(function(event){ var toggle_header = $(this); var toggle_target = toggle_header.data('target'); $(toggle_header).toggleClass('toggleHeaderShow'); $(toggle_target).toggleClass('toggleContentShow'); }); }); $(document).on('show.bs.collapse', ".mobileIssueCards .collapse", function() { $(".mobileIssueCards .collapse").collapse('hide'); var panel = $(this).parent()[0]; }); $(".reportSection a").click(function() { $(".reportSectionContent").collapse('hide'); $(this).collapse('show'); }); // Open up the window full-screen $('.showMapFullScreen').click(function() { $("#startPage").removeClass('showMe'); var center = map.getCenter(); $('#map-wrapper').addClass('mapFullScreen'); $('body').addClass('mapOpen'); // Hide scrollbars setTimeout(function(){ // Wait one second for animation to finish google.maps.event.trigger(map, 'resize'); // Update google maps map.setCenter(center); fitMap(); }, 1); }); $('#closeMapFullScreen').click(function() { $('#map-wrapper').removeClass('mapFullScreen'); $('body').removeClass('mapOpen'); // Show scrollbars $('#instructionsMapFullScreen').removeClass('showMe'); window.scrollTo(0, 0); }); /** Function to recenter the map based on items or initial location **/ $("#resetMap").click(function() { var totalIssues = issueCount(); if (totalIssues) { fitMap(true); } else { map.setCenter(locationMarker.position); } $("#mapMenu").dropdown('toggle'); return false; }); function showInfoWindowToolbar() { // Do nothing, this is a review function that gets called in mapping.js so it's also needed here // Not great, but it works. } function hideInfoWindowToolbar() { // See above } $(document).on('click', ".lineLabel", function(e) { var lineId = $(this).data('label-id'); new google.maps.event.trigger( lines[lineId], 'click', {} ); return false; }); // Keep the dropdown open after click events on the view menu $('#viewMenu .dropdown-menu').click(function(event){ event.stopPropagation(); }); // When view dropdown is to be shown, only show the checkboxes for the types that are on the map $('#viewMenu').on('show.bs.dropdown', function () { // Hide all $(".issueCheckBox").parents('li').hide(); $(".zoneCheckBox").parents('li').hide(); $(".lineCheckBox").parents('li').hide(); var drawnTypes = getDrawnTypes(); $(".issueCheckBox").each(function() { var typeId = parseInt($(this).val()); if (drawnTypes.issues.indexOf(typeId) !== -1) { $(this).parents('li').show(); } }); $(".zoneCheckBox").each(function() { var typeId = parseInt($(this).val()); if (drawnTypes.zones.indexOf(typeId) !== -1) { $(this).parents('li').show(); } }); $(".lineCheckBox").each(function() { var typeId = parseInt($(this).val()); if (drawnTypes.lines.indexOf(typeId) !== -1) { $(this).parents('li').show(); } }); }); // Keep the dropdown open after click events on the view menu $('#viewMenu .dropdown-menu').click(function(event){ event.stopPropagation(); }); // When view dropdown is to be shown, only show the checkboxes for the types that are on the map $('#viewMenu').on('show.bs.dropdown', function () { // Hide all $(".issueCheckBox").parents('li').hide(); $(".zoneCheckBox").parents('li').hide(); $(".lineCheckBox").parents('li').hide(); var drawnTypes = getDrawnTypes(); $(".issueCheckBox").each(function() { var typeId = parseInt($(this).val()); if (drawnTypes.issues.indexOf(typeId) !== -1) { $(this).parents('li').show(); } }); $(".zoneCheckBox").each(function() { var typeId = parseInt($(this).val()); if (drawnTypes.zones.indexOf(typeId) !== -1) { $(this).parents('li').show(); } }); $(".lineCheckBox").each(function() { var typeId = parseInt($(this).val()); if (drawnTypes.lines.indexOf(typeId) !== -1) { $(this).parents('li').show(); } }); }); $('#viewMenu').on('shown.bs.dropdown', function(){ $("#viewMenuControls").show(); }); $('#viewMenu').on('hide.bs.dropdown', function(){ $("#viewMenuControls").hide(); }); // Close it $("#closeViewMenu").click(function() { $('#viewMenu .dropdown-toggle').dropdown('toggle'); return false; }); $('#viewMenuAll').click(function() { $("#viewMenu input").prop('checked', true); return false; }); $('#viewMenuNone').click(function() { $("#viewMenu input").prop('checked', false); return false; }); // Handle 'all issues' being selected $('#viewAllIssues' ).on( 'change', function( event ) { // If checked, check all issues, otherwise uncheck all var checked = false; if ($(this).prop('checked')) { var checked = true; } $('.issueCheckBox').each(function() { $(this).prop('checked', checked); }); return false; }); // Handle individual issue checks $('#viewMenu input.issueCheckBox' ).on('change', function(event) { // If all are selected, check the all box above, otherwise uncheck it if ($('.issueCheckBox:checked').length == $('.issueCheckBox').length) { $("#viewAllIssues").prop('checked', true); } else { $("#viewAllIssues").prop('checked', false); } return false; }); // Handle 'all zones' being selected $('#viewAllZones').on( 'change', function( event ) { // If checked, check all issues, otherwise uncheck all var checked = false; if ($(this).prop('checked')) { var checked = true; } $('.zoneCheckBox').each(function() { $(this).prop('checked', checked); }); return false; }); // Handle individual issue checks $('#viewMenu input.zoneCheckBox' ).on('change', function(event) { // If all are selected, check the all box above, otherwise uncheck it if ($('.zoneCheckBox:checked').length == $('.zoneCheckBox').length) { $("#viewAllZones").prop('checked', true); } else { $("#viewAllZones").prop('checked', false); } return false; }); // Handle 'all lines' being selected $('#viewAllLines').on( 'change', function( event ) { // If checked, check all issues, otherwise uncheck all var checked = false; if ($(this).prop('checked')) { var checked = true; } $('.lineCheckBox').each(function() { $(this).prop('checked', checked); }); return false; }); // Handle individual line checks $('#viewMenu input.lineCheckBox' ).on('change', function(event) { // If all are selected, check the all box above, otherwise uncheck it if ($('.lineCheckBox:checked').length == $('.lineCheckBox').length) { $("#viewAllLines").prop('checked', true); } else { $("#viewAllLines").prop('checked', false); } return false; }); $("#applyViewChanges").click(function() { drawSelectedObjects(); updateViewMessage(); $('#viewMenu .dropdown-toggle').dropdown('toggle'); }); $("#reportAddressTitle").textfill({}); function setVisibleIssues() { visibleIssues.issues = []; visibleIssues.zones = []; visibleIssues.lines = []; // Issues $('.issueCheckBox').each(function() { if ($(this).prop('checked')) { visibleIssues.issues.push(parseInt($(this).val())); } }); // Zones $('.zoneCheckBox').each(function() { if ($(this).prop('checked')) { visibleIssues.zones.push(parseInt($(this).val())); } }); // Lines $('.lineCheckBox').each(function() { if ($(this).prop('checked')) { visibleIssues.lines.push(parseInt($(this).val())); } }); } function drawSelectedObjects() { setVisibleIssues(); var showIssues = []; var showZones = []; var showLines = []; // Issues if (visibleIssues.issues.length > 0) { for (i in visibleIssues.issues) { var issueTypeId = visibleIssues.issues[i]; for (i in markers) { markers[i].setMap(null); if (markers[i].markerTypeId == issueTypeId) { showIssues.push(markers[i]); } } for (i in showIssues) { showIssues[i].setMap(map); } } } else { for (i in markers) { markers[i].setMap(null); } } // Zones if (visibleIssues.zones.length > 0) { for (i in visibleIssues.zones) { var zoneTypeId = visibleIssues.zones[i]; for (i in polygons) { polygons[i].label.close(); polygons[i].setMap(null); if (polygons[i].typeId == zoneTypeId) { showZones.push(polygons[i]); } } for (i in showZones) { showZones[i].label.open(map); showZones[i].setMap(map); } } } else { for (i in polygons) { polygons[i].label.close(); polygons[i].setMap(null); } } // Lines if (visibleIssues.lines.length > 0) { for (i in visibleIssues.lines) { var lineTypeId = visibleIssues.lines[i]; for (i in lines) { lines[i].setMap(null); lines[i].label.close(); if (lines[i].typeId == lineTypeId) { showLines.push(lines[i]); } } for (i in showLines) { showLines[i].setMap(map); showLines[i].label.open(map); } } } else { for (i in lines) { lines[i].setMap(null); lines[i].label.close(); } } } function getDrawnTypes() { var types = {}; types.issues = []; types.zones = []; types.lines = []; /* These loops could be optimized to only add unique values */ for (i in markers) { var typeId = markers[i].markerTypeId; types.issues.push(typeId); } for (i in polygons) { var typeId = polygons[i].typeId; types.zones.push(typeId); } for (i in lines) { var typeId = lines[i].typeId; types.lines.push(typeId); } return types; } function updateViewMessage() { var visibleIssueChecks = $(".issueCheckBox:visible").length; var checkedVisibleIssueChecks = $(".issueCheckBox:visible:checked").length; var visibleZoneChecks = $(".zoneCheckBox:visible").length; var checkedVisibleZoneChecks = $(".zoneCheckBox:visible:checked").length; var visibleLineChecks = $(".lineCheckBox:visible").length; var checkedVisibleLineChecks = $(".lineCheckBox:visible:checked").length; var totalVisible = (visibleIssueChecks + visibleZoneChecks + visibleLineChecks); var totalChecked = (checkedVisibleIssueChecks + checkedVisibleZoneChecks + checkedVisibleLineChecks); if (totalChecked < totalVisible) { $("#viewNotice").show(); } else { $("#viewNotice").hide(); } } $("#issues").DataTable({ paging: false, info: false, lengthChange: false, searching: false, "columns": [ null, {'visible': combined }, null, null, {'sortable': false }, {'sortable': false } ] }); $("#issues-polygons, #issues-lines").DataTable({ paging: false, info: false, lengthChange: false, searching: false, "columns": [ null, {'visible': combined }, null, null, null, {'sortable': false, 'width': '285px' }, {'sortable': false, 'width': '300px' } ] }); });