var lineVertices = new Array(); var speedVertices = new Array( ); var player_map = { player_index : 0, head_color : "orange", head_html : "Up", indexOfLastPushpin : "", my_player_interval : "", player_speed_translate : { 1:20,2:19,3:18,4:17,5:16,6:15,7:14,8:13,9:12,10:11,11:10,12:9,13:8,14:7,15:6,16:5,17:4,18:3,19:2,20:1}, is_playing : false, player_speed : 10, polygon : Array(), polygon_e : Array(), pinInfobox : Array(), pinInfobox_e : Array(), line : Array(), client_id : "", nick : "", start_date : "", end_date : "", color_r : 255, color_g : 58, color_b : 58, color_o : 150, trigger_breadcrumbs : Array(), breadcrumbs_on : false, last_center : "", temp_play : false, step_back : false, speed_color_save : Array(), set_expansive : false, pull_labels : function(){ //player_map.polygon = Array(); $.ajax({ type: "get", url: "/grab_routes.php", data: {"search_type" : "get_geofences", "client_id" : global_client_id }, }).done(function(geofence_results){ var geofence_o = JSON.parse(geofence_results); var count = 0; for( geofence_k in geofence_o ){ if( player_map.set_expansive == true ){ var job_id = $('#map_expansive_geofence').val(); if( geofence_o[geofence_k].geonum != job_id ){ count++; continue; } else{ } } else{ if( geofence_o[geofence_k].expansive == '1'){ count++; continue; } } var point_a = Array(); var temp_point; if ( geofence_o[geofence_k].points.length != 0 ) { // look to see if job has geofence for( key in geofence_o[geofence_k].points ){ // record pushpins if ( key == 0 ){ //console.log( Number(geofence_o[geofence_k].points[key].lat) ); //console.log( Number(geofence_o[geofence_k].points[key].lon) ); //console.log( geofence_o[geofence_k].geoname); //console.log(count); player_map.pinInfobox[count] = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(Number(geofence_o[geofence_k].points[key].lat),Number( geofence_o[geofence_k].points[key].lon )), {title: geofence_o[geofence_k].geoname, visible: true, width : 120, height : 50}); } //temp_point = new Microsoft.Maps.Location(Number(geofence_o[geofence_k]['pt'+s+'a']),Number(geofence_o[geofence_k]['pt'+s+'o'])); //point_a[s-1] = temp_point; break; // This is only because we need the job name } //var polygoncolor = new Microsoft.Maps.Color(player_map.color_o,player_map.color_r,player_map.color_g,player_map.color_b); //player_map.polygon[count] = new Microsoft.Maps.Polygon(point_a,{fillColor: polygoncolor, strokeColor: polygoncolor }); //my_eag_map.entities.push(player_map.polygon[count]); //console.log(player_map.polygon[count]); //my_eag_map.entities.push(player_map.polygon[count]); //push labels // Create the info box for the pushpin //my_eag_map.entities.push(player_map.pinInfobox[count]); player_map.pinInfobox[count].setMap(my_eag_map); // Set the view //my_eag_map.setView({bounds: Microsoft.Maps.LocationRect.fromLocations(point_a)}); count++; } // of of check to see if job has a geofence } // make sure this is always set to false after putting geos on map //player_map.set_expansive = false; }); }, pull_geos : function(){ player_map.polygon = Array(); $.ajax({ type: "get", url: "/grab_routes.php", data: {"search_type" : "get_geofences", "client_id" : global_client_id }, }).done(function(geofence_results){ var geofence_o = JSON.parse(geofence_results); var count = 0; for( geofence_k in geofence_o ){ if( player_map.set_expansive == true ){ var job_id = $('#map_expansive_geofence').val(); if( geofence_o[geofence_k].geonum != job_id ){ count++; continue; } else{ } } else{ if( geofence_o[geofence_k].expansive == '1'){ count++; continue; } } var point_a = Array(); var temp_point; //console.log(geofence_o[geofence_k]); if( geofence_o[geofence_k].points.length != 0 ){ for( key in geofence_o[geofence_k].points ){ temp_point = new Microsoft.Maps.Location(Number(geofence_o[geofence_k].points[key].lat),Number(geofence_o[geofence_k].points[key].lon)); point_a[key] = temp_point; } var polygoncolor = new Microsoft.Maps.Color(player_map.color_o,player_map.color_r,player_map.color_g,player_map.color_b); player_map.polygon[count] = new Microsoft.Maps.Polygon(point_a,{fillColor: polygoncolor, strokeColor: polygoncolor }); my_eag_map.entities.push(player_map.polygon[count]); } //player_map.polygon[count].setMap(my_eag_map); //console.log(player_map.polygon[count]); //my_eag_map.entities.push(player_map.polygon[count]); //push labels // Create the info box for the pushpin //my_eag_map.entities.push(player_map.pinInfobox[count]); // Set the view //my_eag_map.setView({bounds: Microsoft.Maps.LocationRect.fromLocations(point_a)}); count++; } // make sure this is always set to false after putting geos on map player_map.set_expansive = false; }); }, pull_expansive_geos : function(){ player_map.polygon_e = Array(); $.ajax({ type: "get", url: "/expansive_geofences.txt", data: {"search_type" : "get_expansive_geofences", "client_id" : global_client_id }, }).done(function(geofence_results){ var geofence_o = JSON.parse(geofence_results); var count = 0; for( geofence_k in geofence_o ){ console.log('here'); var job_id = $('#map_expansive_geofence').val(); if( geofence_o[geofence_k].geonum != job_id ){ //count++; continue; } else{ } var point_a = Array(); var temp_point; //console.log(geofence_o[geofence_k]); if ( geofence_o[geofence_k].points.length != 0 ) { // look to see if job has geofence for( key in geofence_o[geofence_k].points ){ if ( key == 0){ player_map.pinInfobox_e[count] = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(Number( geofence_o[geofence_k].points[key].lat ),Number(geofence_o[geofence_k].points[key].lon)), {title: geofence_o[geofence_k].geoname, visible: true, width : 120, height : 50}); } temp_point = new Microsoft.Maps.Location(Number(geofence_o[geofence_k].points[key].lat),Number(geofence_o[geofence_k].points[key].lon)); point_a[key] = temp_point; } var polygoncolor = new Microsoft.Maps.Color(player_map.color_o,player_map.color_r,player_map.color_g,player_map.color_b); player_map.polygon_e[count] = new Microsoft.Maps.Polygon(point_a,{fillColor: polygoncolor, strokeColor: polygoncolor }); my_eag_map.entities.push(player_map.polygon_e[count]); //player_map.polygon_e[count].setMap(my_eag_map); //console.log(player_map.polygon_e[count]); //my_eag_map.entities.push(player_map.polygon_e[count]); //push labels // Create the info box for the pushpin my_eag_map.entities.push(player_map.pinInfobox_e[count]); // Set the view //my_eag_map.setView({bounds: Microsoft.Maps.LocationRect.fromLocations(point_a)}); count++; } } // make sure this is always set to false after putting geos on map player_map.set_expansive = false; }); }, init : function(){ $("input[name='geofence_color']").change(function(){ var rgb_value = $(this).val(); var rgb_value_a = rgb_value.split(","); player_map.color_r = rgb_value_a[0]; player_map.color_g = rgb_value_a[1]; player_map.color_b = rgb_value_a[2]; if( $(this).prop("checked") == true ){ for ( polygon_k in player_map.polygon ){ var indexOfPinToRemove = my_eag_map.entities.indexOf(player_map.polygon[polygon_k]); my_eag_map.entities.removeAt(indexOfPinToRemove); } player_map.pull_geos(); } }); $('#player_pause').click(function(){ if ( player_map.is_playing == true ){ clearInterval(player_map.my_player_interval); player_map.is_playing = false; } }); $('#player_fwd').click(function(){ if ( player_map.is_playing == true ){ player_map.player_index = player_map.player_index + 100; } }); $('#player_rew').click(function(){ if ( player_map.is_playing == true ){ player_map.player_index = player_map.player_index - 100; } }); $('#step_fwd').click(function(){ if ( player_map.is_playing != true ){ player_map.temp_play = true; player_map.play(); } }); $('#step_rew').click(function(){ if ( player_map.is_playing != true ){ player_map.player_index--; player_map.step_back = true; player_map.temp_play = true; player_map.play(); } }); $('#trigger_static_route').click(function(){ if( $(this).prop("checked") == false ){ for( key in player_map.line){ var indexOfPinToRemove = my_eag_map.entities.indexOf(player_map.line[key]); my_eag_map.entities.removeAt(indexOfPinToRemove); } } else{ // Add the polyline to the map for ( key in player_map.line){ my_eag_map.entities.push(player_map.line[key]); //GetMap(player_map.nick, player_map.client_id, player_map.start_date, player_map.end_date); } } }); $('#trigger_geofences').click(function(){ if( $(this).prop("checked") == false ){ for ( polygon_k in player_map.polygon ){ var indexOfPinToRemove = my_eag_map.entities.indexOf(player_map.polygon[polygon_k]); my_eag_map.entities.removeAt(indexOfPinToRemove); } /*for(pin_k in player_map.pinInfobox){ var indexOfLabelToRemove = my_eag_map.entities.indexOf(player_map.pinInfobox[pin_k]); my_eag_map.entities.removeAt(indexOfLabelToRemove); }*/ } else{ player_map.pull_geos(); } }); $('#trigger_geofence_labels').click(function(){ if( $(this).prop("checked") == false ){ /*for ( polygon_k in player_map.polygon ){ var indexOfPinToRemove = my_eag_map.entities.indexOf(player_map.polygon[polygon_k]); my_eag_map.entities.removeAt(indexOfPinToRemove); }*/ for(pin_k in player_map.pinInfobox){ //var indexOfLabelToRemove = my_eag_map.entities.indexOf(player_map.pinInfobox[pin_k]); //console.log( indexOfLabelToRemove ); //my_eag_map.entities.removeAt( indexOfLabelToRemove ); player_map.pinInfobox[pin_k].setMap(null); } } else{ player_map.pull_labels(); } }); $('#trigger_expansive_geofences').click(function(){ if( $(this).prop("checked") == false ){ for ( polygon_k in player_map.polygon_e ){ var indexOfPinToRemove = my_eag_map.entities.indexOf(player_map.polygon_e[polygon_k]); //var indexOfLabelToRemove = my_eag_map.entities.indexOf(player_map.pinInfobox[polygon_k]); my_eag_map.entities.removeAt(indexOfPinToRemove); //my_eag_map.entities.removeAt(indexOfLabelToRemove); } for(pin_k in player_map.pinInfobox_e){ var indexOfLabelToRemove = my_eag_map.entities.indexOf(player_map.pinInfobox_e[pin_k]); my_eag_map.entities.removeAt(indexOfLabelToRemove); } } else{ player_map.set_expansive = true; player_map.pull_expansive_geos(); } }); $('#trigger_breadcrumbs').click(function(){ if( $(this).prop("checked") == true ){ player_map.breadcrumbs_on = true; } else{ player_map.breadcrumbs_on = false; } }); }, play2 : function(){ if ( player_map.player_index == 0 ){ player_map.head_color = "orange"; player_map.head_html = "Up"; } //check to see if point index is active if ( lineVertices[player_map.player_index] == undefined ){ clearInterval(player_map.my_player_interval); return 1; } $( "#timeline_slider" ).slider( "option", "value", player_map.player_index ); // Retrieve the location of the map center var center = new Microsoft.Maps.Location ( lineVertices[player_map.player_index].latitude, lineVertices[player_map.player_index].longitude); // my_eag_map.getCenter(); // Add a pin to the center of the map, using a custom icon var sdir = lineVertices[player_map.player_index].gpsdir; // get rid of last push pin if ( player_map.indexOfLastPushpin != -1 ){ my_eag_map.entities.remove( player_map.indexOfLastPushpin ); } if( player_map.breadcrumbs_on == true ){ if( player_map.indexOfLastPushpin != -1 ){ var crumb = new Microsoft.Maps.Pushpin(player_map.last_center, {icon: 'images/breadcrumb.png', width: 10, height: 10, anchor : new Microsoft.Maps.Point(5,5) }); my_eag_map.entities.push(crumb); } player_map.last_center = center; } if ( ((sdir >= 0) && (sdir <= 22)) || ((sdir >= 337) && (sdir <= 360)) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowN.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if( (sdir >= 22) && (sdir <= 67) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowNE.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if ( (sdir > 67) && (sdir <= 112) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowE.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if ( (sdir > 112) && (sdir <= 157) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowSE.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if ( (sdir > 157) && (sdir <= 202) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowS.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if ( (sdir > 202) && (sdir <= 247) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowSW.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if ( (sdir > 247) && (sdir <= 292) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowW.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if ( (sdir > 292) && (sdir <= 337) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowNW.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } my_eag_map.entities.push(pin); // set index for next interval of push pin player_map.indexOfLastPushpin = pin; if( player_map.speed_color_save[player_map.player_index] == undefined ){ $('#white_box_speed').html('N/A mph'); } else{ $('#white_box_speed').html(player_map.speed_color_save[player_map.player_index].speed+' mph'); } $('#player_truck_time').html(lineVertices[player_map.player_index].gpstime); $('#white_box_truck_time').html(lineVertices[player_map.player_index].gpstime); // left gutter broom test if(lineVertices[player_map.player_index].gpsanalog02 == 0){ var left_color = "orange"; var left_html = "Up"; } else{ var left_color = "green"; var left_html = "Down"; } // right gutter broom/seat switch test if(lineVertices[player_map.player_index].gpsfunct03 == 0){ var right_color = "orange"; var right_html = "Up"; } else{ var right_color = "green"; var right_html = "Down"; } // ignition if(lineVertices[player_map.player_index].gpsfunct04 == 0){ var ignition_color = "orange"; var ignition_html = "Off"; } else{ var ignition_color = "green"; var ignition_html = "On"; } // head down test if(lineVertices[player_map.player_index].gpsfunct00 == 0){ player_map.head_color = "orange"; player_map.head_html = "Up"; } else{ player_map.head_color = "green"; player_map.head_html = "Down"; } // head up test if(lineVertices[player_map.player_index].gpsfunct02 == 0){ //var head_color = "orange"; //var head_html = "Up"; } else{ //player_map.head_color = "orange"; //player_map.head_html = "Up"; } //------------------------------------------------------- get the gutter broom up and down information $('#map_ignition_state').css( 'background-color',ignition_color); $('#gutter_br_table_left').css('background-color',left_color); $('#gutter_br_table_right').css('background-color',right_color); $('#head_down_table').css('background-color',player_map.head_color); $('#map_ignition_state').html(ignition_html); $('#gutter_br_table_left').html(left_html ); //lineVertices[player_map.player_index].gpsanalog02 $('#gutter_br_table_right').html(right_html ); //lineVertices[player_map.player_index].gpsfunct03 $('#head_down_table').html(player_map.head_html ); //lineVertices[player_map.player_index].gpsfunct00 + ' ' + lineVertices[player_map.player_index].gpsfunct02 my_eag_map.setView({ center: new Microsoft.Maps.Location(lineVertices[player_map.player_index].latitude, lineVertices[player_map.player_index].longitude ) }); if (player_map.step_back != true){ player_map.player_index++; } else{ player_map.step_back = false; } // temp play if ( player_map.temp_play == true ){ clearInterval(player_map.my_player_interval); player_map.is_playing = false; player_map.temp_play = false; } }, play : function(){ //alert( lineVertices[player_map.player_index].gpslat + ' ' + lineVertices[player_map.player_index].gpslon ); //var points_length = lineVertices.length; if ( player_map.is_playing == false ){ player_map.is_playing = true; if ( player_map.temp_play == true ){ player_map.play2(); } else{ player_map.my_player_interval = setInterval(function(){ player_map.play2(); /*if ( player_map.player_index == 0 ){ player_map.head_color = "orange"; player_map.head_html = "Up"; } //check to see if point index is active if ( lineVertices[player_map.player_index] == undefined ){ clearInterval(player_map.my_player_interval); return 1; } $( "#timeline_slider" ).slider( "option", "value", player_map.player_index ); // Retrieve the location of the map center var center = new Microsoft.Maps.Location ( lineVertices[player_map.player_index].latitude, lineVertices[player_map.player_index].longitude); // my_eag_map.getCenter(); // Add a pin to the center of the map, using a custom icon var sdir = lineVertices[player_map.player_index].gpsdir; // get rid of last push pin if ( player_map.indexOfLastPushpin != -1 ){ my_eag_map.entities.remove( player_map.indexOfLastPushpin ); } if( player_map.breadcrumbs_on == true ){ if( player_map.indexOfLastPushpin != -1 ){ var crumb = new Microsoft.Maps.Pushpin(player_map.last_center, {icon: 'images/breadcrumb.png', width: 10, height: 10, anchor : new Microsoft.Maps.Point(5,5) }); my_eag_map.entities.push(crumb); } player_map.last_center = center; } if ( ((sdir >= 0) && (sdir <= 22)) || ((sdir >= 337) && (sdir <= 360)) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowN.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if( (sdir >= 22) && (sdir <= 67) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowNE.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if ( (sdir > 67) && (sdir <= 112) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowE.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if ( (sdir > 112) && (sdir <= 157) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowSE.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if ( (sdir > 157) && (sdir <= 202) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowS.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if ( (sdir > 202) && (sdir <= 247) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowSW.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if ( (sdir > 247) && (sdir <= 292) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowW.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } else if ( (sdir > 292) && (sdir <= 337) ){ var pin = new Microsoft.Maps.Pushpin(center, {icon: '/images/arrowNW.png', width: 32, height: 32, anchor : new Microsoft.Maps.Point(16,16) }); } my_eag_map.entities.push(pin); // set index for next interval of push pin player_map.indexOfLastPushpin = pin; $('#player_truck_time').html(lineVertices[player_map.player_index].gpstime); $('#white_box_truck_time').html(lineVertices[player_map.player_index].gpstime); $('#white_box_speed').html(player_map.speed_color_save[player_map.player_index].speed+' mph'); // left gutter broom test if(lineVertices[player_map.player_index].gpsanalog02 == 0){ var left_color = "orange"; var left_html = "Up"; } else{ var left_color = "green"; var left_html = "Down"; } // right gutter broom test if(lineVertices[player_map.player_index].gpsfunct03 == 0){ var right_color = "orange"; var right_html = "Up"; } else{ var right_color = "green"; var right_html = "Down"; } // head down test if(lineVertices[player_map.player_index].gpsfunct00 == 0){ //var head_color = "orange"; //var head_html = "Up"; } else{ player_map.head_color = "green"; player_map.head_html = "Down"; } // head up test if(lineVertices[player_map.player_index].gpsfunct02 == 0){ //var head_color = "orange"; //var head_html = "Up"; } else{ player_map.head_color = "orange"; player_map.head_html = "Up"; } //------------------------------------------------------- get the gutter broom up and down information $('#gutter_br_table_left').css('background-color',left_color); $('#gutter_br_table_right').css('background-color',right_color); $('#head_down_table').css('background-color',player_map.head_color); $('#gutter_br_table_left').html(left_html ); //lineVertices[player_map.player_index].gpsanalog02 $('#gutter_br_table_right').html(right_html ); //lineVertices[player_map.player_index].gpsfunct03 $('#head_down_table').html(player_map.head_html ); //lineVertices[player_map.player_index].gpsfunct00 + ' ' + lineVertices[player_map.player_index].gpsfunct02 my_eag_map.setView({ center: new Microsoft.Maps.Location(lineVertices[player_map.player_index].latitude, lineVertices[player_map.player_index].longitude ) }); if (player_map.step_back != true){ player_map.player_index++; } else{ player_map.step_bacclass='lp_lead_field'k = false; in } // temp play if ( player_map.temp_play == true ){ clearInterval(player_map.my_player_interval); player_map.is_playing = false; player_map.temp_play = false; }*/ }, ( player_map.player_speed_translate[player_map.player_speed] * 100 ) ); }// end of no interval if statement }// end of if statement }// end of play function };// end of map object $(document).ready(function(){ player_map.init(); // disable tabs //alert('my alert'); //$('#tabs').tabs({disabled : [7]}); //$('#tabs').tabs({disabled : [7,8]}); }); var my_eag_map; function GetMapAll(client_all_id, truck_watch_vehicle_class){ $('#white_box').css('visibility','hidden'); $.ajax({ type: "get", url: "/grab_routes.php", data: {"search_type" : "get_all_trucks", "client_id" : client_all_id, "active_colors" : routes_Search.active_colors, "truck_watch_vehicle_class" : truck_watch_vehicle_class }, }).done(function(point_results){ var results_a = point_results.split("--MMTTNNSS--"); var point_o = JSON.parse( results_a[0] ); var center_a = JSON.parse( results_a[1] ); var map_options = { credentials:"AghkdaMkXBTK5PuzNdtokhDnEx0ncK6jl9G0MVOuSQcADAnKSNa8I1dX3-GpAr3i", strokeColor:new Microsoft.Maps.Color(200, 255, 86, 86), mapTypeId: Microsoft.Maps.MapTypeId.aerial, zoom : 16, center: new Microsoft.Maps.Location(center_a[0], center_a[1] ), strokeThickness:5 }; my_eag_map = new Microsoft.Maps.Map(document.getElementById("eag_div"), map_options); //alert(point_o[0].Latitude); for( point_v in point_o ){ if ( point_o[point_v].color == '' || point_o[point_v].color == null){ var point_color = 'white'; } else{ var point_color = point_o[point_v].color; } var point = new Microsoft.Maps.Location ( point_o[point_v].Latitude, point_o[point_v].Longitude); // point_color //console.log('images/'+point_color+'-dot.png'); //console.log(point); var text_color = 'white'; if( point_color == 'yellow' ){ text_color = 'black'; } else{ text_color = 'white'; } console.log('point color' + point_color +'text' + text_color); var current_trucks = new Microsoft.Maps.Pushpin(point, { color : '#000000', 'typeName' : 'truck_label', width: 100, height: 20, anchor : new Microsoft.Maps.Point(0,0), icon : '' + point_o[point_v].fleetio_match + '' }); //var current_trucks = new Microsoft.Maps.Pushpin(point, {'text' : point_o[point_v].fleetio_match, 'color' : 'black', 'typeName' : 'truck_label', 'icon': 'images/'+point_color+'-dot.png', width: 100, height: 20, anchor : new Microsoft.Maps.Point(0,0) }); my_eag_map.entities.push(current_trucks); } }); } function GetMap(vehicle, client_id, start_date_time, end_date_time ) { player_map.polygon = Array(); lineVertices = new Array(); $('#geofence_color_red').prop('checked', true); $('#white_box').css('visibility','visible'); //alert(vehicle + client_id + start_date_time, end_date_time); // get the points for route // get expansive geofences $.ajax({ type: "get", url: "/expansive_geofences.txt", data: {"search_type" : "get_expansive_geofences", "client_id" : client_id } }).done(function(geo_result){ var result_a = JSON.parse(geo_result); var adder = ''; for( r_key in result_a ){ adder += ""; } $('#map_expansive_geofence').html(adder); }); // end get expansive geofences $("#global_message").html("Pulling map info!........"); $("#global_message").show('fast'); $.ajax({ type: "get", url: "/route_points_map.txt", data: {"search_type" : "get_route_points_map", "vehicle" : vehicle, "client_id" : client_id, "start_date_time" : start_date_time, "end_date_time" : end_date_time, "offset" : , "timezone" : "" }, }).done(function(point_results){ $('#global_message').hide('slow'); var point_o = JSON.parse(point_results); // set slider value $( "#speed_slider" ).slider( "option", "value", player_map.player_speed ); //if ( point_key == 0 ){ var first_point_lat = point_o[0].ga; // gpslat var first_point_lon = point_o[0].go; // gpslon var first_time = point_o[0].gt; // gpstime var first_name = point_o[0].nk; // Nickname var first_unit = point_o[0].unit_id; //} var map_options = { credentials:"AghkdaMkXBTK5PuzNdtokhDnEx0ncK6jl9G0MVOuSQcADAnKSNa8I1dX3-GpAr3i", strokeColor:new Microsoft.Maps.Color(200, 255, 86, 86), mapTypeId: Microsoft.Maps.MapTypeId.aerial, zoom : 16, center: new Microsoft.Maps.Location(first_point_lat, first_point_lon), strokeThickness:5 }; my_eag_map = new Microsoft.Maps.Map(document.getElementById("eag_div"), map_options); var prev_loc; var tempVertices = Array(); var switchVertices = false; var cur_speed = 0; var switch_count = 0; var lazy_scroll_index = 0; speed_count = 0; var speed_color = new Array(); lineVertices = new Array(); speed_color[switch_count] = { "r" : 220, "g" : 20, "b" : 20 }; for ( point_key in point_o ){ if(routes_Search.lazy_scroll == true){ //console.log(point_o[point_key].gpstime + ' ' + routes_Search.event_time); if ( point_o[point_key].gt == routes_Search.event_time ){ //alert('got it'); lazy_scroll_index = point_key; } } if ( point_o[point_key].ga == "" || point_o[point_key].go == undefined ){ continue; } var location1 = new Microsoft.Maps.Location( point_o[point_key].ga, point_o[point_key].go ); // put up stop signs if( point_o[point_key].stop == true){ var stop_sign = new Microsoft.Maps.Pushpin( location1, {icon: 'images/s_sign.png', width: 10, height: 10, anchor : new Microsoft.Maps.Point(5,5) }); my_eag_map.entities.push(stop_sign); (function(){ var f_start_time = point_o[point_key].start_time; //console.log(f_start_time); var f_stop_time = point_o[point_key].stop_time; Microsoft.Maps.Events.addHandler( stop_sign, 'click', function(){ $('#global_message').html("Stop Started: "+f_start_time+"
Stop Ended: "+f_stop_time); $('#global_message').show('slow'); setTimeout(function(){ $('#global_message').hide('slow'); },4000); }); })(); } // end put up stop signs location1.gpsdir = point_o[point_key].gd; // gpsdir location1.gpstime = point_o[point_key].gt; // gpstime location1.speed = point_o[point_key].sp; // speed //left gutter broom location1.gpsanalog02 = point_o[point_key].ga02; // gpsanalog02 //right gutter broom location1.gpsfunct03 = point_o[point_key].gf03; // gpsfunct03 //head down location1.gpsfunct00 = point_o[point_key].gf00; // gpsfunct00 //head up location1.gpsfunct02 = point_o[point_key].gf02; // gpsfunct02 //if ( (point_key != 0) && (location1.gpstime == prev_loc.gpstime) ){ // prev_loc = location1; // continue; //} lineVertices[point_key] = location1; /* var speed = point_o[point_key].gpsanalog04; var rrr = 0; var ggg = 0; var bbb = 0; if ( (speed <= 5) && (cur_speed != 1) ){ rrr = 220; ggg = 20; bbb = 20; cur_speed = 1; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb }; } else if( (speed >= 6) && (speed <= 10) && (cur_speed != 2)){ rrr = 255; ggg = 100; bbb = 0; cur_speed = 2; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb }; } else if( (speed >= 11) && (speed <= 15) && (cur_speed != 3)){ rrr = 255; ggg = 165; bbb = 0; cur_speed = 3; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb }; } else if( (speed >= 16) && (speed <= 20) && (cur_speed != 4)){ rrr = 255; ggg = 255; bbb = 0; cur_speed = 4; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb }; } else if( (speed >= 21) && (speed <= 30) && (cur_speed != 5)){ rrr = 170; ggg = 255; bbb = 60; cur_speed = 5; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb }; } else if( (speed >= 31) && (speed <= 40) && (cur_speed != 6)){ rrr = 85; ggg = 255; bbb = 0; cur_speed = 6; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb }; } else if( (speed >= 41) && (speed <= 50) && (cur_speed != 7)){ rrr = 0; ggg = 255; bbb = 0; cur_speed = 7; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb }; } else if( (speed >= 51) && (speed <= 60) && (cur_speed != 8)){ rrr = 0; ggg = 192; bbb = 0; cur_speed = 8; switchVertices = true; switch_count++; speed_color[switch_count] = {"r" : rrr, "g" : ggg, "b" : bbb }; } else if( (speed >= 61) && (speed <= 70) && (cur_speed != 9)){ rrr = 0; ggg = 128; bbb = 0; cur_speed = 9; switchVertices = true; switch_count++; speed_color[switch_count] = {"r" : rrr, "g" : ggg, "b" : bbb }; } */ /*if( switchVertices == true ){ speedVertices[switch_count] = Array(); speed_count = 0; }*/ //speedVertices[switch_count][speed_count] = location1; //switchVertices = false; if( point_key != 0 ){ //tempVertices[0] = prev_loc; //tempVertices[1] = location1; } prev_loc = location1; var last_time = point_o[point_key].gt; // gpstime speed_count++; if ( point_key != 0 ){ //var lineVertices = new Array(location1, location2, location3, location4, location5); //player_map.line[point_key] = new Microsoft.Maps.Polyline(tempVertices, map_options); //my_eag_map.entities.push(player_map.line[point_key]); } if(point_key == 200){ //break; } } //player_map.line = new Microsoft.Maps.Polyline(lineVertices, map_options); //my_eag_map.entities.push(player_map.line); for( color_key in lineVertices){ if ( color_key != 0){ /*var distance = haversineDistance(Array(lineVertices[color_key-1].longitude,lineVertices[color_key-1].latitude),Array(lineVertices[color_key].longitude,lineVertices[color_key].latitude),true); var start_secs = Date.parse(lineVertices[color_key-1].gpstime) / 1000; var end_secs = Date.parse(lineVertices[color_key].gpstime) / 1000; var total_secs = end_secs - start_secs; if (total_secs == 0 ){ continue; } //var mph = ( distance / total_secs ) * 3600; */ var mph = lineVertices[color_key].speed; //console.log(mph); var speed = Math.round(mph); var rrr = 0; var ggg = 0; var bbb = 0; if ( (speed <= 5) ){ rrr = 220; ggg = 20; bbb = 20; cur_speed = 1; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb, "speed" : speed }; } else if( (speed >= 6) && (speed <= 10) ){ rrr = 255; ggg = 100; bbb = 0; cur_speed = 2; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb, "speed" : speed }; } else if( (speed >= 11) && (speed <= 15) ){ rrr = 255; ggg = 165; bbb = 0; cur_speed = 3; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb, "speed" : speed }; } else if( (speed >= 16) && (speed <= 20) ){ rrr = 255; ggg = 255; bbb = 0; cur_speed = 4; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb, "speed" : speed }; } else if( (speed >= 21) && (speed <= 30) ){ rrr = 170; ggg = 255; bbb = 60; cur_speed = 5; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb, "speed" : speed }; } else if( (speed >= 31) && (speed <= 40) ){ rrr = 85; ggg = 255; bbb = 0; cur_speed = 6; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb, "speed" : speed }; } else if( (speed >= 41) && (speed <= 50) ){ rrr = 0; ggg = 255; bbb = 0; cur_speed = 7; switchVertices = true; switch_count++; speed_color[switch_count] = { "r" : rrr, "g" : ggg, "b" : bbb, "speed" : speed }; } else if( (speed >= 51) && (speed <= 60)){ rrr = 0; ggg = 192; bbb = 0; cur_speed = 8; switchVertices = true; switch_count++; speed_color[switch_count] = {"r" : rrr, "g" : ggg, "b" : bbb , "speed" : speed}; } else if( (speed >= 61) && (speed <= 70) ){ rrr = 0; ggg = 128; bbb = 0; cur_speed = 9; switchVertices = true; switch_count++; speed_color[switch_count] = {"r" : rrr, "g" : ggg, "b" : bbb, "speed" : speed }; } var map_options = { credentials:"AghkdaMkXBTK5PuzNdtokhDnEx0ncK6jl9G0MVOuSQcADAnKSNa8I1dX3-GpAr3i", strokeColor:new Microsoft.Maps.Color(200, rrr, ggg, bbb), mapTypeId: Microsoft.Maps.MapTypeId.aerial, zoom : 16, center: new Microsoft.Maps.Location(first_point_lat, first_point_lon), strokeThickness:5 }; player_map.line[color_key] = new Microsoft.Maps.Polyline(Array(lineVertices[color_key-1],lineVertices[color_key]), map_options); my_eag_map.entities.push(player_map.line[color_key]); } } player_map.speed_color_save = speed_color; /*for ( color_key in speedVertices ){ map_options = { credentials:"AghkdaMkXBTK5PuzNdtokhDnEx0ncK6jl9G0MVOuSQcADAnKSNa8I1dX3-GpAr3i", strokeColor:new Microsoft.Maps.Color(200, speed_color[color_key].r, speed_color[color_key].g, speed_color[color_key].b), mapTypeId: Microsoft.Maps.MapTypeId.aerial, zoom : 16, center: new Microsoft.Maps.Location(first_point_lat, first_point_lon), strokeThickness:5 }; player_map.line = new Microsoft.Maps.Polyline(speedVertices[color_key], map_options); my_eag_map.entities.push(player_map.line); if (color_key == 28){ //break; } }*/ $('#player_truck_time').html(first_time); $('#player_truck_name').html(first_name); $('#player_truck_name').attr('unit_id', first_unit); $('#player_start_time').html(first_time); $('#player_end_time').html(last_time); //$('#view_player_speed').html(player_map.player_speed); // bind player buttons $('#player_play').click(function(){ player_map.play(); }); // bind player buttons $('#map_save_permanently').off("click"); $('#map_save_permanently').click(function(){ var client_id = ; var truck_name = $('#player_truck_name').attr('unit_id'); var player_start_time = $('#player_start_time').html(); var player_end_time = $('#player_end_time').html(); var slice_name = $('#map_save_permanently_name').val(); if ( slice_name == '' ){ $('#global_message').html(); $('#global_message').shaw(); setTimeout(function(){ $('#global_message').hide(); }, 2000); } else{ $('#global_message').html("Saving permanent slice..."); $('#global_message').show(); $.ajax({ type: "post", url: "/grab_routes4.php", data: {"search_type" : "save_permanent_route", "client_id" : client_id, "truck_name" : truck_name, "player_start_time" : player_start_time, "player_end_time" : player_end_time, "slice_name" : slice_name } }).done(function(geo_result){ if ( geo_result == 'success' ){ $('#global_message').hide(); } }); } }); // set time slider $(function() { $( '#timeline_slider' ).slider({ min : 1, max : lineVertices.length - 1, slide : function(event, ui){ var slider_value = $('#timeline_slider').slider('option', 'value'); //player_map.player_speed = slider_value; //console.log( player_map.player_speed + ' ' ); //console.log( player_map.is_playing + ' '); //$('#view_player_speed').html(player_map.player_speed); //console.log( slider_value ); if ( player_map.is_playing == true ){ //console.log('true'); // if map is playing cancel it. why would the map need to play and drag at the same time. clearInterval(player_map.my_player_interval); player_map.is_playing = false; // end cancel playing. // this was added because is_playing was getting stuck on true and slider was not working player_map.player_index = slider_value; //player_map.player_index = false; } else{ //console.log('false'); player_map.player_index = slider_value; player_map.temp_play = true; player_map.play(); } } }); }); if( routes_Search.lazy_scroll == true){ routes_Search.lazy_scroll = false; var slider_value = lazy_scroll_index; //alert (lazy_scroll_index); if ( player_map.is_playing == true ){ player_map.player_index = slider_value; //player_map.player_index = false; } else{ //alert('test'); player_map.player_index = slider_value; player_map.temp_play = true; player_map.play(); } } //var current_trucks = new Microsoft.Mapsi.Pushpin(player_map.last_center, {icon: 'images/breadcrumb.png', width: 10, height: 10, anchor : new Microsoft.Maps.Point(5,5) }); my_eag_map.entities.push(current_trucks); });// end of map done }