[英]How to pass/use jstl arrayList in javascript?
I have a webpage with a form, where once the latitude and a longitude are entered (along with other data) and submitted, these data are saved in mongo database and at the same time a marker is place on a Google map. 我有一个带有表单的网页,一旦输入了纬度和经度(以及其他数据)并提交了这些数据,这些数据将保存在mongo数据库中,同时在Google地图上放置标记。 So , as I submit new lat/lng data, I have a new marker added on the map and so on. 因此,当我提交新的经/纬度数据时,我在地图上添加了一个新标记,依此类推。 Now the problem is , when I switch to another page of the website and I come back to the previous page (with the map), I still have the map, but without the markers. 现在的问题是,当我切换到网站的另一页并返回上一页(带有地图)时,我仍然具有该地图,但是没有标记。 So each time I go to the page with the map, I want the markers whose lat/lng are in the database be displayed. 因此,每次我转到带有地图的页面时,我都希望显示其纬度/经度在数据库中的标记。 In other words I want to retrieve the data from the database (if there are some) and display the markers on the map each time I am on/switch to that page. 换句话说,我想从数据库中检索数据(如果有的话),并且每次我进入/切换到该页面时都在地图上显示标记。 I am facing some problems implementing a code for that and I would appreciate if someone could have a look at the following code and tell me what I am doing wrong . 我在为此实现代码时遇到一些问题,如果有人可以看一下下面的代码并告诉我我做错了,我将不胜感激。
Thanks in advance for your help. 在此先感谢您的帮助。
Here is the code : 这是代码:
AdminWebControler.java AdminWebControler.java
/**
*
* @output ModelAndView
* @description redirect to dashboard
*/
@RequestMapping(value = "/adminDashboard", method = RequestMethod.GET)
public ModelAndView adminPage() {
userDao.updateLastLogin(getCurrentUser());
final ModelAndView model = new ModelAndView();
model.addObject("iLiteList", getAllILites());
model.setViewName("adminDashboard");
return model;
}
WebcontrollerUtilities.java` WebcontrollerUtilities.java`
protected List<ILites> getAllILites(){
ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class);
MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
List<ILites> ilites = mongoOperation.findAll(ILites.class, "ILites");
System.out.println("4. Number of Ilites in the database = " + ilites.size());
return ilites;
}
ILites.java ILites.java
package mongodb.model;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Document(collection = "ILiteDB")
public class ILites {
private Double latitude;
private Double longitude;
/**
*
* @param longitude
* @param latitude
*/
public ILites( final Double latitude,final Double longitude) {
super();
this.longitude = longitude;
this.latitude = latitude;
}
public Double getLatitude() {
return latitude;
}
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
public Double getLongitude() {
return longitude;
}
public void setLongitude(Double longitude) {
this.longitude = longitude;
}
}
adminDashboard.jsp (part of the jsp code (row where the map is displayed) ) adminDashboard.jsp(jsp代码的一部分(显示地图的行))
<div class="row">
<h4>
<strong>I-Lite Network View</strong>
</h4>
<div>
<hr class="Horizontal_divider_main" />
</div>
<c:choose>
<c:when test="${not empty iLiteList}">
<div class="row" id="googleMap" style="width: 100%; height: 50%; margin-left: 3px;"> </div>
</c:when>
<c:otherwise>
<script type="text/javascript">
var lat = new array();
<c:forEach items="${iLiteList}" var="ilites" >
//lat.push('${ilites.latitude}');
lat.push('<c:out value='${ilites.latitude}' />');
</c:forEach>
var lng = new array();
<c:forEach items="${iLiteList}" var="ilites" >
//lng.push('${ilites.longitude}');
lng.push('<c:out value='${ilites.longitude}' />');
</c:forEach>
for (i = 0; i < lat.length; i++) {
var latLng = new google.maps.LatLng(lat[i], lng[i]);
var marker = new google.maps.Marker({
position: latLng,
map: map,
});
marker.setMap(map);
var infowindow = new google.maps.InfoWindow({
content: 'Latitude: ' + location.latitude + '<br>Longitude: ' + location.longitude
});
google.maps.event.addListener(marker, 'click', function() {
coordinates(map, marker, infowindow)});
function coordinates(map, marker,infowindow){
infowindow.open(map,marker);
}
}
</script>
</c:otherwise>
</c:choose>
</div>
map.js map.js
var myCenter=new google.maps.LatLng(48.2188,11.6248);
var map;
function initialize()
{
var mapProp = {
center:myCenter,
zoom:18,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize
var jsList = new Array();
<c:forEach items="${javaList}" var="javaLvar" varStatus="status">
objJs = new Object();
objJs.someProperty = ${javaLvar};
jsList.push(objJs);
</c:forEach>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.