| | |
| | | stream.read(data); |
| | | stream.close(); |
| | | |
| | | String url = req.getRequestURL().toString().replace("WMTSCapabilities.xml", "tile"); |
| | | String url = req.getRequestURL().toString().replace("WMTSCapabilities.xml", "tile?"); |
| | | |
| | | String result = new String(data, StandardCharsets.UTF_8); |
| | | result = result.replace("{url}", url); |
| | |
| | | int x = Integer.parseInt(row); |
| | | int y = Integer.parseInt(col); |
| | | |
| | | ServletServerHttpRequest ssReq = new ServletServerHttpRequest(req); |
| | | ServletServerHttpResponse ssRes = new ServletServerHttpResponse(res); |
| | | |
| | | // æ£æ¥ç¼åæ¯å¦è¿æ |
| | | if (checkIfNotModify(ssReq, ssRes)) { |
| | | // 设置ç¼å头 |
| | | setBrowerCache(ssRes); |
| | | return; |
| | | } |
| | | |
| | | // 设置è¿åå¾çç±»å |
| | | res.setContentType("image/png"); |
| | | // 设置ç¼ååæ° |
| | | setBrowerCache(ssRes); |
| | | // éè¿response对象ï¼è·åå°è¾åºæµ |
| | | ServletOutputStream outputStream = res.getOutputStream(); |
| | | // å®ä¹è¾å
¥æµï¼éè¿è¾å
¥æµè¯»åæä»¶å
容 |
| | | FileInputStream fileInputStream; |
| | | |
| | | // y = (int) Math.pow(2, z) - y - 1; |
| | | String path = config.getTilePath() + File.separator + layer + File.separator + z + File.separator + y + File.separator + x + ".png"; |
| | | System.out.println(path); |
| | | |
| | | File file = new File(path); |
| | | if (!file.exists() || file.isDirectory()) { |
| | | ClassPathResource resource = new ClassPathResource("wmts/nofound.png"); |
| | | fileInputStream = new FileInputStream(resource.getFile()); |
| | | } else { |
| | | System.out.println(path); |
| | | fileInputStream = new FileInputStream(file); |
| | | } |
| | | |
| | | int len = 0; |
| | | byte[] bytes = new byte[1024]; |
| | | while ((len = fileInputStream.read(bytes)) != -1) { |
| | | outputStream.write(bytes, 0, len); |
| | | outputStream.flush(); |
| | | } |
| | | |
| | | outputStream.close(); |
| | | fileInputStream.close(); |
| | | getWmtsTile(layer, z, x, y, req, res); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åWMTSç¦ç |
| | | */ |
| | | private void getWmtsTile(String layer, int z, int x, int y, HttpServletRequest req, HttpServletResponse res) throws Exception { |
| | | ServletServerHttpRequest ssReq = new ServletServerHttpRequest(req); |
| | | ServletServerHttpResponse ssRes = new ServletServerHttpResponse(res); |
| | | |
| | | // æ£æ¥ç¼åæ¯å¦è¿æ |
| | | if (checkIfNotModify(ssReq, ssRes)) { |
| | | // 设置ç¼å头 |
| | | setBrowerCache(ssRes); |
| | | return; |
| | | } |
| | | |
| | | // 设置è¿åå¾çç±»å |
| | | res.setContentType("image/png"); |
| | | // 设置ç¼ååæ° |
| | | setBrowerCache(ssRes); |
| | | // éè¿response对象ï¼è·åå°è¾åºæµ |
| | | ServletOutputStream outputStream = res.getOutputStream(); |
| | | // å®ä¹è¾å
¥æµï¼éè¿è¾å
¥æµè¯»åæä»¶å
容 |
| | | FileInputStream fileInputStream; |
| | | |
| | | // y = (int) Math.pow(2, z) - y - 1; |
| | | String path = config.getTilePath() + File.separator + layer + File.separator + z + File.separator + y + File.separator + x + ".png"; |
| | | System.out.println(path); |
| | | |
| | | File file = new File(path); |
| | | if (!file.exists() || file.isDirectory()) { |
| | | ClassPathResource resource = new ClassPathResource("wmts/nofound.png"); |
| | | fileInputStream = new FileInputStream(resource.getFile()); |
| | | } else { |
| | | System.out.println(path); |
| | | fileInputStream = new FileInputStream(file); |
| | | } |
| | | |
| | | int len = 0; |
| | | byte[] bytes = new byte[1024]; |
| | | while ((len = fileInputStream.read(bytes)) != -1) { |
| | | outputStream.write(bytes, 0, len); |
| | | outputStream.flush(); |
| | | } |
| | | |
| | | outputStream.close(); |
| | | fileInputStream.close(); |
| | | } |
| | | |
| | | /** |
| | | * 设置æµè§å¨ç¼ååæ° |
| | | */ |
| | | private void setBrowerCache(ServerHttpResponse res) { |