1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| @Controller @RequestMapping(value = "/history") @Slf4j public class MapController { @Autowired private MapService mapService;
@ResponseBody @GetMapping("/geometry") public JSONObject getPoint(@RequestParam("category") String category,@RequestParam("start") Integer start,@RequestParam("end") Integer end){ try { List<GeometryModel> result = mapService.getDynastyGeom(category, start, end); JSONObject jsonObject = new JSONObject(); jsonObject.put("number", result.size()); JSONArray jsonArray = new JSONArray(); for (GeometryModel g : result) { JSONObject geom = new JSONObject(); geom.put("gid", g.getGId()); geom.put("namepy", g.getNamePy()); geom.put("namech", g.getNameCh()); geom.put("nameft", g.getNameFt()); geom.put("presloc", g.getPresLoc()); geom.put("typepy", g.getTypePy()); geom.put("typech", g.getTypeCh()); geom.put("levrank", g.getLevRank()); geom.put("begyr", g.getBegYr()); geom.put("begrule", g.getBegRule()); geom.put("endyr", g.getEndYr()); geom.put("endrule", g.getEndRule()); geom.put("geosrc", g.getGeoSrc()); geom.put("compiler", g.getCompiler()); geom.put("gecomplr", g.getGecomplr()); geom.put("checker", g.getChecker()); geom.put("entdate", g.getEntDate()); geom.put("begchgty", g.getBegChgTy()); geom.put("endchgty", g.getEndChgTy()); geom.put("geometry", geometryToJson(g.getGeometry())); jsonArray.add(geom); } jsonObject.put("list", jsonArray); log.info("入参类别:{},起始时间:{},截止时间:{}", category, start, end); return jsonObject; }catch (Exception e){ log.error("程序错误类型:",e); return null; } }
private JSONObject geometryToJson(Geometry geometry){ JSONObject jsonObject=new JSONObject(); jsonObject.put("type",geometry.getGeometryType()); JSONArray coorList=new JSONArray(); for (int i=0;i<geometry.getNumGeometries();i++){ JSONArray coors=new JSONArray(); Coordinate[] coordinates=geometry.getGeometryN(i).getCoordinates(); for (Coordinate c:coordinates) { JSONObject jsonObjectCoor=new JSONObject(); jsonObjectCoor.put("lng",c.x); jsonObjectCoor.put("lat",c.y); coors.add(jsonObjectCoor); } coorList.add(coors); } jsonObject.put("coordinates",coorList); return jsonObject; } }
|