<?php
/*
OpenDataBag - Data Web Interface
Copyright (C) 2004 Nawara
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
header("Content-type: image/png");
$im = @imagecreatefromgif(cfg_images_path.'/switzerland_sm05.gif');
//$im = @imagecreatefromjpeg(cfg_images_path.'/switzerland_admin_2_2000.jpg');
//$im = @imagecreate(634, 323)
// or die("Cannot Initialize new GD image stream");
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$red = imagecolorallocate($im, 233, 14, 91);
$green = imagecolorallocate($im, 17, 200, 91);
$yellow = imagecolorallocate($im, 17, 200, 91);
$record_array=search($search.' MyBag=place');
if(count($record_array))
{
$ii=0;
while(list($tmp,$variable_array)=each($record_array))
{
$lat=read($variable_array,'Latitude');
$lon=read($variable_array,'Longitude');
if($ii==0)
{
$min_latitude = $lat;
$max_latitude = $lat;
$min_longitude = $lon;
$max_longitude = $lon;
}
else
{
if($lat<$min_latitude) $min_latitude=$lat;
if($lat>$max_latitude) $max_latitude=$lat;
if($lon<$min_longitude) $min_longitude=$lon;
if($lon>$max_longitude) $max_longitude=$lon;
}
$p[$ii]['latitude']=$lat;
$p[$ii]['longitude']=$lon;
$p[$ii]['placename']=utf8_decode(read($variable_array,'Place Name'));
$p[$ii]['population']=read($variable_array,'Gtopo30');
if($p[$ii]['population']<$population_min)
$population_min=$p[$ii]['population'];
if($p[$ii]['population']>$population_max)
$population_max=$p[$ii]['population'];
$ii++;
}
}
//echo $min_longitude.' '.$max_longitude.' '.$min_latitude.' '.$max_latitude.'<br>';
if ($max_latitude>$max_longitude)
$max = 0+$max_latitude;
else
$max = 0+$max_longitude;
// override settings for map purpose switzerland_sm05.gif
$min_latitude = 45.75;
$max_latitude = 47.9;
$min_longitude = 5.273;
$max_longitude = 11.28;
// override settings for map purpose switzerland_admin_2_2000.jpg
$d_lat=$max_latitude-$min_latitude;
$d_lon=$max_longitude-$min_longitude;
//imagestring($im, 2, 10, 10 ,$min_longitude.' '.$max_longitude.' '.$min_latitude.' '.$max_latitude.' '.cfg_images_path.'/switzerland_sm05.gif', $black);
//~ if($d_lon>$d_lat)
//~ $d_lat=$d_lon;
//~ else
//~ $d_lon=$d_lat;
//$aspect=0.66*$d_lon/$d_lat;
$aspect=1;
//~ imagestring($im, 3, 10, 10, "max lat ".$max_latitude, $black);
//~ imagestring($im, 3, 10, 25, "min lat ".$min_latitude, $black);
//~ imagestring($im, 3, 10, 40, "max lon ".$max_longitude, $black);
//~ imagestring($im, 3, 10, 55, "min lon ".$min_longitude, $black);
//~ imagestring($im, 3, 10, 70, "search ".$search, $black);
for($ii=0;$ii<100;$ii++)
$color[$ii]=imagecolorallocate($im, $ii-100, 0, 0);
for($ii=100;$ii<255;$ii++)
$color[$ii]=imagecolorallocate($im, 0, 255-$ii+100, 0);
//for($ii=0;$ii<255;$ii++)
// imagefilledrectangle($im, 0, 255-$ii, 10, 255-$ii, $color[$ii]);
for($ii=0;$ii<sizeof($p);$ii++)
{
$img_x=round($aspect*($p[$ii]['longitude']-$min_longitude)*634/$d_lon);
$img_y=round(323-($p[$ii]['latitude']-$min_latitude)*323/$d_lat);
imagesetpixel ($im, $img_x, $img_y, $black);
$tmp_col=$color[256*($p[$ii]['population']-$population_min)/($population_max-$population_min)];
imagefilledrectangle($im, $img_x-3, $img_y-3, $img_x+3, $img_y+3, $tmp_col);
}
for($ii=0;$ii<sizeof($p);$ii++)
{
if($ii<0)
{
$img_x=round($aspect*($p[$ii]['longitude']-$min_longitude)*634/$d_lon);
$img_y=round(323-($p[$ii]['latitude']-$min_latitude)*323/$d_lat);
imagefilledrectangle($im, $img_x, $img_y-2, $img_x+strlen($p[$ii]['placename'])*5, $img_y+10, $white);
imagerectangle($im, $img_x, $img_y-2, $img_x+strlen($p[$ii]['placename'])*5, $img_y+10, $black);
imagestring($im, 1, $img_x, $img_y, $p[$ii]['placename'], $black);
}
}
imagepng($im);
imagedestroy($im);
?>