Lets try this:[php]<?php
$map = imagecreatefromstring(file_get_contents(‘http://www.southernontariochasing.ca/examples/countieswithlogo.png’));
$lineWidth = 1; // Default line width
$width = imagesx($map);
$height = imagesy($map);
$file = ‘http://www.southernontariochasing.ca/grpoly.txt’;
$polys = getPolys($file);
foreach ($polys as $poly)
{
$coords = array();
if(isset($poly[‘red’],$poly[‘green’],$poly[‘blue’]))
{
$borderColor = imagecolorallocate($map, $poly[‘red’], $poly[‘green’], $poly[‘blue’]);
$fillColor = imagecolorallocatealpha($map, $poly[‘red’], $poly[‘green’], $poly[‘blue’], 105);
}
else
{
$borderColor = imagecolorallocate($map, 255, 0, 0); // Default line color when not specified
$fillColor = imagecolorallocatealpha($map, 255, 0, 0, 105); // Default fill color when not specified
}
if(isset($poly[‘lineWidth’])) $lineWidth = $poly[‘lineWidth’];
for($i=0;$i<count($poly[‘lat’]);$i++)
{
$result = getx_y($poly[‘lat’][$i],$poly[‘lon’][$i],$width,$height);
$coords[] = $result[‘x’];
$coords[] = $result[‘y’];
}
imagesetthickness($map, $lineWidth);
imagefilledpolygon($map, $coords, count($coords)/2, $fillColor);
imagepolygon($map, $coords, count($coords)/2, $borderColor);
}
header(“Content-type: image/png”);
imagepng($map);
function getx_y($pt_lat,$pt_lon,$width,$height)
{
$mp_lat = 43.69514; // MidPoint Latitude
$mp_lon = -80.78972; // MidPoint Longitude
$mp_x = round($width/2); //MidPoint x coordinate
$mp_y = round($height/2); //MidPOint y coordinate
$scale = 1.33; // pixels per kilometer
$rhumb = rhumbDB($mp_lat,$pt_lat,$mp_lon,$pt_lon); // Get rhumb line distance and bearing
$dist = $rhumb['distance']; // Get rhumb line Distance from midpoint
$angle = $rhumb['bearing']+2.2; // Get rhumb line Bearing from midpoint & rotate angle 2.2
$h = $dist * $scale; // Get the scaled distance (in pixels) from midpoint
$o = sin(deg2rad($angle%90)) * $h; // Get the offset in one direction using basic trig
$a = sqrt(pow($h,2)-pow($o,2)); // Get the other offset using pythagorean's theorem
if($angle > 0 && $angle <= 90) // Angle is in the 12:00 to 3:00 quadrant
{
$pt_x = $mp_x + $o; //pt_x is to the right of the midpoint
$pt_y = $mp_y - $a; //pt_y is above the midpoint
}
elseif($angle > 90 && $angle <= 180) // Angle is in the 3:00 to 6:00 quadrant
{
$pt_x = $mp_x + $a; //pt_x is to the right of the midpoint
$pt_y = $mp_y + $o; //pt_y is below the midpoint
}
elseif($angle > 180 && $angle <= 270) // Angle is in the 6:00 to 9:00 quadrant
{
$pt_x = $mp_x - $o; //pt_x is to the left of the midpoint
$pt_y = $mp_y + $a; //pt_y is below the midpoint
}
elseif($angle > 270 && $angle <= 360) // Angle is in the 9:00 to 12:00 quadrant
{
$pt_x = $mp_x - $a; //pt_x is to the left of the midpoint
$pt_y = $mp_y - $o; //pt_y is above the midpoint
}
$pt_x = round($pt_x); // Make sure pt_x is an integer
$pt_y = round($pt_y); // Make sure pt_y is an integer
return array('x'=>$pt_x,'y'=>$pt_y);
}
/*
rhumbDB implements the formula for finding distance and bearing between two points.
The distance and bearing are calculated without regard to great circle routes.
Depending on the map, you may need to use the Haversine formula instead, which accounts
for great circle routes. To return results in miles, use $R=3956.09 instead.*/
function rhumbDB($lat1,$lat2,$lon1,$lon2,$R=6366.71)
{
$lat1 = deg2rad($lat1); // All trig functions need to be in radians
$lat2 = deg2rad($lat2); // All trig functions need to be in radians
$lon1 = deg2rad($lon1); // All trig functions need to be in radians
$lon2 = deg2rad($lon2); // All trig functions need to be in radians
$deltlat = $lat2 - $lat1;
$deltlon = $lon2 - $lon1;
$deltPhi = log(tan($lat2/2+M_PI/4)/tan($lat1/2+M_PI/4));
if(is_numeric($deltlat/$deltPhi)) $q = $deltlat/$deltPhi;
else $q = cos($lat1);
if(abs($deltlon) > M_PI)
{
if($deltlon > 0) $deltlon = -(2*M_PI-$deltlon);
else $deltlon = 2*M_PI+$deltlon;
}
$d = sqrt($deltlat*$deltlat + $q*$q*$deltlon*$deltlon)*$R;
$brng = fmod(rad2deg(atan2($deltlon,$deltPhi))+360,360);
return array('distance'=>$d,'bearing'=>$brng);
}
function getPolys($file)
{
$fh = fopen($file, “r”);
$i=0;
while (!feof($fh))
{
$line = trim(fgets($fh));
if(substr($line,0,6) == 'Color:') list($poly[$i]['red'],$poly[$i]['green'],$poly[$i]['blue']) = explode(' ',substr($line,7));
elseif(substr($line,0,5) == 'Line:')
{
preg_match('/\d+/',$line,$match);
$poly[$i]['lineWidth'] = $match[0];
}
elseif(substr($line,0,4) == 'End:') $i++;
elseif(preg_match('/^\d+(.)+([0-9]+)*$/',$line)) list($poly[$i]['lat'][],$poly[$i]['lon'][]) = explode(',',$line);
}
fclose($fh);
return $poly;
}[/php]