openlayers从数据库加载坐标点

页面请求

        itsLayer.setSource(new ol.source.Vector({
            format : new ol.format.GeoJSON(),
            url : "two/showpoint.do?leaves=" + zoom + "&layers=" + layerArr[i] 
        }));

java后台接收

 。。。。。。

		StringBuffer sb = new StringBuffer();
		sb.append("{\"type\": \"FeatureCollection\",\"features\": [");
		if(pointList == null||pointList.size()==0){
			System.out.println("空的不必要");
		}else{
			int i = 0;
				for (Point p : pointList) {
					if(layers.contains(p.getLayers())){
						if(i==0){
							sb.append("{\"type\":\"Feature\",\"id\":\""+p.getIds()+"\",\"properties\":{\"name\":\""+p.getName()+"\",\"leaves\":"+p.getLeaves()+",\"layers\":"+p.getLayers()+"},\"geometry\":{\"type\":\"Point\",\"coordinates\":["+p.getX()+","+p.getY()+"]}}");
							i=i+1;				
						}else{
							sb.append(",{\"type\":\"Feature\",\"id\":\""+p.getIds()+"\",\"properties\":{\"name\":\""+p.getName()+"\",\"leaves\":"+p.getLeaves()+",\"layers\":"+p.getLayers()+"},\"geometry\":{\"type\":\"Point\",\"coordinates\":["+p.getX()+","+p.getY()+"]}}");
						}
					}
				}
		}
		sb.append("]}");

 OK

你可能感兴趣的:(openlayers)