본문 바로가기

develop/web GIS

OpenLayers addfeatures(json) 에서 json형식 java에서 만들기


public class IndexControl {

IndexCode indexCode ;

SbbDBMapper sbbMapper;

public List<IndexCode> getIndexCode(HttpServletResponse response) throws Exception {

DBUtils dbUtils = new DBUtils();

List<IndexCode> getIndex = dbUtils.selectList(DB.SBB_DB, "getIndexCode"); 

JSONObject jsonObj= new JSONObject();

JSONObject jsonObj1= new JSONObject();

JSONObject jsonObj2= new JSONObject();

JSONObject jsonObj3= new JSONObject();

JSONArray jsonArray = new JSONArray();

for(int i=0; i<getIndex.size(); i++) {

jsonObj1.put("type", "Feature");

jsonObj1.put("geometry", jsonObj2);

jsonObj2.put("type", "Point");

jsonObj2.put("coordinates", getIndex.get(i).getLat());

jsonObj1.put("properties", jsonObj3);

jsonObj3.put("location",getIndex.get(i).getStnKo());

jsonArray.put(jsonObj1);

}

jsonObj.put("features", jsonArray);

System.out.println("jsonObj : " +jsonObj);

response.setContentType("application/x-json; charset=UTF-8");

response.getWriter().print(jsonObj); 

return getIndex;

}

}



'develop > web GIS' 카테고리의 다른 글

지도위에 구글차트 띄우기  (0) 2015.02.05
EPSG:4326 to EPSG:900913 transform  (0) 2014.11.19
레이어 클릭시 이벤트 발생  (0) 2014.11.16
마커 생성 및 라벨 수정  (0) 2014.11.14
좌표로 폴리곤 표현  (0) 2014.11.14