var global_map_icon_directory = "itecs"; if($("#icon_map_directory").length > 0) global_map_icon_directory = $("#icon_map_directory").html(); //opt = change the behaviour of function in relationship to //whic part of code calls it //ie opt = ontop => marker on top function create_info_box(mappa,point,html,icona,targa,opt) { var marker; var extra_desc ="Posizione del veicolo "; if(opt == null || opt =="") marker = new GMarker(point,icona); else if(opt.indexOf("ontop") !=-1) marker = new GMarker(point,{icon:icona,zIndexProcess:onTop}); else if(opt.indexOf("paziente") !=-1) { marker = new GMarker(point,icona); extra_desc = ""; } /* var point_label = new GLatLng(point.lat(),(point.lng()/2)); */ var html_fisso = "
"; //var html_dom = html_fisso+html+"
"; GEvent.addListener(marker, "click", function() { var tab1 = new GInfoWindowTab("Info", '
'+html+'
'); var tab2 = new GInfoWindowTab("Mappa", '
'+extra_desc+targa+'
'); // var infoTabs = [tab1,tab2]; marker.zIndexProcess = onTop(marker); marker.openInfoWindowTabsHtml(infoTabs); }); //We have to draw the detail map only when the infowindow was opened and so created, anyway the div detail map is mot creayed GEvent.addListener(marker, "infowindowopen", function() { //var label = new ELabel(point, targa, "style1", new GSize(0,18), 75 ); var dMapDiv = document.getElementById("detailmap"); var detailMap = new GMap2(dMapDiv); //for some strange reason if I put the detail map in the second tab it is not center in the marker, //so I have to center it by Pan var panMap = new GSize(125,90); bounds = new GLatLngBounds(point); detailMap.setCenter(bounds.getCenter()); detailMap.setZoom(detailMap.getBoundsZoomLevel(bounds)); detailMap.panBy(panMap); //detailMap.addControl(new GSmallMapControl()); detailMap.enableScrollWheelZoom(); detailMap.addControl(new GMenuMapTypeControl()); var sub_marker = new GMarker(point); detailMap.addOverlay(sub_marker); //detailMap.addOverlay(label); var CopyrightDiv = dMapDiv.firstChild.nextSibling; var CopyrightImg = dMapDiv.firstChild.nextSibling.nextSibling; CopyrightDiv.style.display = "none"; CopyrightImg.style.display = "none"; }); return marker; } function open_marker(indice) { if (global_array_marker[indice] != null) { bounds = new GLatLngBounds(global_array_marker[indice].getLatLng()); global_mapfleet.setCenter(bounds.getCenter()); global_mapfleet.setZoom(global_mapfleet.getBoundsZoomLevel(bounds)); GEvent.trigger(global_array_marker[indice], "click"); } } function create_icon (img) { var icon = new GIcon(); icon.image = "/ctwebinterface/imgmyfleet/icons/icon_map/"+global_map_icon_directory+"/"+img; icon.iconSize = new GSize(24, 39); icon.iconAnchor = new GPoint(12,39); icon.infoWindowAnchor = new GPoint(12, 5); return icon; } function select_icon_truck (direzione, digital_in,hardware,icona) { if (digital_in >= 8) //veicolo acceso { if (hardware != "GHT") { if ((icona == "default") || (typeof icona == "Undefined")) //trattore semplice { if (direzione >=0 && direzione <=90) return create_icon('camion_on_ne.png'); else if (direzione >90 && direzione <=180) return create_icon('camion_on_se.png'); else if (direzione >180 && direzione <=270) return create_icon('camion_on_sw.png'); else if (direzione >270 && direzione <=360) return create_icon('camion_on_nw.png'); } else if (icona == "rimorchio") //rimorchio { return create_icon('rimorchio_on.png'); } else if (icona == "mterra") //macchine movimento terra { return create_icon('mterra_on.png'); } } else //è un personal tracker return create_icon('man_on.png'); } else //veicolo spento { if (hardware != "GHT") { if ((icona == "default") || (typeof icona == "Undefined")) { if (direzione >=0 && direzione <=90) return create_icon('camion_off_ne.png'); else if (direzione >90 && direzione <=180) return create_icon('camion_off_se.png'); else if (direzione >180 && direzione <=270) return create_icon('camion_off_sw.png'); else if (direzione >270 && direzione <=360) return create_icon('camion_off_nw.png'); } else if (icona == "rimorchio") //rimorchio { return create_icon('rimorchio_off.png'); } else if (icona == "mterra") //macchine movimento terra { return create_icon('mterra_off.png'); } } else //è un personal tracker return create_icon('man_off.png'); } } //takes a marker and bind on it ,on click, an ifobox with 2 tabs: //one with description canned in html and one with a zoomed map //SOPPIANATAT DA create_info_box /* function add_info_box(marker,html) { /* var html_fisso = "
"; var html_dom = html_fisso+html+"
"; GEvent.addListener(marker, "click", function() { var tab1 = new GInfoWindowTab("Info", '
'+html+'
'); var tab2 = new GInfoWindowTab("Mappa", '
'); var infoTabs = [tab1,tab2]; marker.openInfoWindowTabsHtml(infoTabs); var dMapDiv = document.getElementById("detailmap"); var detailMap = new GMap2(dMapDiv); var point = marker.getPoint(); bounds = new GLatLngBounds(point); detailMap.setCenter(bounds.getCenter()); detailMap.setZoom(detailMap.getBoundsZoomLevel(bounds)); detailMap.addControl(new GSmallMapControl()); var sub_marker = new GMarker(point); detailMap.addOverlay(sub_marker); /* GEvent.addListener(detailMap, "zoomend", miniMapZoomEnd); GEvent.addListener(detailMap, "moveend", miniMapMoveEnd); var CopyrightDiv = dMapDiv.firstChild.nextSibling; var CopyrightImg = dMapDiv.firstChild.nextSibling.nextSibling; CopyrightDiv.style.display = "none"; CopyrightImg.style.display = "none"; }); } */ function hide_marker(indice) { if (global_array_marker[indice].isHidden()) { global_array_marker[indice].show(); global_array_label[indice].show(); } else { global_array_marker[indice].hide(); global_array_label[indice].hide(); } } /*function open_info_box (marker,html,direzione,digital_in,idterminale) { /* var icona = select_icon_truck(direzione,digital_in,idterminale); * var tab1 = new GInfoWindowTab("Info", '
'+html+'
'); var tab2 = new GInfoWindowTab("Mappa", '
'); var infoTabs = [tab1,tab2]; marker.openInfoWindowTabsHtml(infoTabs); var dMapDiv = document.getElementById("detailmap"); var detailMap = new GMap2(dMapDiv); var point = marker.getPoint(); bounds = new GLatLngBounds(point); detailMap.setCenter(bounds.getCenter()); detailMap.setZoom(detailMap.getBoundsZoomLevel(bounds)); //detailMap.addControl(new GSmallMapControl()); var sub_marker = new GMarker(point); detailMap.addOverlay(sub_marker); /* GEvent.addListener(detailMap, "zoomend", miniMapZoomEnd); GEvent.addListener(detailMap, "moveend", miniMapMoveEnd); * var CopyrightDiv = dMapDiv.firstChild.nextSibling; var CopyrightImg = dMapDiv.firstChild.nextSibling.nextSibling; CopyrightDiv.style.display = "none"; CopyrightImg.style.display = "none"; }*/ function initialize(dom_element) { var mp = new GMap2(document.getElementById(dom_element)); mp.enableContinuousZoom(); mp.enableDoubleClickZoom(); mp.enableScrollWheelZoom(); mp.addControl(new GMapTypeControl()); mp.addControl(new GScaleControl()); mp.addControl(new GLargeMapControl()); mp.addMapType(G_SATELLITE_3D_MAP); /* mp.addControl(new google.maps.LocalSearch()); */ //mp.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20))); mp.setCenter(new GLatLng(45.23872577078619,11.762773990631104), 5); bounds = new GLatLngBounds(); global_mgr_fleet = new MarkerManager(mp); /* mp.setCenter(bounds.getCenter()); mp.setZoom(mp.getBoundsZoomLevel(bounds)); */ return mp; } function initialize_simple(dom_element) { var mp = new GMap2(document.getElementById(dom_element)); mp.enableContinuousZoom(); mp.enableDoubleClickZoom(); mp.enableScrollWheelZoom(); mp.addControl(new GSmallMapControl()); mp.setCenter(new GLatLng(45.23872577078619,11.762773990631104), 5); bounds = new GLatLngBounds(); return mp; } /*function draw_points (mappa,json,tipo) { //console.profile('Measuring time points'); /* console.log("tipo :"+tipo); console.log("load_data"); **** if (json.result != 'empty') { /* if(tipo == "add") { global_mgr_fleet = new MarkerManager(mappa); } **** if (tipo == "update") { //mappa.clearOverlays(); if(global_mgr_fleet!=null) { global_mgr_fleet.clearMarkers(); } } for (var i = 0; i < json.result; i++) //json.length { //console.log(global_json.dati[i].longitudine +" "+global_json.dati[i].latitudine); if(json.dati[i].longitudine!="" && json.dati[i].longitudine!=null && json.dati[i].latitudine!="" && json.dati[i].latitudine!=null && json.dati[i].latitudine!=0) { var point = new GLatLng(json.dati[i].latitudine,json.dati[i].longitudine); var point_label = new GLatLng(point.lat(),(point.lng()/2)); bounds.extend(point); var html = ""; html+= "Targa: "+json.dati[i].name+"
"; html+= "Data/ora: "+json.dati[i].datadb+"
"; html+= "Indirizzo (zona): "+json.dati[i].indirizzo+"
"; if(json.dati[i].indirizzo_zone!=null && json.dati[i].indirizzo_zone!="" ) html+=" ("+json.dati[i].indirizzo_zone+")
"; html+= "Velocità: "+json.dati[0].velocita+" Km/h
"; html+= "Batteria: "+json.dati[i].batteria+" %
"; // Crea l'icona personalizzata var icona = select_icon_truck(json.dati[i].direzione, json.dati[i].digital_in,json.dati[i].hardware); json.dati[i].marker = create_info_box(mappa,point,html,icona,json.dati[i].name); //mappa.addOverlay(json.dati[i].marker); global_mgr_fleet.addMarker(json.dati[i].marker,3); json.dati[i].html = html; var label = new ELabel(point, json.dati[i].name, "style1", new GSize(0,18), 75 ); //mappa.addOverlay(label); global_mgr_fleet.addMarker(label,3); } } if (tipo == "add") //se il tipo è update, non faccio il setCenter e il setZoom { mappa.setCenter(bounds.getCenter()); mappa.setZoom(mappa.getBoundsZoomLevel(bounds)); } global_mgr_fleet.refresh(); return json; } //console.profileEnd(); }*/ function remove_event_for_marker (marker) { GEvent.clearListeners(marker,"click"); GEvent.clearListeners(marker, "infowindowopen"); } /* funzione utilizzate dalla generalmap per disegnare, uno alla volta, un array di punti */ function draw_point_map (mappa,dat,tipo,indice) { if (dat.longitudine!="" && dat.longitudine!=null && dat.latitudine!="" && dat.latitudine!=null && dat.latitudine!=0) { var point = new GLatLng(dat.latitudine,dat.longitudine); //var point_label = new GLatLng(point.lat(),(point.lng()/2)); bounds.extend(point); var html = ""; html+= "Targa: "+dat.name+"
"; html+= "Data/ora: "+dat.datadb+"
"; html+= "Indirizzo (zona): "+dat.indirizzo+"
"; if(dat.indirizzo_zone!=null && dat.indirizzo_zone!="" ) html+=" ("+dat.indirizzo_zone+")
"; html+= "Velocità: "+dat.velocita+" Km/h
"; html+= "Batteria: "+dat.batteria+" %
"; // Crea l'icona personalizzata var icona = select_icon_truck(dat.direzione, dat.digital_in,dat.hardware, dat.icona); //var marker = new GMarker(point,icona); dat.html = html; //eseguo la pulizia di eventuali eventMarker precedenti if (global_array_marker[indice] != null) { remove_event_for_marker(global_array_marker[indice]); global_mgr_fleet.removeMarker(global_array_marker[indice]); } dat.marker = create_info_box(mappa,point,html,icona,dat.name); global_mgr_fleet.addMarker(dat.marker,3); dat.label = new ELabel(point, dat.name, "style1", new GSize(0,18), 75 ); global_mgr_fleet.addMarker(dat.label,10); } else { //eseguo la pulizia di eventuali eventMarker precedenti if (global_array_marker[indice] != null) { remove_event_for_marker(global_array_marker[indice]); global_mgr_fleet.removeMarker(global_array_marker[indice]); dat.marker = null; dat.html = null; dat.label = null; } } return dat; } /* funzione utilizzate dalla mapvehicle per disegnare un singolo punto sulla mappa */ function draw_single_point (mappa,json) { if (json.result != 'empty') { if(json.dati[0].longitudine!="" && json.dati[0].longitudine!=null && json.dati[0].latitudine!="" && json.dati[0].latitudine!=null && json.dati[0].latitudine!=0) { var point = new GLatLng(json.dati[0].latitudine,json.dati[0].longitudine); bounds.extend(point); var html = ""; var option =""; if(json.dati[0].name!= null) html+= "Targa: "+json.dati[0].name+"
"; if(json.dati[0].name_rubrica!= null) { html+= "Nome: "+json.dati[0].name_rubrica+"
"; option = "paziente"; } if(json.dati[0].ora != null) html+= "Ora: "+json.dati[0].ora+"
"; html+= "Indirizzo (zona): "+json.dati[0].indirizzo+"
("+json.dati[0].indirizzo+")
"; if( json.dati[0].velocita!= null) html+= "Velocità: "+json.dati[0].velocita+" Km/h
"; /* var label = new ELabel(point, json.dati[0].targa, "style1", new GSize(-9,18), 75); mappa.addOverlay(label); */ var label_txt =""; if(json.dati[0].name!= null) label_txt = json.dati[0].name; if(json.dati[0].name_rubrica!= null) label_txt = json.dati[0].name_rubrica; var icona = select_icon_truck(json.dati[0].direzione, json.dati[0].digital_in,json.dati[0].hardware, label_txt); json.dati[0].marker = create_info_box(mappa,point,html,icona,label_txt,option); json.dati[0].html = html; var label = new ELabel(point, label_txt, "style1", new GSize(0,18), 75 ); mappa.addOverlay(label); } mappa.setCenter(bounds.getCenter()); mappa.setZoom(mappa.getBoundsZoomLevel(bounds)); return json; } } //json : lat, long function draw_simple_point(mappa,lat,long) { var point = new GLatLng(lat,long); bounds.extend(point); var marker = new GMarker(point); mappa.setCenter(bounds.getCenter()); mappa.setZoom(20); mappa.addOverlay(marker); } //passo la mappa e il json con i dati per disegnare anche i ballon function draw_point_paziente(mappa,json) { //first of all delete past markers mappa.clearOverlays(); for(var i=0;i < json.data.length;i++) { //occhio i dati sono inseriti in modo che per ogni paziente ho 2 record : uno con il viaggio di andata e uno on il viaggio di ritorno var entrata =""; var uscita = ""; if(json.data[i].id_andata == null) //trova il record di ritorno che se tutto è ok è il record successivo { entrata = json.data[i].ora_movimento.substring(0,2); if(json.data[i+1].id_andata == json.data[i].id_movimento) { uscita = json.data[i+1].ora_movimento.substring(0,2); } var point = new GLatLng(json.data[i].latitudine_rubrica,json.data[i].longitudine_rubrica); var label_txt = json.data[i].cognome +" "+json.data[i].nome; var label = new ELabel(point, label_txt, "style1", new GSize(0,18), 75 ); mappa.addOverlay(label); bounds.extend(point); //definiamo l'icona var icon = new GIcon(); var type_icon = "green"; if(json.data[i].carrozzina == 0 || json.data[i].carrozzina == 2 ) //0 = no carrzozzina //2 = non so type_icon = "green"; else //non deambulante { type_icon = "yellow"; if(parseInt(json.data[i].scale) > 0) //non è al piano terra { if(json.data[i].ascensore == 0) //no c'è ascensore type_icon = "red"; } } icon.image ="/ctwebinterface/imgmyfleet/icons/icon_map/"+global_map_icon_directory+"/"+type_icon+".png"; icon.iconSize = new GSize(20, 34); icon.iconAnchor = new GPoint(19, 34); icon.infoWindowAnchor = new GPoint(0,0); var html = ""+label_txt+""+"
"; html += "Indirizzo:"+json.data[i].indirizzo_rubrica+"
"; html += "Entrata: "+entrata+"
"; html += "Uscita: "+uscita+"
"; html += "
"; html += "Ascensore: "+translate_status(json.data[i].ascensore,"")+"
"; html += "Scale: "+translate_status(json.data[i].scale,"scale")+"
"; html += "Accompagnato: "+translate_status(json.data[i].accompagnato,"")+"
"; html += "Carrozzina: "+translate_status(json.data[i].carrozzina,"carrozzina")+"
"; html += "Peso: "+translate_status(json.data[i].obeso,"peso")+"
"; html += "Note: "+json.data[i].note_rubrica; var marker = create_info_box(mappa,point,html,icon,label_txt,"paziente"); mappa.addOverlay(marker); } } mappa.setCenter(bounds.getCenter()); mappa.setZoom(mappa.getBoundsZoomLevel(bounds)); } function my_point(point,info,name,distance) { this.point = point; this.info = info; this.name = name; this.distance = distance; } //map :object map //data to draw var draw_title = true; //add the name of veihcle function draw_route(map,json) { var result = null; if (json != 'empty') { //create the marker manager var mgr = new MarkerManager(map); var center_latitudine; var center_longitudine; var mpoints = new Array(); //here we save mypoints (mp) var mp = null; //here we have info about point and point itself var points = new Array(); //here I have the point itself ,gpoint var first_point = true; var j = 0 ; //index for the good point result = new Array(); for (var i = 0; i < json.length; i++) //json.length { if(draw_title == true && i == 0) { if($("#title_maproute").length >0) { var t = $("#title_maproute").html(); $("#title_maproute").html(t+" "+json[i].idvet); } draw_title = false; } //console.log("json "+json.length+" "+i); //console.log(global_json[i].longitudine +" "+global_json[i].latitudine); if(json[i].plongitudine!="" && json[i].plongitudine!=0 && json[i].platitudine!="" && json[i].platitudine!=null && json[i].platitudine!=0) { var point = new GLatLng(json[i].platitudine,json[i].plongitudine); result[i] = point; bounds.extend(point); var html = ""; html+=""+(j+1)+"/"+(json.length)+"
"; html+= "Data/ora: "+json[i].tempo+"
"; var indirizzo = json[i].indirizzo; html+= "Indirizzo (zona): "+indirizzo+"
"; if(json[i].indirizzo_zone!=null) html+=" ("+json[i].indirizzo_zone+")
"; html+= "Velocità: "+json[i].velocity+" Km/h
"; /*html+= "Batteria: "+json[i].batteria+"
"; */ mp = new my_point(point,html,json[i].idvet,json[i].dist); mpoints[j] = mp; points[j] = point; //var marker = create_info_box(map,point,html); if(first_point) //start icon, first point valid { var start_icon = new GIcon(); start_icon.image = "http://www.google.com/mapfiles/dd-start.png"; start_icon.iconSize = new GSize(20, 34); start_icon.iconAnchor = new GPoint(19, 34); start_icon.infoWindowAnchor = new GPoint(0,0); /* marker = new GMarker(point,{icon:start_icon,zIndexProcess:onTop}); add_info_box(marker,html); old*/ marker = create_info_box(map,point,html,start_icon,json[i].idvet,"ontop"); //map.addOverlay(marker); mgr.addMarker(marker,3); first_point = false; } if(i==json.length-1) //end { var end_icon = new GIcon(); end_icon.image = "http://www.google.com/mapfiles/dd-end.png"; end_icon.iconSize = new GSize(20, 34); end_icon.iconAnchor = new GPoint(19, 34); end_icon.infoWindowAnchor = new GPoint(0,0); /* marker = new GMarker(point,{icon:end_icon,zIndexProcess:onTop}); add_info_box(marker,html); old */ marker = create_info_box(map,point,html,end_icon,json[i].idvet,"ontop"); mgr.addMarker(marker,3); } j++; } /* if ((json[i].platitudine != 0) && (json[i].plongitudine != 0)) { var center_latitudine = json[i].platitudine; var center_longitudine = json[i].plongitudine; } */ } //map.setCenter(new GLatLng(center_latitudine,center_longitudine),5); //at the end draw the polyline var polylineEncoder = new PolylineEncoder(); var polyline = polylineEncoder.dpEncodeToGPolyline(points, '#3366FF', 4, 0.7); //map.addOverlay(new GPolyline(points)); map.addOverlay(polyline); arrowHead(mpoints,map); midArrows(mpoints,map,mgr); mgr.refresh(); /* GDir1 = new GDirections(); for(var i = 0; i < points.length - 1; i++) { waypoints[i] = new Array(points[i].lat(), points[i].lng(),points[i+1].lat(), points[i+1].lng()); console.log(waypoints[i]); } GDir1.loadFromWaypoints(waypoints, {getPolyline:true}); var gp = GDir1.getPolyline(); map.addOverlay(gp); */ map.setCenter(bounds.getCenter()); map.setZoom(map.getBoundsZoomLevel(bounds)); GEvent.addListener(map, "zoomend", function(old, current) { /* console.log("refresh "+old +" "+current); */ mgr.refresh(); }); } else { //global_map.setCenter(new GLatLng(global_json[global_json.length-1].platitudine,global_json[global_json.length-1].plongitudine), 10); //mappa.setCenter(new GLatLng(global_json[0].latitudine,global_json[0].longitudine),5); } return result; } //utility functions to change color for a zone //color for the zones var global_start_color = "336600"; var global_last_color = "336600"; function d2h(d) {return d.toString(16);} function h2d(h) {return parseInt(h,16);} function padLeft(str, pad, count) { while(str.length"; html += "Fine: "+json.soste.stopping[i].finesosta+"
"; var Hours = Math.floor(parseFloat(json.soste.stopping[i].duratasosta)/60); var Minutes = parseFloat(json.soste.stopping[i].duratasosta)%60; var rest_duration = Hours + ":" + Math.round(Minutes); html += "Durata: "+rest_duration+" (HH:mm)
"; Hours = Math.floor(parseFloat(json.soste.stopping[i].duratasostaDIGIN8)/60); Minutes = parseFloat(json.soste.stopping[i].duratasostaDIGIN8)%60; rest_duration = Hours + ":" + Math.round(Minutes); html += "A motore spento: "+rest_duration+" (HH:mm)
"; /* add_info_box(marker,html); map.addOverlay(marker); old*/ var restIcon = new GIcon(); restIcon.iconSize = new GSize(35,35); restIcon.shadowSize = new GSize(1,1); restIcon.iconAnchor = new GPoint(0,35); restIcon.infoWindowAnchor = new GPoint(0,17); restIcon.image ="/ctwebinterface/imgmyfleet/icons/icon_map/"+global_map_icon_directory+"/rest.png"; var marker = create_info_box(map,point,html,restIcon,"Sosta",""); map.addOverlay(marker); } } } } } } } // === A function to create the arrow head at the end of the polyline === function arrowHead(points,map) { // === The basis of the arrow icon information === var arrowIcon = new GIcon(); arrowIcon.iconSize = new GSize(24,24); arrowIcon.shadowSize = new GSize(1,1); arrowIcon.iconAnchor = new GPoint(12,12); arrowIcon.infoWindowAnchor = new GPoint(0,0); // == obtain the bearing between the last two points var p1=points[points.length-1].point; var p2=points[points.length-2].point; var dir = bearing(p2,p1); // == round it to a multiple of 3 and cast out 120s var dir = Math.round(dir/3) * 3; while (dir >= 120) {dir -= 120;} // == use the corresponding triangle marker arrowIcon.image = "http://www.google.com/intl/en_ALL/mapfiles/dir_"+dir+".png"; // map.addOverlay(new GMarker(p1, arrowIcon)); /* var marker = new GMarker(p1, arrowIcon); add_info_box(marker,points[points.length-1].info); old*/ var marker = create_info_box(map,points[points.length-1].point,points[points.length-1].info,arrowIcon,points[points.length-1].name,""); map.addOverlay(marker); } function bearing( from, to ) { // === Returns the bearing in degrees between two points. === // North = 0, East = 90, South = 180, West = 270. var degreesPerRadian = 180.0 / Math.PI; // See T. Vincenty, Survey Review, 23, No 176, p 88-93,1975. // Convert to radians. var lat1 = from.latRadians(); var lon1 = from.lngRadians(); var lat2 = to.latRadians(); var lon2 = to.lngRadians(); // Compute the angle. var angle = - Math.atan2( Math.sin( lon1 - lon2 ) * Math.cos( lat2 ), Math.cos( lat1 ) * Math.sin( lat2 ) - Math.sin( lat1 ) * Math.cos( lat2 ) * Math.cos( lon1 - lon2 ) ); if ( angle < 0.0 ) angle += Math.PI * 2.0; // And convert result to degrees. angle = angle * degreesPerRadian; angle = angle.toFixed(1); //console.log(from +" "+to+" " +angle); return angle; } // === A function to put arrow heads at intermediate points function midArrows(points,map,mgr) { // === The basis of the arrow icon information === var arrowIcon = new GIcon(); arrowIcon.iconSize = new GSize(24,24); arrowIcon.shadowSize = new GSize(1,1); arrowIcon.iconAnchor = new GPoint(12,12); arrowIcon.infoWindowAnchor = new GPoint(0,0); //with the marker manager we manage more //level of zoom: we draw a marker every 20 in the max zoom extension //the other will be shown at high leve of zoom /* var tot_dist = 0 ; for (var i=1; i < points.length-1; i++) { tot_dist += parseInt(points[i+1].distance) - parseInt(points[i-1].distance); }*/ var j = 0; var marker_index = 1; var distance = 0 ; //distance beetween two points var offset = 6000; if(points.length >=1) { offset = Math.round(parseInt(points[points.length-1].distance)/100); } //console.log("off "+offset); for (var i=1; i < points.length-1; i++) { var p1=points[i-1].point; var p2=points[i+1].point; var dir = bearing(p1,p2); //console.log(points[i].distance +" "+i); distance = distance +parseInt( (parseInt(points[i].distance) - parseInt(points[i-1].distance))); // console.log( points[i].distance +"-" +points[i-1].distance+" = " + distance); // == round it to a multiple of 3 and cast out 120s var dir = Math.round(dir/3) * 3; while (dir >= 120) {dir -= 120;} // == use the corresponding triangle marker // console.log("http://www.google.com/intl/en_ALL/mapfiles/dir_"+dir+".png"); arrowIcon = new GIcon(); arrowIcon.iconSize = new GSize(24,24); arrowIcon.shadowSize = new GSize(1,1); arrowIcon.iconAnchor = new GPoint(12,12); arrowIcon.infoWindowAnchor = new GPoint(0,0); arrowIcon.image = "http://www.google.com/intl/en_ALL/mapfiles/dir_"+dir+".png"; /* console.log("a "+i+" " +dir); if(dir>0 && dir <= 45) { dir = 45; } else if(dir>45 && dir <= 90) { dir = 90; } else if(dir>90 && dir <= 135) { dir = 135; } else if(dir>180 && dir <= 225) { dir = 225; } else if(dir>225 && dir <=270) { dir = 270; } else if(dir>270 && dir <=315) { dir = 315; } else if(dir>315 && dir <=270) { dir = 0; } */ /* var marker = new GMarker(points[i].point, arrowIcon); old*/ // add_info_box(marker,points[i].info); j++ var marker; if(parseInt(distance) >= parseInt(offset) ) { arrowIcon = new GIcon(); arrowIcon.iconSize = new GSize(20,34); arrowIcon.shadowSize = new GSize(1,1); arrowIcon.iconAnchor = new GPoint(10,34); arrowIcon.infoWindowAnchor = new GPoint(0,0); arrowIcon.image ="/ctwebinterface/imgmyfleet/icons/icon_map/"+global_map_icon_directory+"/numbered_markers/marker"+marker_index+".png"; // console.log (distance + "j "+j); marker = create_info_box(map,points[i].point,points[i].info,arrowIcon,points[i].name,""); marker_index++; //console.log(marker_index); mgr.addMarker(marker,3); //show it //j=0; distance = 0 ; } else { /* arrowIcon = new GIcon(); arrowIcon.iconSize = new GSize(24,24); arrowIcon.shadowSize = new GSize(1,1); arrowIcon.iconAnchor = new GPoint(12,12); arrowIcon.infoWindowAnchor = new GPoint(0,0); */ // arrowIcon.image = "/ctwebinterface/imgmyfleet/icons/icon_map/arrows/"+dir+".gif"; marker = create_info_box(map,points[i].point,points[i].info,arrowIcon,points[i].name,""); mgr.addMarker(marker,12); //show it only at high zoom level // console.log(distance +" j in "+j); } //map.addOverlay(marker); } } //load zone //RETURN: a json which contains the list of the zones function load_zone(map,path,opt) { var result ; /* $.ajax({ type:'GET', url:'../control_myfleet/control_zone_ajax.php', data:{load:load,type:all}, error: function(xhr){alert(xhr);}, complete: function(xhr){alert(xhr);}, success: function(data){alert(data);} }); */ var url_to_zone = '../control_myfleet/control_zone_ajax.php'; if(path!=null) url_to_zone = path; var show_modal = false; if(opt!=null) { if(opt.search('modal_show')) { show_modal = true; } } $.ajax({ type:'GET', url:url_to_zone, data:{load:'1',type:'all'}, error: function(xhr){complete_zone(show_modal);}, beforeSend: function(xhr){before_load_zone(show_modal);}, complete: function(xhr){complete_zone(show_modal);}, success: function(data){draw_zones(map,data,opt);} }); } function before_load_zone(s) { if(s==true) { simple_modal_loading(" Attendere","Aggiornamento in corso..."); } } function complete_zone(s) { if(s==true) { if($.modal!=null) $.modal.close(); } } //this function draw the zone you have in the table //control_zones, this markers are indipendent from the one which rapresents the trucks, and they are manaeed by a marker manager function draw_zones(mappa,json,opt) { //create the marker manager if(mappa==null) return; //if you don't have any assets in the map the map wasn't initialized so the object map is null mgr = new MarkerManager(mappa,{trackMarkers: true}); var icon_array = Array(); if( typeof(json.icon) != "undefined" && json.icon!="") { for(var i=0;i"; html+= "Codice zona: "+json.dati[i].desc_zone+"
"; html+= "
Latitudine: "+json.dati[i].latitudine+"
"; html+= "Longitudine: "+json.dati[i].longitudine+"
"; icona =""; if(json.dati[i].id_icon!="") { for(var m = 0 ;m< icon_array.length;m++) { if(icon_array[m].id == json.dati[i].id_icon) { icona = icon_array[m]; } } } mgr.addMarker(create_info_box(mappa,point,html,icona,json.dati[i].name),3); /* creo una label per la zona */ if (json.dati[i].desc_zone.length > 0) { var zone_label = new ELabel(point, json.dati[i].desc_zone, "style1", new GSize(0,18), 75 ); mgr.addMarker(zone_label,10); } //mappa.addOverlay( create_info_box(mappa,point,html,icona,json.dati[i].name)); } mgr.refresh(); var mgr_global = false; if(opt!=null) { if(opt.indexOf('global')!=-1) { mgr_global = true; } } if(mgr_global) global_mgr_zone = mgr; //save the manager in an ext function to call it }