| | |
| | | ServletServerHttpResponse ssRes = new ServletServerHttpResponse(res); |
| | | |
| | | // 检查缓存是否过期 |
| | | if (checkIfNotModify(ssReq, ssRes)) { |
| | | // 设置缓存头 |
| | | setBrowerCache(ssRes); |
| | | return; |
| | | } |
| | | // if (checkIfNotModify(ssReq, ssRes)) { |
| | | // // 设置缓存头 |
| | | // setBrowerCache(ssRes); |
| | | // return; |
| | | // } |
| | | |
| | | // 设置返回图片类型 |
| | | res.setContentType("image/png"); |
| | |
| | | // 定义输入流,通过输入流读取文件内容 |
| | | FileInputStream fileInputStream; |
| | | |
| | | // y = (1 << z) - y - 1 |
| | | y = (int) Math.pow(2, z) - y - 1; |
| | | String path = config.getTilePath() + File.separator + layer + File.separator + z + File.separator + x + File.separator + y + ".png"; |
| | | |
| | | 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(); |
| | | |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |