[Mapserver-users] Map Extent
Eric Bridger
eric at gomoos.org
Mon Feb 3 05:45:39 PST 2003
Hi all. I am a new mapserver, mapscript user, about 2 weeks now. So
first my thanks to all involved in developing a truly excellent
application. We are using Mapserver 3.6.4 and mapscript to develop an
Linux Apache/mod-perl oceanographic application.
I am having trouble mapping the users map image mouse click to map
coordinates with precision. At first I thought it might be the
registration of the map datasets we were using (shape files) with one
shaded relief jpg, so I switched to using the states_ugl data and the
s1ex1.map from the 3.6 tutorial in a simple mapscript test and noticed
the same issues.
When adding a point symbol to the map at the location clicked, the
symbol appears near where I expected but not exactly where I expected.
The closer I click to the center of the map the closer the symbol
registers. It appears to me that the y-coordinate is always on target,
but that the x corrdinate is off. The closer to the edges of the map,
the further off the x coordinate is.
Perhaps this has to do with the fact that the map created 400x300 goes
all the way from y=0 to y=400, but not from x=0 to x=300?
The mapextent is gotten from the map object created from the map file.
I calculate the map coordinates with code adapted from the mapquakes.pl
example:
if($q->param('img.x') && $q->param('imgext')) { # Make sure we got a
click
@imgext = split(' ', $q->param('imgext'));
$x = $q->param('img.x');
$y = $q->param('img.y');
$cx = ($imgext[2]-$imgext[0])/($map->{width}-1);
$cy = ($imgext[3]-$imgext[1])/($map->{height}-1);
$x = $imgext[0] + $cx*$x;
$y = $imgext[3] - $cy*$y;
}
Create a point object and add it to the map and display it.
Par of the map file:
MAP
EXTENT -97.238976 41.619778 -82.122902 49.38562
SIZE 400 300
SHAPEPATH "/home/eric/work/htdocs/mapserver/tutorial35/data"
# Added by EB
IMAGETYPE PNG
UNITS DD
LAYER # States
NAME "lobster_zones"
DATA states_ugl
STATUS DEFAULT
TYPE POLYGON
CLASSITEM "STATE"
CLASS
NAME "Michigan"
COLOR 255 255 128
OUTLINECOLOR 0 0 0
END # end of class object
END # end of layer object
....
Thanks.
Eric Bridger
eric at gomoos.org
Gulf of Maine Ocean Observing System www.gomoos.org
More information about the MapServer-users
mailing list