Java Script questions

Doug Nebert ddnebert at usgs.gov
Thu Oct 28 13:39:47 PDT 1999


I have been attempting to apply the mapimage.java implementation 
and have been having a number of problems: mostly due to lack of 
proficiency with JavaScript and the exchange of information between 
HTML and the applet. 

Current implementation: http://clearinghouse3.fgdc.gov/global.html

The short explanation is that I cannot get the map to zoom. If I 
use a setting as suggested: 

<param name="image" value="http://clearinghouse3.fgdc.gov[img]">

First of all I don't see the map, just a big blue image. Which implies 
that I am actually seeing the map, but am stuck out in the ocean 
at some pixel coordinates instead of at some "geographic" coordinates.
I notice that if I use the rectangle box to zoom it is somehow setting 
&imgbox=102+45+270+143 in the GET call I see, but that doesn't 
mean much in the registered image coordinates.  I need to be able 
to translate the pixel coordinates into the "lat-long" coordinates 
1) to pass to the mapserver to help formulate a &mapext and 2) to 
report the rectangle's coordinates out to the HTML form using it 
for other purposes. I am not sure how to approach this and whether/how 
to use Java or JavaScript to enable it. As a side note, I do want to 
be able to use this map selection in the context of a bigger "form" 
to which I can post the coordinates pulled from the map. This may 
suggest that I need to use Java exclusively as a component in a 
bigger form, right?

This will take several steps:

1. Store the current latitude and longitude values for the displayed 
map. On startup these are: latmin = -90, latmax = 90, longmin = -180, 
and longmax = 180 though these could also be set in the calling 
HTML file for different startup regions. Where/how do I do this?

2. Collect a rectangle within the java applet. This appears to set
imgxy and imgbox values as the pixel coordinates measureed from the 
upper left corner of the canvas. This seems to be done already.

3. I think that one would need to calculate the appropriate
map dimensions to grab based on the doodled rectangle. One would 
determine the coordinate bounds of a rectangle that more than 
encloses the selected rectangular region. I will always request a 
map that is twice as wide as it is tall (360 W-E x 180 N-S degrees 
sets my design aspect ratio). This seems to be done instead inside 
the applet:

SetImageBox(\"" + Math.min(x1,x2) + " " + Math.min(y1,y2) + " " 
+ Math.max(x1,x2) + " " + Math.max(y1,y2) + "\"); ");

Doesn't this request pixel coordinates rather than geographic 
coordinates? I need some external control to derive not the 
imgbox but two mapext values and pack them into the GET command:
I need the requested map extent, and I need the selected rectangle 
bounds drawn on it. The transformation math is as follows:

xCoord = longmin + (( x / wide ) * ( longmax - longmin ));
yCoord = latmin + ((( tall - y ) / tall ) * ( latmax - latmin ));

where wide = 500 and tall = 250 as integer pixel values. 

How do I differentiate between the red rectangle coordinates and 
the mapext requesting coordinates? I need to set and manage both.

4. Request a map with the correct latitude and longitude values
expressed in the &mapext settings, and not use "zoom" at all 
via the GET method (or java equivalent).

5. Have the selection rectangle shown in red on the resulting map.

Tutorial advice on how to achieve this would be appreciated, as 
I am sure many of you have dealt with these kind of issues before. 
By your suggestions, I can better understand how this all works.
As I describe it here, I come to the conclusion that I probably 
need a full java applet to do all the interaction I need... Any
suggestions or examples?

-- 
Douglas D. Nebert
Clearinghouse Coordinator 
FGDC Secretariat	Phone: +1 703 648 4151	Fax: +1 703 648-5755	
Pager Messaging: 	http://fgdclearhs.er.usgs.gov/dougmsg.html



More information about the MapServer-users mailing list