G
Guest
I've declared four (global) variables eg maxLat which are supposed to
be assigned by load(), however they don't get assigned as if load()
can't see them.
initialising maxLat 'var maxLat =4' passes '4' to my hidden form field
at the bottom so I'm pretty sure the problem is in my function.
I've enough about JavaScript scope (newbie) to be pretty sure I've made
an obvious and simple error which hopefully someone will point out
easily.
Thanks in advance,
R
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<title>FreeWay - Road Mapping</title>
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/freeway.css"/>
<style type="text/css">v\:* {behavior:url(#default#VML);}</style>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<jsp:directive.page
import="java.util.Vector,freeway.mod.GoogleMapsOverlay"/>
<%!GoogleMapsOverlay overlay; %>
<script
src="http://maps.google.com/maps?file=ap...LF1ZPr8ix_G8ZppbBTxcsJtCXZyBSsPCx-hp23hoomRZg"type="text/javascript"></script>
<script type="text/javascript">
var maxLat;
var maxLon;
var minLat;
var minLon;
function load() {
map = new GMap2(document.getElementById("map"));
<%--TODO this should be done dynamically (i.e. on form submission) so
user can manipulate map THEN ask for roads to be loaded--%>
map.setCenter(new GLatLng(53.3884, -6.2566), 20);
var track = new Array();
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
maxLon = northEast.lng();
maxLat = northEast.lat();
minLon = southWest.lng();
minLat = southWest.lat();
<%
if(session.getAttribute("overlay") != null){
overlay = (GoogleMapsOverlay) session.getAttribute("overlay");
Vector lats = overlay.getLastTrackLat();
Vector lons = overlay.getLastTrackLon();
for(int i=0;i<lats.size(); i++){
out.println("track.push(new GLatLng("
+lats.get(i)+ "," + lons.get(i)
+ "));");
}
}
else{System.out.println("Couldn't retrieve overlay object");}
%>
map.addOverlay(new GPolyline(track));
}
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 500px; height: 300px"></div>
<br/>
<form name="dataForm" action="/FreeWay/servlet/MapHelper" method="post"
enctype="multipart/form-data">
<h1>NMEA Data File:</h1>
<fieldset>
<legend>Enter Path</legend>
<label for="uploadfile">File:</label>
<input id="uploadfile" name="uploadfile" type="file" value="null"
/><br />
<label for="loadDb">Get Existing Roads:</label>
<input id="loadDb" type="radio" name="loadType" value="DB" />
<label for="loadFile">Upload File:</label>
<input id="loadFile" type="radio" name="loadType" value=File
checked="checked"/>
</fieldset>
<fieldset>
<input type="submit" value="Go"/>
<input type="reset" value="reset"/>
</fieldset>
<script src="${pageContext.request.contextPath}/bounds.js"
type="text/javascript"></script>
</form>
</body>
</html>
------------------------bounds.js
document.write("<input type=\"hidden\" name=\"maxLat\" value=\"" +
maxLat + "\"/>");
document.write("<input type=\"hidden\" name=\"maxLon\" value=\"" +
maxLon + "\"/>");
document.write("<input type=\"hidden\" name=\"minLat\" value=\"" +
minLat + "\"/>");
document.write("<input type=\"hidden\" name=\"minLon\" value=\"" +
minLon + "\"/>");
be assigned by load(), however they don't get assigned as if load()
can't see them.
initialising maxLat 'var maxLat =4' passes '4' to my hidden form field
at the bottom so I'm pretty sure the problem is in my function.
I've enough about JavaScript scope (newbie) to be pretty sure I've made
an obvious and simple error which hopefully someone will point out
easily.
Thanks in advance,
R
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<title>FreeWay - Road Mapping</title>
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/freeway.css"/>
<style type="text/css">v\:* {behavior:url(#default#VML);}</style>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<jsp:directive.page
import="java.util.Vector,freeway.mod.GoogleMapsOverlay"/>
<%!GoogleMapsOverlay overlay; %>
<script
src="http://maps.google.com/maps?file=ap...LF1ZPr8ix_G8ZppbBTxcsJtCXZyBSsPCx-hp23hoomRZg"type="text/javascript"></script>
<script type="text/javascript">
var maxLat;
var maxLon;
var minLat;
var minLon;
function load() {
map = new GMap2(document.getElementById("map"));
<%--TODO this should be done dynamically (i.e. on form submission) so
user can manipulate map THEN ask for roads to be loaded--%>
map.setCenter(new GLatLng(53.3884, -6.2566), 20);
var track = new Array();
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
maxLon = northEast.lng();
maxLat = northEast.lat();
minLon = southWest.lng();
minLat = southWest.lat();
<%
if(session.getAttribute("overlay") != null){
overlay = (GoogleMapsOverlay) session.getAttribute("overlay");
Vector lats = overlay.getLastTrackLat();
Vector lons = overlay.getLastTrackLon();
for(int i=0;i<lats.size(); i++){
out.println("track.push(new GLatLng("
+lats.get(i)+ "," + lons.get(i)
+ "));");
}
}
else{System.out.println("Couldn't retrieve overlay object");}
%>
map.addOverlay(new GPolyline(track));
}
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 500px; height: 300px"></div>
<br/>
<form name="dataForm" action="/FreeWay/servlet/MapHelper" method="post"
enctype="multipart/form-data">
<h1>NMEA Data File:</h1>
<fieldset>
<legend>Enter Path</legend>
<label for="uploadfile">File:</label>
<input id="uploadfile" name="uploadfile" type="file" value="null"
/><br />
<label for="loadDb">Get Existing Roads:</label>
<input id="loadDb" type="radio" name="loadType" value="DB" />
<label for="loadFile">Upload File:</label>
<input id="loadFile" type="radio" name="loadType" value=File
checked="checked"/>
</fieldset>
<fieldset>
<input type="submit" value="Go"/>
<input type="reset" value="reset"/>
</fieldset>
<script src="${pageContext.request.contextPath}/bounds.js"
type="text/javascript"></script>
</form>
</body>
</html>
------------------------bounds.js
document.write("<input type=\"hidden\" name=\"maxLat\" value=\"" +
maxLat + "\"/>");
document.write("<input type=\"hidden\" name=\"maxLon\" value=\"" +
maxLon + "\"/>");
document.write("<input type=\"hidden\" name=\"minLat\" value=\"" +
minLat + "\"/>");
document.write("<input type=\"hidden\" name=\"minLon\" value=\"" +
minLon + "\"/>");