Generating a map of people
The xplanet utility can be used together with the Midgard phonebook for generating maps where people's locations are shown on a world map.
To do this, you first need to make the datamanager schema in your person editor able to input coordinates. This is easily done by adding two new fields:
"latitude" => array (
"description" => "Latitude (decimal format)",
"datatype" => "text",
"location" => "parameter",
"start_fieldgroup" => Array (
"title" => "Location"
),
),
"longitude" => array (
"description" => "Longitude (decimal format)",
"datatype" => "text",
"location" => "parameter",
"end_fieldgroup" => "",
),
When this has been done you need to create a PHP script that will read the data from your database, and store it into an xplanet marker file. In this example, I have saved this script to a regular Midgard page :
<?php
$coord_file_name = '/tmp/my_team_coords.txt';
$my_group = mgd_get_object_by_guid("68f8b606a9a64505d722b41899e5689f");
if (is_writable($coord_file_name))
{
$coord_file = fopen($coord_file_name, 'w');
// Cycle through the developers
if($my_group)
{
$members = mgd_list_members($my_group->id);
if($members)
{
while($members->fetch())
{
$member = mgd_get_person($members->uid);
$latitude = $member->parameter('midcom.helper.datamanager', 'data_latitude');
$longitude = $member->parameter('midcom.helper.datamanager', 'data_longitude');
if ($latitude
&& $longitude)
{
// Write the line
$member_line = "{$latitude} {$longitude} \"{$member->username}\" # {$member->firstname} {$member->lastname}\n";
fwrite($coord_file, $member_line);
}
}
}
}
fclose($coord_file);
}
else
{
die("Coordinate file {$coord_file_name} is not writable");
}
// Then make the maps
exec("xplanet --output /tmp/our_team.jpg --geometry 640x320 -num_times 1 -projection rectangular -body earth -config /home/bergie/my_team.conf");
?>
After this has been done, test that the coordinate file gets populated properly. Lines in it should look something like the following:
60.1591 24.9422 "bergie" # Henri Bergius
Next you need to make the xplanet configuration file /home/bergie/my_team.conf. It should contain at least the following:
marker_file=/tmp/midgard-coords.txt
map=earth.jpg
night_map=earth.jpg
Once this has been done, add your script to cron to ensure that the maps get updated frequently. In this case I have the following file in /etc/cron.daily:
#!/bin/sh
/usr/bin/lynx -dump http://www.example.net/path/to/page/
