Changes between Initial Version and Version 1 of PHPMapscriptSnippet1


Ignore:
Timestamp:
Jan 27, 2009, 9:37:04 AM (15 years ago)
Author:
jmckenna
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PHPMapscriptSnippet1

    v1 v1  
     1Here is a code snippet from Antti Roppola, there is also another example in the GMap demo application that is a little fancier (GMap demo http://www2.dmsolutions.ca/gmap/gmap75.phtml download demo: http://dl.maptools.org/dl/).
     2{{{
     3/**
     4 * converts pixel units into map units
     5 *
     6 * @param int $click_x coordinate X in pixels
     7 * @param int $click_y coordinate Y in pixels
     8 * @param array $current_extent holds the current extent of the map (XMin, YMin, XMax, YMax)
     9 * @global map object
     10 * @return array  [0]=> X in map units; [1]=> Y in map units
     11 */
     12function click2map ($click_x, $click_y, $current_extent) {
     13        global $map;   
     14
     15        $x_pct = ($click_x / $map->width);
     16        $y_pct = 1 - ($click_y / $map->height);
     17       
     18        $x_map = $current_extent[0] + ( ($current_extent[2] - $current_extent[0]) * $x_pct);
     19        $y_map = $current_extent[1] + ( ($current_extent[3] - $current_extent[1]) * $y_pct);
     20
     21        return array($x_map, $y_map);
     22}
     23}}}