管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-02-19 84580a66aa12a0d7832eec116dbbb8bfd1e2364e
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.lf.server.controller.data;
 
import com.lf.server.annotation.SysLog;
import com.lf.server.config.PropertiesConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
 
/**
 * WMTS服务
 * @author WWW
 */
@Api(tags = "数据管理\\WMTS服务")
@RestController
@RequestMapping("/wmts")
public class WmtsController {
    @Autowired
    PropertiesConfig config;
 
    private final static Log log = LogFactory.getLog(WmtsController.class);
 
    @SysLog()
    @ApiOperation(value = "获取WMTS元数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, dataType = "String", defaultValue = "token", paramType = "path")
    })
    @GetMapping("select/{token}/WMTSCapabilities.xml")
    public void selectWmtsCapabilities(@PathVariable(name = "token") String token, HttpServletRequest req, HttpServletResponse res) {
        try {
            ClassPathResource resource = new ClassPathResource("wmts/web.xml");
            if (!resource.exists()) {
                return;
            }
 
            InputStream stream = resource.getInputStream();
            byte[] data = new byte[stream.available()];
            stream.read(data);
            stream.close();
 
            String url = req.getRequestURL().toString().replace("WMTSCapabilities.xml", "tile");
 
            String result = new String(data, StandardCharsets.UTF_8);
            result = result.replace("{url}", url);
            byte[] bytes = result.getBytes(StandardCharsets.UTF_8);
 
            res.setHeader("Content-Type", "application/xml;charset=UTF-8");
            ServletOutputStream os = res.getOutputStream();
            os.write(bytes);
            os.flush();
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
 
    @ApiOperation(value = "获取WMTS瓦片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, dataType = "String", defaultValue = "token", paramType = "path"),
            @ApiImplicitParam(name = "layer", value = "图层类型", required = true, dataType = "String", defaultValue = "TDTIMG"),
            @ApiImplicitParam(name = "tilematrix", value = "层级", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "tilerow", value = "行号", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "tilecol", value = "列号", required = true, dataType = "Integer")
    })
    @GetMapping("select/{token}/tile")
    public void selectWmtsTile(@RequestParam("layer") String layer, @RequestParam("tilematrix") Integer l, @RequestParam("tilerow") Integer r,
                               @RequestParam("tilecol") Integer c, @RequestParam("format") String format, @PathVariable(name = "token") String token,
                               HttpServletRequest req, HttpServletResponse res) {
        try {
            // ServletServerHttpRequest ssRequest = new ServletServerHttpRequest(request)
            String base = config.getTilePath();
 
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
}