global $MyHost, $MyLogin, $MyPassword, $MyDatabase, $scale_to_showicons,
$map, $mappath;
Get some variables from global environment
@mysql_connect($MyHost, $MyLogin, $MyPassword);
@mysql_select_db($MyDatabase);
Connect to the database
if ($scale_to_showicons > $map->scale) {
If the actual scale of the map is ok to show the images on the map than
proceed
$mapimagepath = $mappath . $mapurl;
The real path of the image with the map
$mapdim = GetImageSize($mapimagepath);
Get the dimensions of the image
$coords_map_width = $map->extent->maxx - $map->extent->minx;
The geographic width of the map.
$mapscale = $mapdim[img_WIDTH] / $coords_map_width;
The relationship between dimension of the image and the real width of
the map. So now I know every pixel scale on the map.
switch ($mapdim[img_TYPE]) {
case 1: $mapimg = ImageCreateFromGif($mapimagepath); break;
case 2: $mapimg = ImageCreateFromJpeg($mapimagepath); break;
case 3: $mapimg = ImageCreateFromPng($mapimagepath); break;
} ;
Check the type of image generated by the mapserver and create a virtual
image in memory to merge with the icons.
$qry .= "select * from weather where x > '" . $map->extent->minx
. "' AND x < '" . $map->extent->maxx . "' AND y > '" . $map->extent->miny
. "' AND y < '" . $map->extent->maxy . "'";
$res = mysql_query($qry);
Get from the database which icons are visible on the map
$dimicon = GetImageSize($row->imagepath);
Get the dimensions of the icon
switch ($dimic[img_TYPE]) {
case 1: $tmpimg = ImageCreateFromGif($row->imagepath); break;
case 2: $tmpimg =?; ImageCreateFromJpeg($row->imagepath); break;
case 3: $tmpimg = ImageCreateFromPng($row->imagepath); break;
}
Check the type of image and create a virtual image into memory to merge
with the map.
$x = ($row->x - $map->extent->minx) * $mapscale;
$y = $mapdim[img_HEIGHT] - (($row->y - $map->extent->miny) *
$mapscale);
Calculate the position x and y where to put the icon on the map image.
Here I use the relationship pixel->real geographic coordinates
@ImageCopy ($mapimg, $tmpimg, $x, $y, 0, 0, $dimicon[img_WIDTH], $dimic[img_HEIGHT]);
Merge the image with the map
After all the images are merged
switch ($mapdim[img_TYPE]) {
case 1: ImageGif($mapimg, $mapimagepath); break;
case 2: ImageJpeg($mapimg, $mapimagepath); break;
case 3: ImagePng($mapimg, $mapimagepath); break;
}
save the new image on the old map image |