123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- package cn.com.taiji.web.controller;
- import cn.com.taiji.cn.com.taiji.common.domain.Result;
- import cn.com.taiji.cql.model.GeoDataSource;
- import cn.com.taiji.cql.model.GeoRequestParam;
- import cn.com.taiji.tile.service.ITileService;
- import cn.com.taiji.web.service.IGeoDataSourceService;
- import com.alibaba.fastjson.JSONObject;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import javax.servlet.ServletOutputStream;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.util.Enumeration;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * 图层通用查询控制器
- *
- * @author makejava
- * @since 2021-04-22 16:53:35
- */
- @Slf4j
- @RestController
- @Api("图层通用查询控制器")
- public class TileWebController {
- @Autowired
- private ITileService tileService;
- @Autowired
- private IGeoDataSourceService geoDataSourceService;
- @ApiOperation("面向瓦片的点击查询")
- @GetMapping("/queryElements")
- public Result<List<?>> queryElements(String bbox,Integer type,String layerName){
- List<?> list=tileService.queryElements(bbox,type,layerName);
- return Result.ok();
- }
- @RequestMapping(value = {"/queryTile"}, method = {RequestMethod.GET, RequestMethod.POST})
- public void queryTile(HttpServletRequest request, HttpServletResponse response) {
- GeoRequestParam geoRequestParam = JSONObject.parseObject(JSONObject.toJSONString(getParameterMap(request)), GeoRequestParam.class);
- if(geoRequestParam.getLayers() !=null && !"".equals(geoRequestParam.getLayers())){
- try{
- GeoDataSource geoDs = geoDataSourceService.layerCodeGeoDataSource(geoRequestParam.getLayers());
- if(geoDs !=null){
- byte[] ret = tileService.tileData(geoRequestParam,geoDs);
- responseWrite(response, "image/png", ret);
- }else{
- log.info("根据图层代码:" + geoRequestParam.getLayers() + "获取图层对应的数据源为空或者为null");
- }
- }catch (Exception exception){
- exception.printStackTrace();
- log.error("根据图层代码:" + geoRequestParam.getLayers() +"获取数据源信息失败!"+exception);
- }
- }else{
- log.info("图层代码layers参数为空!");
- }
- }
- private void responseWrite(HttpServletResponse response, String contentType, byte[] data) {
- response.setStatus(200);
- response.setContentType(contentType);
- if (data != null) {
- response.setContentLength(data.length);
- ServletOutputStream out = null;
- try {
- out = response.getOutputStream();
- out.write(data);
- out.flush();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (out != null)
- try {
- out.close();
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- }
- }
- }
- /**
- * 将请求参数转化为Map
- *
- * @param request
- * @return
- */
- public static Map<String, Object> getParameterMap(HttpServletRequest request) {
- Map<String, Object> param = new HashMap<>();
- try {
- Enumeration<String> em = request.getParameterNames();
- while (em.hasMoreElements()) {
- String key = em.nextElement();
- param.put(key.toLowerCase(), request.getParameter(key));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return param;
- }
- }
|