<?php if(!defined('IN_PHPVMS') && IN_PHPVMS !== true) { die(); } ?>
<div class="mapcenter" align="center">
	<div class="alert alert-warning text-left">
		<strong>Attention</strong><br>
		Jumpseat flights will not be displayed in the map. 
	</div>
	<div id="routemap" style="width: 100%; height: <?php echo Config::Get('MAP_HEIGHT')?>">
	  
	</div>
</div>
<script type="text/javascript">
function initCarte(){
var act_json_data = '<?php echo json_encode(PIREPData::act_json(Auth::$userinfo->pilotid)); ?>';
var lineSymbol = {
                      path: 'M 157.98695,184.38488 L 173.37483,168.20017 C 182.38616,159.18884 197.56012,162.31477 197.56012,162.31477 L 242.58958,168.47612 L 265.39575,146.16045 C 277.41087,134.35989 288.26269,152.4142 283.54247,158.63631 L 271.83305,172.24635 L 320.32641,181.22794 L 336.78707,162.03882 C 354.38063,141.01237 367.47041,159.95529 359.53185,171.11218 L 348.89521,184.56906 L 421.75804,194.07153 C 484.40828,133.78139 509.98537,108.77262 526.46939,123.63021 C 543.05967,138.5836 513.71315,168.38877 456.64135,227.17701 L 467.00204,302.24678 L 482.26714,289.52597 C 491.27847,282.01653 507.27901,294.06392 490.75822,309.72648 L 469.76089,329.52825 L 478.61969,378.66527 L 491.73923,368.58052 C 503.32523,359.35463 517.39476,371.55518 501.7322,388.29052 L 480.88803,409.28786 C 480.02981,409.93153 487.69305,452.38631 487.69305,452.38631 C 492.41327,473.19821 480.67347,480.80195 480.67347,480.80195 L 466.35838,493.27782 L 411.97962,339.67439 C 407.47395,326.15738 396.0546,311.47862 376.97351,313.22076 C 366.8894,314.29354 341.41552,331.49026 337.98263,335.56682 L 279.00579,392.27531 C 277.5039,393.34809 288.07915,465.99635 288.07915,465.99635 C 288.07915,468.14191 269.38054,492.66454 269.38054,492.66454 L 232.01433,426.14725 L 213.56128,434.7301 L 224.35108,417.93211 L 157.06733,379.9526 L 182.29502,361.49956 C 194.31014,364.28878 257.3034,371.36975 258.59073,370.72608 C 258.59073,370.72608 309.88762,319.85344 312.81633,316.77643 C 329.76623,298.96831 335.46935,292.31456 338.04402,283.51778 C 340.6208,274.71377 336.23117,261.81195 309.62838,245.4769 C 272.93937,222.94855 157.98695,184.38488 157.98695,184.38488 z',
                       scale: 0.055,
                      rotation: -45,
                      strokeColor: '#00ef43',
                      fillColor: '#00ef43',
                      fillOpacity: 10,
                      anchor: new google.maps.Point(500, 170)
                    };
					
function animateCircle(line) {
          var count = 0;
          window.setInterval(function() {
            count = (count + 1) % 200;

            var icons = line.get('icons');
            icons[0].offset = (count / 2) + '%';
            line.set('icons', icons);
        }, 10);
}	
				
//var iconBase = ' http://dl.iflyva.in/img/maps/';

var iconBase = 'https://maps.google.com/mapfiles/ms/micons/';	
  
var map_flights = new google.maps.Map(document.getElementById('routemap'), {
    zoom: 4,
    center: {lat: 40, lng: 15},
    mapTypeControlOptions: {
      mapTypeIds: []
    }, 
    disableDefaultUI: true, 
    mapTypeControl: true,
    scaleControl: true,
    zoomControl: true,
    zoomControlOptions: {
      style: google.maps.ZoomControlStyle.LARGE 
    },
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    styles: [ {
        "featureType": "landscape",
        "stylers": [ {
            "color": "#24282d"
        }
        ]
    }
    ,
    {
        "featureType": "administrative",
        "stylers": [ {
            "visibility": "off"
        }
        ]
    }
    ,
    {
        "featureType": "transit",
        "stylers": [ {
            "visibility": "off"
        }
        ]
    }
    ,
    {
        "featureType": "road",
        "stylers": [ {
            "visibility": "off"
        }
        ]
    }
    ,
    {
        "featureType": "water",
        "stylers": [ {
            "color": "#303844"
        }
        ]
    }
    ,
    {
        "featureType": "poi",
        "stylers": [ {
            "visibility": "off"
        }
        ]
    }
    ,
    {
        featureType: "all",
        elementType: "labels",
        stylers: [ {
            visibility: "off"
        }
        ]
    }
    ]
});

/* console.log(act_json_data); */
var act_obj = $.parseJSON(act_json_data);
/* First object in array = current position */
console.log(act_obj[0]);
console.log("current_position (lat: " +act_obj[0].arrival_lat+ " long: " +act_obj[0].arrival_long+ " ICAO: " +act_obj[0].arricao+ ")");
  
$.each(act_obj, function(k, flight) {
act_obj.forEach(function(elem){	
	if (elem === 0) {return;}
});	
    var flightPlanCoordinates = [
        {lat: Number(flight.departure_lat), lng: Number(flight.departure_long)},
        {lat: Number(flight.arrival_lat), lng: Number(flight.arrival_long)},
    ];
	
    var flightPath = new google.maps.Polyline({
        path: flightPlanCoordinates,
		strokeColor: "#0095db",
		strokeOpacity: 0.6, 
		strokeWeight: 4,
		geodesic: true,
		map: map_flights
    })
	
	/*.setMap(map_flights);*/

   /* flightPath.setMap(map_flights); */
   
	var Planes = new google.maps.Polyline({
						path: flightPlanCoordinates,
						icons: [{
						icon: lineSymbol,
						offset: '100%'
						}],
						strokeColor:  "#16cefc",
						strokeOpacity: 1.0,
						strokeWeight: 2,
						geodesic: true,
						map: map_flights,
					});

	animateCircle(Planes);
					
var deparures = new google.maps.LatLng({lat: Number(flight.departure_lat), lng: Number(flight.departure_long)});
var arrivals = new google.maps.LatLng({lat: Number(flight.arrival_lat), lng: Number(flight.arrival_long)});
var comp =  new google.maps.LatLng(act_obj[0].arrival_lat, act_obj[0].arrival_long);


/*
if (comp.equals (deparures)) {
	icon = new google.maps.MarkerImage(iconBase1 + "green-dot.png", null, new google.maps.Point(0, 0), new google.maps.Point(10, 10));
	console.log((comp.equals (deparures)));
	} else if (comp.equals (arrivals)) {
	icon = new google.maps.MarkerImage(iconBase1 + "green-dot.png", null, new google.maps.Point(0, 0), new google.maps.Point(10, 10));
	console.log((comp.equals (arrivals)));
	} else {
	icon = new google.maps.MarkerImage(iconBase + "light_blue_marker_plane.png", null, new google.maps.Point(0, 0), new google.maps.Point(10, 10));
	console.log((comp.equals (deparures)));
}
console.log((comp.equals (deparures)));
console.log((comp.equals (arrivals)));

route.getPath().push(latlng);   	  
*/	  
                  
 var depmarker = new google.maps.Marker({
    position: deparures,
    map: map_flights,
	title: flight.depicao,
	icon: iconBase + "light_blue_marker_plane.png",
    animation:google.maps.Animation.DROP
  });
  


 var arrmarker = new google.maps.Marker({
    position: arrivals,
    map: map_flights,
	title: flight.arricao,
	icon: iconBase + "light_blue_marker_plane.png"
  });  
 

 
var cur_location = new google.maps.LatLng(act_obj[0].arrival_lat, act_obj[0].arrival_long);

var current = new google.maps.Marker({
    position: cur_location,
    map: map_flights,
    title: 'act_obj[0].arricao',
    icon: iconBase1 + "green-dot.png"
});


 var departureinfo = "You are currently at: " + act_obj[0].arricao;

                    var departurewindow = new google.maps.InfoWindow({
                        content: departureinfo
                    }); 
                    
                    current.addListener('mouseover', function() {
                      departurewindow.open(map_flights, current);
                      departurewindow.open(map_flights); 
                    });
  
});
		
};

// init lorsque la page est chargee
google.maps.event.addDomListener( window, 'load', initCarte);        
</script>