|
@@ -160,7 +160,7 @@ public class ImageServiceImpl implements IImageService {
|
|
|
g2d.dispose();
|
|
|
mapContent.dispose();
|
|
|
//添加图例
|
|
|
- addLegend(filePath, wktsVo);
|
|
|
+ filePath = addLegend(filePath, wktsVo);
|
|
|
} catch (IOException ex) {
|
|
|
System.out.println("create image fail");
|
|
|
System.out.println(ex);
|
|
@@ -172,7 +172,15 @@ public class ImageServiceImpl implements IImageService {
|
|
|
return filePath;
|
|
|
}
|
|
|
|
|
|
- private void addLegend(String filePath, WktsVo wktsVo) throws IOException {
|
|
|
+ private String addLegend(String filePath, WktsVo wktsVo) throws IOException {
|
|
|
+ // 图片保存路径
|
|
|
+ String fileDir = rootPath + "/images/" + StringUtils.getUUID() + "/";
|
|
|
+ File dir = new File(fileDir);
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ String filePathNow = fileDir + System.currentTimeMillis() + ".png";
|
|
|
+
|
|
|
//添加图例
|
|
|
File file_legend = new File(filePath);
|
|
|
if (file_legend.exists()) {
|
|
@@ -191,12 +199,25 @@ public class ImageServiceImpl implements IImageService {
|
|
|
Graphics2D g2d = (Graphics2D) originalImage.getGraphics();
|
|
|
int legend_i = 0;
|
|
|
for (WktsVo.WktInfo wktInfo : wktsVo.getWktInfos()) {
|
|
|
- if (wktInfo.getBorderLegendDisplay()) {
|
|
|
- Color colorBorder = Color.decode(wktInfo.getBorderColor());
|
|
|
- g2d.setBackground(colorBorder);
|
|
|
+ if (wktInfo.getLegendDisplay()) {
|
|
|
+ String legendColor = wktInfo.getLegendColor();
|
|
|
+ if (StringUtils.isEmpty(legendColor)) {
|
|
|
+ legendColor = wktInfo.getFillColor();
|
|
|
+ }
|
|
|
+ Float legendColorOpacity = wktInfo.getLegendColorOpacity();
|
|
|
+ if (legendColorOpacity == null) {
|
|
|
+ legendColorOpacity = wktInfo.getFillOpacity();
|
|
|
+ }
|
|
|
+ legendColorOpacity = legendColorOpacity * 255;
|
|
|
+ Color color = Color.decode(legendColor);
|
|
|
+ int red = color.getRed();
|
|
|
+ int green = color.getGreen();
|
|
|
+ int blue = color.getBlue();
|
|
|
+ Color colorFill = new Color(red, green, blue, legendColorOpacity.intValue());
|
|
|
+ g2d.setBackground(colorFill);
|
|
|
g2d.clearRect(width_1, height_1 + height_2 * legend_i, legend_width, legend_height); // 清除原有
|
|
|
|
|
|
- g2d.setColor(colorBorder);
|
|
|
+ g2d.setColor(colorFill);
|
|
|
// 设置画笔字体样式为微软雅黑,斜体,文字大小为20px
|
|
|
if (height_2 > 20) {
|
|
|
g2d.setFont(new Font("微软雅黑", Font.ITALIC, 20));
|
|
@@ -204,15 +225,18 @@ public class ImageServiceImpl implements IImageService {
|
|
|
g2d.setFont(new Font("微软雅黑", Font.ITALIC, height_2));
|
|
|
}
|
|
|
// 写上水印文字和坐标
|
|
|
- g2d.drawString(wktInfo.getBorderLegendText(), width_1 - legend_height, height_1 + height_2 * (legend_i) + height_2 / 2);
|
|
|
+ g2d.drawString(wktInfo.getLegendText(), width_1 - legend_height, height_1 + height_2 * (legend_i) + height_2 / 2);
|
|
|
}
|
|
|
legend_i++;
|
|
|
}
|
|
|
|
|
|
// 保存新图片
|
|
|
- ImageIO.write(originalImage, "png", new File("D:\\onemapfile\\analyse\\images\\ce2dc2baae4449e3957eb0a4beb66f69\\" + System.currentTimeMillis() + ".png"));
|
|
|
+ ImageIO.write(originalImage, "png", new File(filePathNow));
|
|
|
// 释放资源
|
|
|
g2d.dispose();
|
|
|
+ return filePathNow;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|