Calculating correct map extent/image
jga at scot.cnes.fr
jga at scot.cnes.fr
Fri Mar 9 01:16:42 PST 2001
On 8 Mar, Burkhard Sell wrote:
> hello,
> we are using a java applet to communicate with the mapserver.
>
> for example if we zoom, we send the new map extent to the map server,
> and
> get a image back.
>
> but problem is, that the extent of the image is not the same as the
> requested
> extent, because the server fits it to the screen ratio.
> what must we do to calculate/set the correct extent of the returned
> image?
>
> is there any way to get the data calculated by the server back to the
> client?
>
> we hope anybody can help :-))
>
> Burkhard Sell
Hi,
I wrote this method to calculate the correct extent. It's derived from
the mapserver source code (i didn't remember which .c file :)
/**
*
* This method calculate the correct extent from a box extent.
* Assume x1Extent, y1Extent, x2Extent, y2Extent the requested extent
* x1Coord, y1Coord, x2Coord, y2Coord are the corrected coordinate
*
*/
public void setAdjustedCoordinates() {
float cellsize, ox, oy;
cellsize = (float) (Math.max((x2Extent - x1Extent) / (screenSize.width - 1), (y2Extent - y1Extent) / (screenSize.height - 1)));
if(cellsize <= 0) {
System.out.println(" Error : Invalid coordinates adjustment!");
System.exit(0);
}
ox = ms_NINT( (float) (Math.max(((screenSize.width - 1) - (x2Extent - x1Extent) / cellsize) / 2, 0.0)));
oy = ms_NINT( (float) (Math.max(((screenSize.height - 1) - (y2Extent - y1Extent) / cellsize) / 2, 0.0)));
x1Coord = x1Extent - ox * cellsize;
y1Coord = y1Extent - oy * cellsize;
x2Coord = x2Extent + ox * cellsize;
y2Coord = y2Extent + oy * cellsize;
}
/**
*
* See MS_MINT definition in map.h (cf:mapserver source code)
*
*/
private float ms_NINT(float x) {
if (x >= 0)
return (float) (x + 0.5);
else
return (float) (x - 0.5);
}
Regards
J
--
"Luck doesn't exist. It's just a lack of unluck"
http://j3rome.org
More information about the MapServer-users
mailing list