[Mapserver-users] Problems in Cursor Coordinate Display on Status Bar Using Mapplet

Bruce, Bob CON BBruce at gov.mb.ca
Mon May 26 15:42:37 EDT 2003


I have been working my way through the tutorials to learn how to implement
the MapServer and have hit a snag with the Mapplet. I can get it to work OK
with the zoom box but I cannot get it to display the cursor coordinates. I
have looked at the past messages on this listserv and tried to follow their
instructions to no avail, and have also consulted the Mini-HowTo about the
mapplet to see how to do this - still no success.

So, this is what I've done:

1) I put in the Javascript function: mapplet_mouse_moved(name,x,y) that was
described in an earlier message, and couldn't get a cursor display,
2) the Mapplet Mini-HowTo mentions a different function: mapOver(x,y) , I
put that in and also didn't get a display of the cursor coordinates,

so I'm stuck at the moment and wonder if someone out there has an answer to
fix this problem.
My HTML code in the template looks as follows:

<html>
  <head>
    <title>MapServer Tutorial - Section 3, Example 5 - Zoom Rectangle and
Cursor Coordinate Display</title>
	<link type="text/css" rel="stylesheet" href="../ms35.css" />
<script>
    //functions called from within the mapimage applet that allow us
    //to do box zooms and queries
    function mapOver(x,y) {
      // geographic coordinate translation goes here
      document.mapserv.mapOverX.value = x;
      document.mapserv.mapOverY.value = y;
      // option to window status bar output
      window.status = "x: " + x + " y: " + y;
    }
    function mapplet_mouse_moved(name,x,y) {
      var imgext = '[imgext]';
      var mapext = '[mapext]';
      var mapsize = '[mapsize]';

      mapsizeArray = mapsize.split(' ');

      if (imgext != '' && mapext == '') {
        imgextArray = imgext.split(' ');
      }
      else if (mapext != '' && imgext == '') {
        imgextArray = mapext.split(' ');
      }
      else if (mapext != '' && imgext != '') {
        imgextArray = mapext.split(' ');
      }
      else {
        imgextArray = '';
      }

      if (imgextArray != '') {
        coordx = imgextArray[0]*1 +
(x*(imgextArray[2]-imgextArray[0])/mapsizeArray[0]);
        coordy = imgextArray[3] -
(y*(imgextArray[3]-imgextArray[1])/mapsizeArray[1]);
      }
      else {
        coordx = '';
        coordy = '';
      }
      with (Math) {
        window.status = "X: " + round(coordx) + " Y: " + round(coordy);
      }
    }
    function mapplet_apply(name, minx, miny, maxx, maxy, redraw) {
      document.mapserv.imgbox.value = minx + " " + miny + " " + maxx + " " +
maxy;
      document.mapserv.imgxy.value = minx + " " + miny;
    }
    function mapplet_error(message) {
      alert(message);
    }
</script>
  </head>

  <body>
<h3>Section 3<br>
  Example 5 &#150; Zoom Rectangle and Cursor Coordinate Display</h3>
<p>This&nbsp; used.</p>
<p>
    <!-- <form method="GET" action="/cgi-bin/mapserv.exe"> -->
    <form method="GET" name="mapserv" action="/cgi-bin/mapserv.exe">
    <input type="hidden" name="map" value="[map]">
    <input type="hidden" name="imgext" value="[mapext]">
    <input type="hidden" name="imgbox" value="-1 -1 -1 -1">
    <input type="hidden" name="imgxy" value="302.5 242.5">
    [<a href="/bbruce/tileswwinnipeg/s3/TilesWWinnipeg-s3ex5_map.html">map
file listing</a>]
    [<a
href="/bbruce/tileswwinnipeg/s3/TilesWWinnipeg-s3ex5_code.html">template
file listing</a>]
    <table border=1 cellpadding=3 width="822">
    <tr>
    <td align=center valign=middle width="652">
      <table border="0" width="100%">
        <tr>
          <td width="33%">[minx]</td>
          <td width="33%">
      <center>[maxy]</center></td>
          <td width="34%">
            <p align="right">[maxx]</td>
        </tr>
        <tr>
          <td width="100%" colspan="3">
            <p align="center">
           <!-- <input type="image" name="img" src="[img]" border="0"> -->
  	        <applet codebase="/bbruce/java" code="mapplet.class"
width="606"
               height="486" name="mapplet" MAYSCRIPT> 
		<param name="image" value="http://[host][img]">
		<PARAM NAME="jitter" VALUE="1">
		<PARAM NAME="color"  VALUE="red">
		<PARAM NAME="thickness" VALUE="2">
	      </applet>
            </td>
        </tr>
        <tr>
          <td width="33%">[minx]</td>
          <td width="33%"><center>[miny]</center>
          </td>
          <td width="34%">
            <p align="right">[maxx]</td>
        </tr>
        <tr>
          <td width="33%"></td>
          <td width="33%"><center>Scale 1:[scale]</center>
          </td>
          <td width="34%"></td>
        </tr>
      </table>
    </td>
    <td valign=top width="146">
      <font size=+1 face=arial,helvetica>Map Controls</font>
      <p>
		<input type="submit" name="submit" value="Refresh/Query">
          <br>
      Set your zoom option:<br>
      <select name="zoom" size="1">
      <option value="10" [zoom_10_select]> Zoom in 10 times
      <option value="8" [zoom_8_select]> Zoom in 8 times
      <option value="4" [zoom_4_select]> Zoom in 4 times
      <option value="3" [zoom_3_select]> Zoom in 3 times
      <option value="2" [zoom_2_select]> Zoom in 2 times
      <option value="1"  [zoom_1_select]> Recenter Map
      <option value="-2" [zoom_-2_select]> Zoom out 2 times
      <option value="-3" [zoom_-3_select]> Zoom out 3 times
      <option value="-4" [zoom_-4_select]> Zoom out 4 times
      <option value="-8" [zoom_-8_select]> Zoom out 8 times
      <option value="-10" [zoom_-10_select]> Zoom out 10 times
      </select>
      <br>
		<select name="mode">
		  <option value="browse">Browse</option>
		  <option value="query">Single-Layer Query</option>
		  <option value="nquery">Multi-Layer Query</option>
		</select>
      <p>
      <font face=arial,helvetica><b>Legend</b></font><br>
      <img src="[legend]"><p>
      <!-- <img src="[ref]"> -->
      <!-- <input type="image" name="ref" src="[ref]" border="0"> -->
      <img src="[ref]">
    </td>
    </tr></table>
</form>

thanks for your help,
				Bob Bruce

****************************************************************************
****************************** 
**    Bob Bruce, P.Eng.         Geomatics Support Engineer 
**    bbruce at gov.mb.ca          Manitoba Geomatics/Remote Sensing Branch, 
**    work # (204) 945-6636             1007 Century Street, 
**    home # (204) 256-4615             Winnipeg, Manitoba, Canada, R3H 0W4 
**    FAX  # (204) 945-1365             
** 
**    The Manitoba Centre for:  
**      Cadastral & Topographical Mapping, and Remote Sensing 
**      See us on the Web at: http://www.gov.mb.ca/conservation/geomatics/
<http://www.gov.mb.ca/conservation/geomatics/cada_mapping/index.html>
cada_mapping/index.html
**          and: http://www.gov.mb.ca/conservation/geomatics/index.html 
**      Check out our digital maps at: http://mli.gov.mb.ca/
<http://mli.gov.mb.ca/>  
****************************************************************************
******************************




More information about the mapserver-users mailing list