Jump to content
stuartpb

Airport Information Addon

Recommended Posts

After receiving several requests by PM, I am releasing the addon I use to show the airports in the phpVMS database, with a separate page for each airport with various bits of data. First though I would like to attribute the work which I did not complete and is part of this addon.

  • The Airport Table Page - This was originally created by Adamm, and I just removed some of the columns and added the link to the seperate webpage for the detailed airport info.
  • The Last Arrival and Last Departure Fields - I asked for help on this forum, and Jeff (Lorathon) gave me the code to enable this feature.
  • The Flight Counts - Simpilot posted some code to show the flight count. I expanded on this to show the arrival and departure flight counts.
  • The Google Map - I reused and slightly modified (stripped out the ACARS functionality) the acars map from the default acarsmap.tpl here.
  • The js for the map display - Problem resolved my Mark1Million

I take absolutely no credit for the above mentioned aspects of the addon, and I would like to thank those mentioned for helping me create the addon released here. If you are going to thank anyone for this addon, thank those guys. I just put stuff together and added some more stuff. If you use this addon, I have placed attribution in the HTML commenting, please do leave it there.

If it doesn't work on your site, I'm sorry but I can only provide limited support, as I'm still a learner when it comes to php. Please don't PM me asking for support. You would be much better posting here and there is every chance that someone more knowledgeable may be able to help.

The addon can be seen working here:

http://execair.org/index.php/airports

The attached file has the same functionality but requires CSS styling to be applied. There are many tutorials available online, which discuss CSS styling at length, here are a few:

http://w3schools.com/Css/default.asp

http://www.csstutorial.net/

http://www.echoecho.com/css.htm

To install the addon, unzip the folder, then copy the contents of the core folder over to the core folder on your website. Then to access the addon, you need to create a link to the new page in your navigation:

<a href="<?php echo url('/airports'); ?>">Text for link here</a>

EDIT: Attached File Amended to correct all Map Errors mentioned below.

RE-EDIT: The attachment has been amended again to correct the errors. It should work 100% now.

airportinfo_v3.zip

  • Like 5

Share this post


Link to post
Share on other sites
Guest

he doesnt show any map on the airport information page, does someone have the same problem?

Share this post


Link to post
Share on other sites

Thank-you Stuart, this is a great addition to any VA.

No worries Mark B)

he doesnt show any map on the airport information page, does someone have the same problem?

Try replacing the following in the airport_info.tpl file:

<?php 
/* These are the settings for the Google map. You can see the
Google API reference if you want to add more options.

There's two options I've added:

autozoom: This will automatically center in on/zoom 
  so all your current flights are visible. If false,
  then the zoom and center you specify will be used instead

refreshTime: Time, in seconds * 1000 to refresh the map.
  The default is 10000 (10 seconds)
*/
?>
var acars_map_defaults = {
autozoom: true,
   center: new google.maps.LatLng("<?php echo $name->lat; ?>", "<?php echo $name->lng; ?>"),
   mapTypeId: google.maps.MapTypeId.HYBRID };
</script>

with:

<?php 
?>
var acars_map_defaults = {
zoom: 14,
   center: new google.maps.LatLng("<?php echo $name->lat; ?>", "<?php echo $name->lng; ?>"),
   mapTypeId: google.maps.MapTypeId.HYBRID
};
</script>

If that works, I'll amend the file in the attachment. I think it's because I removed the zoom level in the attached file accidentally. I meant to delete the autozoom part.

EDIT: I've just found another mistake I made, sorry about this. In the airport_info.tpl file, there are two script tags here:

<script type="text/javascript">
<script type="text/javascript">
<?php 
?>
var acars_map_defaults = {
zoom: 14,
   center: new google.maps.LatLng("<?php echo $name->lat; ?>", "<?php echo $name->lng; ?>"),
   mapTypeId: google.maps.MapTypeId.HYBRID
};
</script>

Remove the top <script type="text/javascript"> from the code. I was cut and pasting the code from my working site, to a new file, and made a few errors in doing so. let me know if the above changes work, and I'll amend the attached file.

Share this post


Link to post
Share on other sites

Thanks Stuart :)

No worries mate.

I've amended the attached addon file with the corrections mentioned. The map should work now.

FFS: I've just spotted another error. I stripped out the styling from my working copy, but forgot that the map div needs to have width and height attributes set for the map to display properly.

Another change:

in the airport_info.tpl page again, find:

<div id="acarsmap"></div>

And set the width and height attributes like so:

<div id="acarsmap" style="width:672px;height:450px;></div>

You can change the values to whatever suits your layout best.

Amended the attached file again :(

Share this post


Link to post
Share on other sites

Anyone get the map displaying yet? It's working on my end, but it would be cool to know if I've corrected the errors properly. I don't have much faith in my coding skills (or lack of) as it is :P

Share this post


Link to post
Share on other sites

Mine is still not showing the map (http://www.flyaerova...rport?icao=CYYZ excuse the layout)

EDIT: Mark beat me to it. :P

Could it be that the outer div container for the map needs to have the class defined in order for the js to output?

<div class="mapcenter" align="center" >

<div id="acarsmap" style="width:672px;height:450px;></div>

</div

I'll try removing the class tag from my page and see it it breaks the map, brb.

EDIT: Nope that isn't it. I'm trying to figure out what the problem is, bear with me please.

Share this post


Link to post
Share on other sites

To get the airport map work.

At the top of the page:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

Then where you like the map to be dispayed use this:

    <script type="text/javascript">

     function initialize() {
       var mapDiv = document.getElementById('map-canvas');
       var map = new google.maps.Map(mapDiv, {
         center: new google.maps.LatLng(<?php echo $name->lat; ?> , <?php echo $name->lng; ?> ),
         zoom: 14,
         mapTypeId: google.maps.MapTypeId.SATELLITE
       });
     }


     google.maps.event.addDomListener(window, 'load', initialize);
   </script>
   <div id="map-canvas" style="width: 100%; height: 500px"></div>

You can change the:

mapTypeId: google.maps.MapTypeId.SATELLITE

to

mapTypeId: google.maps.MapTypeId.HYBRID

for the hybrid mode ;)

Share this post


Link to post
Share on other sites

To get the airport map work.

At the top of the page:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

Then where you like the map to be dispayed use this:

    <script type="text/javascript">

     function initialize() {
       var mapDiv = document.getElementById('map-canvas');
       var map = new google.maps.Map(mapDiv, {
         center: new google.maps.LatLng(<?php echo $name->lat; ?> , <?php echo $name->lng; ?>  ?>),
         zoom: 14,
         mapTypeId: google.maps.MapTypeId.SATELLITE
       });
     }


     google.maps.event.addDomListener(window, 'load', initialize);
   </script>
   <div id="map-canvas" style="width: 100%; height: 500px"></div>

You can change the:

mapTypeId: google.maps.MapTypeId.SATELLITE

to

mapTypeId: google.maps.MapTypeId.HYBRID

for the hybrid mode ;)

Ahh Thanks Dimitris, I just realised why due to your post. I have minimised all my Javascript into one single file, so I don't need to call the script from the page. It's already called in the layout.tpl file. I wouldn't have thought about that unless you posted.

EDIT: You don't need to call the google maps script from the page it's already called from the layout or header file as default. i can't figure out how I could get it working without having to to use the initialise function? I can't see any obvious differences from James'es to mine in the coding but mine works?

Share this post


Link to post
Share on other sites

Ok i now have that working but with one change, instead of calling out to Google im using the existing file in the system

So,

<script type="text/javascript" src="<?php echo fileurl('/lib/js/acarsmap.js');?>"></script>
<br />
<h3><?php echo $name->name;?></h3>
<script type="text/javascript">

     function initialize() {
       var mapDiv = document.getElementById('map-canvas');
       var map = new google.maps.Map(mapDiv, {
         center: new google.maps.LatLng(<?php echo $name->lat; ?> , <?php echo $name->lng; ?> ),
         zoom: 14,
         mapTypeId: google.maps.MapTypeId.SATELLITE
       });
     }


     google.maps.event.addDomListener(window, 'load', initialize);
   </script>
   <div id="map-canvas" style="width: 100%; height: 500px"></div>

:) Get there in the end...

Share this post


Link to post
Share on other sites

Ok i now have that working but with one change, instead of calling out to Google im using the existing file in the system

So,

<script type="text/javascript" src="<?php echo fileurl('/lib/js/acarsmap.js');?>"></script>
<br />
<h3><?php echo $name->name;?></h3>
<script type="text/javascript">

     function initialize() {
       var mapDiv = document.getElementById('map-canvas');
       var map = new google.maps.Map(mapDiv, {
         center: new google.maps.LatLng(<?php echo $name->lat; ?> , <?php echo $name->lng; ?> ),
         zoom: 14,
         mapTypeId: google.maps.MapTypeId.SATELLITE
       });
     }


     google.maps.event.addDomListener(window, 'load', initialize);
   </script>
   <div id="map-canvas" style="width: 100%; height: 500px"></div>

:) Get there in the end...

I've got headache now :P

Share this post


Link to post
Share on other sites

I still can't suss out how it works in mine the way I listed, so I will amend the file to include Mark's JS. I'm going with Mark's as there is no need to call the google maps js again from the page. It's already been called so it's redundant to call it again. I'll amend the attribution too, to reflect this.

Share this post


Link to post
Share on other sites

Ah that's no problem, just glad its working, great addition there :)

For the Notams, the code is in the forum here for that all you need to do is modify the code and create a new filename and include the variables for this page.

Infact here you go its easier just to paste it here seeing as were all in a sharing mood today ;).

<?php 

$stream = "http://www.ourairports.com/airports/$name->icao/notams.rss"; 

$file = new CodonWebService();
$contents = @$file->get($stream);
$xml = @simplexml_load_string($contents); 

$out = array(); 

$i = 1; 

if (!isset($xml->channel->item)) { 
   die("Sorry Nothing Found"); 
} 

foreach($xml->channel->item as $item) {  
   $data = array(); 
   $data['title'] = $item->title; 
   $data['description'] = $item->description; 
   $data['link'] = $item->link; 

   array_push($out, $data); 

   if ($i == 1) { 
       break; 
   } 
   $i--; 
}

echo $data['title'];
echo $data['description'];

$i = 2; 

if (!isset($xml->channel->item)) { 
   die("Sorry Nothing Found"); 
} 

foreach($xml->channel->item as $item) {  
   $data = array(); 
   $data['title'] = $item->title; 
   $data['description'] = $item->description; 
   $data['link'] = $item->link; 

   array_push($out, $data); 

   if ($i == 1) { 
       break; 
   } 
   $i--; 
}

echo $data['title'];
echo $data['description'];

$i = 3; 

if (!isset($xml->channel->item)) { 
   die("Sorry Nothing Found"); 
} 

foreach($xml->channel->item as $item) {  
   $data = array(); 
   $data['title'] = $item->title; 
   $data['description'] = $item->description; 
   $data['link'] = $item->link; 

   array_push($out, $data); 

   if ($i == 1) { 
       break; 
   } 
   $i--; 
}

echo $data['title'];
echo $data['description'];

?> 

Place this in your active skins folder, then just include it where you want it.

Share this post


Link to post
Share on other sites

Cool addition Mark! You could even go one step further and add the latest METARs code from the schedules_briefing.tpl and add that. The potential for a really informative addon is there.

Share this post


Link to post
Share on other sites

I downloaded again the file (with the changes) but now I m getting this:

Fatal error: Call to undefined method AirportData::getarrflights() in /home/greeceai/public_html/fss/core/templates/airport_info.tpl on line 25

Share this post


Link to post
Share on other sites

I downloaded again the file (with the changes) but now I m getting this:

Can you check the AirportData.class.php file, and post up the contents here?

Share this post


Link to post
Share on other sites

Cool addition Mark! You could even go one step further and add the latest METARs code from the schedules_briefing.tpl and add that. The potential for a really informative addon is there.

Copy fromt the schedule_bfiefing for the metars:

<div id="<?php echo $name->icao; ?>" class="metar">Getting Airport METAR</div> <br />
		<a href="http://flightaware.com/resources/airport/<?php echo $name->icao?>/weather" target="_blank">
		View Weather Details for <?php echo $name->icao ?></a>

Share this post


Link to post
Share on other sites

Can you check the AirportData.class.php file, and post up the contents here?

It is 15lines and the content is:

<?php
class AirportData extends CodonData {
function getdeptflights($icao)  {
   	$sql = 'SELECT pirepid FROM '.TABLE_PREFIX.'pireps
                           	WHERE depicao="'.$icao.'"';
   	$result = DB::get_results($sql);    	
   	return count($result);
}
   	function getarrflights($icao)  {
   	$sql = 'SELECT pirepid FROM '.TABLE_PREFIX.'pireps
                           	WHERE arricao="'.$icao.'"';
   	$result = DB::get_results($sql);    	
   	return count($result);
}
}

EDIT: Solved! Corrupted on upload.

Share this post


Link to post
Share on other sites

EDIT: Solved! Corrupted on upload.

Thank god for that!! I am still trying to figure out how the map works as it was on my site, but not on others :P

Share this post


Link to post
Share on other sites

Stuart, Thank you for this add-on. :)

I will give it a try! 1+ rep.

Share this post


Link to post
Share on other sites

Hi, and thanks for sharing this great addon, i really appreciate your work. however, I have one question, I want to add RWY lenght and ILS frequencies for each runway, I guess to make it show up in your addon, i have to figure out how to add column to "add a new airport" in Admin panel section, and then just paste the code from there to airport_info.tpl, but as i am total noob in coding i would appreciate if someone could help me in this.

Thanks.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...