<div id="ajax_map">
		<div class="mapcenter" align="center">
            <div id="fleet_map" style="width: 90%; height: 500px"></div>
         </div>
         <br><br><br>
         <script src="<?php echo SITE_URL?>/lib/js/base_map.js"></script>
         <script type="text/javascript">
            const map = createMap({
            	render_elem: 'fleet_map',
            	provider: '<?php echo Config::Get("MAP_TYPE"); ?>',
            });
			
			map.setView([0, 0], 1.5);
			
            <?php
               function in_array_r($item , $array){
					return preg_match('/"'.preg_quote($item, '/').'"/i' , json_encode($array));
				}
            $airports = array();
            
               foreach ($fleet as $fleetmap) {
               	//$last_flight = ICSFleetData::get_last_flight($fleetmap->id);
               	//if($last_flight == '') {
               	//	$current_location = 'KFDW';
               	//} else {
               	//	
               	//	$current_location = $last_flight->arricao;
				   //}
				   $current_location = $fleetmap->location;
               	
               	$airportdata = OperationsData::getAirportInfo($current_location);
               	$coords = '['.$airportdata->lat.','.$airportdata->lng.']';
               	
               	
               	if(in_array_r($current_location , $airports)){
               		array_push($airports[$current_location], $fleetmap->registration);
               	} else {
               		$airports[$current_location] = array($fleetmap->registration);
            	}
            	
               }
               
               
               foreach ($airports as $airport => $plane) {
               			$message = '';
               		$airportdata = OperationsData::getAirportInfo($airport);
               		$coords = '['.$airportdata->lat.','.$airportdata->lng.']';
               			foreach ($plane as $p) {
							$message .= ' '.$p;
						}
					
					
               		?>
               		
               		L.marker(<?php echo $coords; ?>).bindTooltip("<?php echo $message; ?>").addTo(map);
               		
               		<?php
				}
               
               ?>
            	
            
            	var legend = L.control({position: 'bottomright'});
            
            	legend.onAdd = function (map) {
            
                var div = L.DomUtil.create('div', 'info legend');
                    div.innerHTML = '<img src="<?php echo SITE_URL; ?>/iCrew/favicon.png" style="width: 50px; height: auto;" /> <span class="text-primary">Fleet Map</span> ';
            	//<br><span class="label label-success">Direct Flights</span><br><span class="label label-warning">Connecting Flights</span>    
            
                return div;
            	};
            
            	legend.addTo(map);
         </script>
         
</div>