<?php
// Lets load the MIF file into our array
$polygons = LoadMIF("1.mif");
// This is the width of our final image
$image_sx = 400;
// This is the height of our final image
$image_sy = 400;
//This is the scale/zoom level if not parsed.
if(empty($scale))$scale = 35000;
// Next we set our base object we want to plot and center on
$my_long = -63.10774861954596;
$my_lat = 46.2899306519141;
// Set the correct scale for use in getlocationcoords
$sx = 2 * $scale;
$sy = $scale;
// Now we find out what screen coordinates the long/lat
//coordinates are at based on a complete map of the world
$center = getlocationcoords($my_lat, $my_long, $sx,$sy) ;
// Based on the size of the final image, we work out the
// amount we will need to add/subtract from the screen
// coordinate that will be calculated later to center our point
// on the final image.<br>
$min_x = $center["x"] - ($image_sx / 2);
$min_y = $center["y"] - ($image_sy / 2);
// So lets create our image, and also allocate some colors to
// make everything look purdy.
$im = imagecreate($image_sx,$image_sy);
$land = imagecolorallocate ($im, 0xF7,0xEF,0xDE);
$sea = imagecolorallocate ($im, 0xB5,0xC7,0xD6);
$red = imagecolorallocate ($im,0xff,0x00,0x00);
// Lets now draw out inital background .. the mighty ocean.
// You could also use a drawn "sea scape" image if you
// wanted things to look a little different.
imagefilledrectangle($im,0,0,$image_sx,$image_sy,$sea);
// Now we loop through the array of arrays getting each polygon
// in turn
foreach($polygons as $poly)
{
$converted_points = array();
// Each vector objects is stored as a space delimited string
// {long} {lat} {long} {lat} etc etc.
// So we explode these points into a temporary array for
// easy conversion to screen coordinates.
$points = explode(" ",$poly["poly_string"]);
$number_points = count($points);
$i = 0;
while($i<$number_points)
{
// Get each long/lat in turn. Convert it to screen coordinates
// Then subtract the "world screen" coordindate of our base object
// ( our house ) so the polygon will be centered around it.
$lon = $points[$i];
$lat = $points[$i+1];
$pt = getlocationcoords($lat, $lon, $sx, $sy);
$converted_points[] = $pt["x"] - $min_x;
$converted_points[] = $pt["y"] - $min_y;
$i+=2;
}
// Then use GD to draw the polygon. We divide the number of points by
// 2 as this is the actually true number of points in the array
imagefilledpolygon($im,$converted_points,$number_points/2,$land);
}
// Next center our base object
$pt["x"] = $center["x"] - $min_x;
$pt["y"] = $center["y"] - $min_y;
// And plot it in the middle of the map
imagefilledrectangle($im,$pt["x"]-2,$pt["y"]-2,$pt["x"]+2,$pt["y"]+2,$red);
// Set the headers and return the image header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>