Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
PHP - GD - ImageMAP - Problems

Posted by drgonzo46567 (drgonzo46567), 20 July 2004
Hello,

Would anyone here be willing to lend a hand at further customizing a world map plotting script written in PHP?

The following script gathers a couple values from a database and plots an imagefilledrectangle and imagestring value for each row.

We are gathering long/lat coords from volunteers participating in our current project - Magnetic Pole Shift Monitoring.  http://www.data4science.net/poleshift converting them into image pixels, and then returning a world map image with the plots and readings on it..

This script works fine. however due to the large number of users we have and the close proximity of each coordinate pair, overlapping plots(rectangles/strings) are occuring.  I am in need of a way to EITHER setup an image map from the original created image, which takes the user to an additional image (say North America only) and resizes the image to show the plots more spaced apart. OR help to re-structure my submission forms and mysql database to better accomplish this.

The current function getlocationcoords() only converts the pairs from the full sized (entire world map) image, thus returning "off plotted data" on a smaller section of the original map.  

Is it possible to imagemap the <img src="plot.php"> tag in my html page? if so, will imageresize(or the correct function i WOULD need) enlarge the section of the image thus spreading apart the overlapped plots?

Would i have to use a seperate plot script for the section of the original map, and re-write the function to accommodate for the smaller image? This would also require only pulling values from the SQL rows (lat/lon pairs) that were physically within the boundaries of the smaller image's location.

Was that as confusing as I thought it was? Can anyone help me? I'd do just about anything in return for some advice or even someone to take the time and help me set it up.  You'd be well thanked on the website also If that happens to hold any value to you..

Our site has just recently been listed on Jeff Rense - News Site www.rense.com and Radio and here in a few days, Art Bell & CoasttoCoastam.com


Chris Bake
cbake@u4internet.com
*Feel free to email me about anything that you think may help me out. Thanks in advance!


Here's the script:


<?php
// Define Coords locator Function
function getlocationcoords($lat, $lon, $width, $height)
{  
   $x = (($lon + 186) * ($width / 360));
   $y = ((($lat * -1) + 8 * ($height / 180));
   return array("x"=>round($x),"y"=>round($y));
}

// Connect and Retrieve DB entries
$link=mysql_connect("localhost", "user", "password") or die("Could not connect : " . mysql_error());
mysql_select_db("poleshift", $link) or die("Could not select database");
$result=mysql_query("SELECT DISTINCT * FROM pole") or die("No database records found");

// Call Image
$im = imagecreatefromjpeg("bkglobe.jpg");

 
// Scale image pixels and set to variables  
$scale_x = imagesx($im);
$scale_y = imagesy($im);

// Loop though each element of the array loaded from the DB

while ($myrow=mysql_fetch_array($result)) {

// Set collected DB data to variables for each point
$lat = $myrow['latitude'];
$lon = $myrow['longitude'];

$reading = $myrow['reading'];  

// Detect CompassType and Set Color for Map Point
switch ($myrow['compasstype'])
{
case "Mechanical Compass":
$color = imagecolorallocate ($im, 150,150,0);  // Green Dot
Break;
case "Electronic Compass":
$color = imagecolorallocate ($im, 255,0,0);  //  Red Dot
Break;
case "GPS":
$color = imagecolorallocate ($im, 0,0,255);  // Blue Dot
Break;
default:
$color = imagecolorallocate ($im, 0,0,0);  // Default Block Dot
Break;
}
 


// Plot points

 $pt = getlocationcoords($lat,$lon, $scale_x, $scale_y);
  imagefilledrectangle($im,$pt["x"]-1.5,
                       $pt["y"]-1.5,$pt["x"]+1.5,$pt["y"]+1.5,$color);
 
  $textheight = (imagefontheight(2)/2);
imagestring($im,2,$pt["x"]+5,$pt["y"]-$textheight,$reading,$color);

}  // End Plot Loop


// Create Image
imagejpeg($im,"",80);

//Clear Image
imagedestroy($im);

?>

Edited to correct URL to Chris's site. Chris - please feel free to edit our this comment once you have read it
- Graham




This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho