好吧所以我使用primefaces gmap来显示从数据库中检索的多个多边形,但是我不能让它显示在页面上,我知道坐标正确传递,我的代码代码类似于在主要面上展示http://www.primefaces.org/showcase/ui/data/gmap/polygons.xhtml 所以基本上我很难过。 这是我的支持bean代码
@PostConstruct
public void init() {
try {
Class.forName("com.mysql.jdbc.Driver");
DBConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/demeter2.0", "root", "root");
} catch (SQLException ex) {
Logger.getLogger(Animal.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Animal.class.getName()).log(Level.SEVERE, null, ex);
}
PreparedStatement ps = null;
try {
if (DBConn != null) {
String sql = "SELECT ST_AsText(markers) FROM paddock WHERE idPaddock > 0";
ps = (PreparedStatement) DBConn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
polygonModel = new DefaultMapModel();
if (!rs.next()) {
//return null;
} else {
rs.beforeFirst();
Polygon polygon = new Polygon();
while (rs.next()) {
String value = rs.getString(1);
String valuereal = value.replaceAll("[^0-9 .,]+", "");
ArrayList<String> myList = new ArrayList<String>(Arrays.asList(valuereal.split(",")));
myList.remove(myList.size() - 1);
for (String coordString : myList) {
String[] parts = coordString.split(" ");
String latS = parts[0];
String lngS = parts[1];
double lat = Double.parseDouble(latS);
double lng = Double.parseDouble(lngS);
LatLng coord = new LatLng(lat, lng);
polygon.getPaths().add(coord);
System.out.println(coord);
}
polygon.setStrokeColor("#FF9900");
polygon.setFillColor("#FF9900");
polygon.setStrokeOpacity(0.7);
polygon.setFillOpacity(0.7);
polygonModel.addOverlay(polygon);
}//end while
}
}
} catch (Exception e) {
System.out.println(e);
} finally {
try {
ps.close();
DBConn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
和JSF代码
<h:form prependId="false">
<p:growl id="growl" life="3000" showDetail="true" />
<p:gmap id="gmap" center="36.890257,30.707417" zoom="13" type="HYBRID" style="width:100%;height:400px" model="#{paddock.polygonModel}">
<p:ajax event="overlaySelect" listener="#{paddock.onPolygonSelect}" update="growl" />
</p:gmap>
</h:form>