|
@@ -38,18 +38,40 @@ import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* 生成图片服务
|
|
|
*/
|
|
|
@Service
|
|
|
public class ImageServiceImpl implements IImageService {
|
|
|
+ @Value("${Path.WinRsImage}")
|
|
|
+ public String winRsImage;
|
|
|
+ @Value("${Path.LinuxRxImage}")
|
|
|
+ public String linuxRxImage;
|
|
|
|
|
|
- @Value("${Path.rsImage}")
|
|
|
- public String rsImage;
|
|
|
+ @Value("${Path.WinRootPath}")
|
|
|
+ public String WinRootPath;
|
|
|
+ @Value("${Path.LinuxRootPath}")
|
|
|
+ public String LinuxRootPath;
|
|
|
|
|
|
@Override
|
|
|
public String getSensingImage(WktsVo wktsVo) throws Exception {
|
|
|
+ String rsImage = winRsImage;
|
|
|
+ String rootPath = WinRootPath;
|
|
|
+ if (System.getProperty("os.name").toLowerCase().contains("linux")) {
|
|
|
+ rsImage = linuxRxImage;
|
|
|
+ rootPath = LinuxRootPath;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 图片保存路径
|
|
|
+ String fileDir = rootPath + "/images/" + UUID.randomUUID().toString() + "/";
|
|
|
+ File dir = new File(fileDir);
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ String filePath=fileDir + System.currentTimeMillis()+".png";
|
|
|
+
|
|
|
// 创建一个 MapContent 对象
|
|
|
MapContent mapContent = new MapContent();
|
|
|
mapContent.setTitle("Quickstart");
|
|
@@ -101,10 +123,10 @@ public class ImageServiceImpl implements IImageService {
|
|
|
combinedBounds.expandBy(expandWidth, expandHeight);
|
|
|
|
|
|
// 将地图绘制到图片
|
|
|
- File outputFile = new File("states.png");
|
|
|
+ File outputFile = new File(filePath);
|
|
|
try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile); ImageOutputStream outputImageFile = ImageIO.createImageOutputStream(fileOutputStream);) {
|
|
|
|
|
|
- int w = 1000;
|
|
|
+ int w = 600;
|
|
|
int h = (int) (w * (combinedBounds.getHeight() / combinedBounds.getWidth()));
|
|
|
BufferedImage bufferedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
|
|
|
Graphics2D g2d = bufferedImage.createGraphics();
|
|
@@ -131,7 +153,7 @@ public class ImageServiceImpl implements IImageService {
|
|
|
} catch (IOException ex) {
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
- return "";
|
|
|
+ return filePath;
|
|
|
}
|
|
|
|
|
|
private Style createStyle(String borderColor, float borderOpacity, String fillColor, float fillOpacity) {
|