PHPMapScript : pixels to geo problem using dynamic symbols
Geoff Rowland
geoffrey.rowland at NOAA.GOV
Mon Mar 7 07:39:02 PST 2005
I am testing out creating dynamic symbols on a map using examples on the
wiki. If I click on the center of the map, it works fine. However as I
get to the outer regions of the map, the Y position is correct, but the
X position is off. Any idea what is causing this? I'm sure it's obvious
I am overlooking.
the example I am testing out can be viewed here
http://www.ranetproject.net/apps/maps/ms/africa_view2.php
here is my map file
NAME "Africa"
SIZE 800 600
STATUS ON
EXTENT -17.533 -46.970 55.541 37.340
UNITS METERS
SHAPEPATH "data"
WEB
IMAGEPATH "f:\inetpub\ranet\apps\maps\ms\tmp\"
IMAGEURL "tmp/"
END
SYMBOL
NAME 'star'
TYPE VECTOR
FILLED TRUE
POINTS
0 .375
.35 .375
.5 0
.65 .375
1 .375
.75 .625
.875 1
.5 .75
.125 1
.25 .625
END
END
LAYER
NAME "INLINE"
TYPE POINT
STATUS ON
CLASS
NAME "0"
STYLE
COLOR 255 0 0 # red
SYMBOL 'star'
SIZE 16
END #style
END #class
END #layer
LAYER
NAME "Africa"
TYPE POLYGON
STATUS ON
DATA "africa"
CLASS
STYLE
COLOR 255 243 227
OUTLINECOLOR 200 200 200
SYMBOL 0
END
END
END
END
and here is my php code (just using example code)
<?
//Convert pixels to map units (got from PHPMapscriptSnippet1)
function click2map ($click_x, $click_y) {
global $map;
$e= &$map->extent; //for saving writing
$x_pct = ($click_x / $map->width);
$y_pct = 1 - ($click_y / $map->height);
$x_map = $e->minx + ( ($e->maxx - $e->minx) * $x_pct);
$y_map = $e->miny + ( ($e->maxy - $e->miny) * $y_pct);
return array($x_map, $y_map);
}
$map= ms_newMapObj('africa.map');
//Convert pixels to map units
$map_pt = click2map($_GET['image_x'],$_GET['image_y'],$map->extent);
//Create the point
$pt = ms_newPointObj();
$pt-> setXY($map_pt[0],$map_pt[1]);
//Draw the map and add the point
$img = $map->draw();
$layer = $map->getLayerByName('INLINE');
$pt->draw($map, $layer, $img, 0 ,'yuhuu');
$url = $img->saveWebImage();
?>
<html><head></head><body>
<form method="get" action="africa_view2.php" >
<input style="border:thin solid black;" type="image"
name="image" src="<?php echo $url?>" />
</form>
<pre>
<!-- Debug Lines -->
<?php
echo "GET\n";
print_r($_GET);
echo "Point:\n";
print_r($pt); ?>
?>
</pre>
</body>
</html>
--
Geoffrey Rowland
Technical Officer
Climate Information Project
NOAA Research
Office of Global Programs
http://www.cip.noaa.gov
http://www.ranetproject.net
Contractor,
RGII Technologies, Inc., a Computer Horizons Company
http://www.rg2.com
Phone: 301-427-2089x186
Fax : 301-427-2082
geoffrey.rowland at noaa.gov
More information about the MapServer-users
mailing list