|
@@ -35,24 +35,7 @@ public class ShapeUtils {
|
|
|
*/
|
|
|
public static byte[] getTileByte(String bboxStr, List<POI> dataList, ShapeStyle shapeStyle) {
|
|
|
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
|
|
|
-// String[] split = bboxStr.split(",");
|
|
|
-// double[] bbox = new double[split.length];
|
|
|
-// for (int i = 0; i < split.length; i++) {
|
|
|
-// bbox[i] = Double.parseDouble(split[i]);
|
|
|
-// }
|
|
|
-// Graphics2D graphics = image.createGraphics();
|
|
|
-// for (POI poi : dataList) {
|
|
|
-// Geometry shape = GeoUtils.getGeoUtils().createGeometry(poi.getShape());
|
|
|
-// //判断数据点线面
|
|
|
-// if (StringUtils.equals(shape.getGeometryType(), "Polygon")) {
|
|
|
-// drawPolygonShape(bbox, graphics, shape, poi, shapeStyle);
|
|
|
-// } else if (StringUtils.equalsAny(shape.getGeometryType(), "LinearRing", "LineString", "MultiLineString")) {
|
|
|
-// drawLineShape(bbox, graphics, shape, shapeStyle);
|
|
|
-// } else if (StringUtils.equals(shape.getGeometryType(), "Point")) {
|
|
|
-// drawPointShape(bbox, graphics, shape, poi, shapeStyle);
|
|
|
-// }
|
|
|
-// }
|
|
|
- renderAndDetectClick(image, bboxStr, dataList, shapeStyle, 0, 0, null, false);
|
|
|
+ renderAndDetectClick(image, bboxStr, dataList, shapeStyle);
|
|
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
|
|
try {
|
|
|
ImageIO.write(image, "png", buffer);
|
|
@@ -87,14 +70,14 @@ public class ShapeUtils {
|
|
|
int[] xpoint = new int[(geometry.getCoordinates()).length];
|
|
|
int[] ypoint = new int[(geometry.getCoordinates()).length];
|
|
|
convertCoordinatesToPixels(geometry.getCoordinates(), xpoint, ypoint, bbox);
|
|
|
- graphics.setColor(shapeStyle.getLineColor());
|
|
|
+ graphics.setColor(shapeStyle.getColor());
|
|
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
if (Objects.equals(shapeStyle.getLineType(), 2)) {
|
|
|
- graphics.setStroke(new BasicStroke(shapeStyle.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, shapeStyle.getLineDashPattern(), 0.0f));
|
|
|
+ graphics.setStroke(new BasicStroke(shapeStyle.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, shapeStyle.getDashPattern(), 0.0f));
|
|
|
} else if (Objects.equals(shapeStyle.getLineType(), 3)) {
|
|
|
- graphics.setStroke(new BasicStroke(shapeStyle.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, shapeStyle.getLineDashPattern(), 0.0f));
|
|
|
+ graphics.setStroke(new BasicStroke(shapeStyle.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, shapeStyle.getDashPattern(), 0.0f));
|
|
|
} else {
|
|
|
- graphics.setStroke(new BasicStroke(shapeStyle.getLineWidth()));
|
|
|
+ graphics.setStroke(new BasicStroke(shapeStyle.getWidth()));
|
|
|
}
|
|
|
//端点的样式可以是圆形 (CAP_ROUND)、平直 (CAP_BUTT) 或方形 (CAP_SQUARE)
|
|
|
// 连接样式:线段之间的连接可以设置为斜接 (JOIN_MITER)、圆角 (JOIN_ROUND) 或平直 (JOIN_BEVEL)。
|
|
@@ -105,20 +88,20 @@ public class ShapeUtils {
|
|
|
public static void drawPointShape(double[] bbox, Graphics2D graphics, Geometry geometry, POI poi, ShapeStyle shapeStyle) {
|
|
|
int[] pxy = TileUtils.toPixelXY(geometry.getCoordinate().x, geometry.getCoordinate().y, bbox[0], bbox[1], bbox[2], bbox[3]);
|
|
|
//设置边框 实现轮廓
|
|
|
- graphics.setColor(shapeStyle.getPointColor());
|
|
|
+ graphics.setColor(shapeStyle.getColor());
|
|
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
//设置字体
|
|
|
//设置字体样式
|
|
|
- if (BooleanUtil.isTrue(shapeStyle.getPointFontShow())) {
|
|
|
- Font font = new Font("Arial", Font.BOLD, shapeStyle.getPointFontSize());
|
|
|
+ if (BooleanUtil.isTrue(shapeStyle.getIsShowName())) {
|
|
|
+ Font font = new Font("Arial", Font.BOLD, shapeStyle.getFontSize());
|
|
|
String s = poi.getName();
|
|
|
- graphics.setColor(shapeStyle.getPointFontColor());
|
|
|
+ graphics.setColor(shapeStyle.getFontColor());
|
|
|
graphics.setFont(font);
|
|
|
graphics.drawString(s, pxy[0], pxy[1]);
|
|
|
}
|
|
|
BufferedImage pointMarkerImage = shapeStyle.getPointMarkerImage();
|
|
|
if (pointMarkerImage != null) {
|
|
|
- graphics.drawImage(TileUtils.scaleWidthHeight(pointMarkerImage, shapeStyle.getPointWidth(), shapeStyle.getPointHeight()), pxy[0], pxy[1], null);
|
|
|
+ graphics.drawImage(TileUtils.scaleWidthHeight(pointMarkerImage, shapeStyle.getWidth(), shapeStyle.getHeight()), pxy[0], pxy[1], null);
|
|
|
} else {
|
|
|
drawPointShape(shapeStyle, graphics, pxy);
|
|
|
}
|
|
@@ -180,7 +163,7 @@ public class ShapeUtils {
|
|
|
}
|
|
|
|
|
|
private static void setBackgroundImage(Graphics2D graphics, ShapeStyle shapeStyle) {
|
|
|
- BufferedImage backgroundImage = shapeStyle.getBackgroundImage();
|
|
|
+ BufferedImage backgroundImage = shapeStyle.getBgImage();
|
|
|
if (backgroundImage != null) {
|
|
|
TexturePaint texturePaint = new TexturePaint(backgroundImage, new Rectangle(0, 0, backgroundImage.getWidth(), backgroundImage.getHeight()));
|
|
|
graphics.setPaint(texturePaint);
|
|
@@ -220,38 +203,38 @@ public class ShapeUtils {
|
|
|
}
|
|
|
|
|
|
private static void drawPointShape(ShapeStyle shapeStyle, Graphics2D graphics, int[] pxy) {
|
|
|
- if (BooleanUtil.isTrue(shapeStyle.getPointDashed())) {
|
|
|
+ if (BooleanUtil.isTrue(shapeStyle.getIsDashed())) {
|
|
|
//如果是
|
|
|
Stroke dashed = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, shapeStyle.getPointDashPattern(), 0);
|
|
|
graphics.setStroke(dashed);
|
|
|
}
|
|
|
- if (Objects.equals(shapeStyle.getShapeType(), 1)) {
|
|
|
+ if (Objects.equals(shapeStyle.getPointType(), 1)) {
|
|
|
//正方形
|
|
|
- graphics.drawRect(pxy[0], pxy[1], shapeStyle.getPointWidth(), shapeStyle.getPointHeight());
|
|
|
- if (BooleanUtil.isTrue(shapeStyle.getPointFill())) {
|
|
|
- graphics.fillRect(pxy[0], pxy[1], shapeStyle.getPointWidth(), shapeStyle.getPointHeight());
|
|
|
+ graphics.drawRect(pxy[0], pxy[1], shapeStyle.getWidth(), shapeStyle.getHeight());
|
|
|
+ if (BooleanUtil.isTrue(shapeStyle.getIsFill())) {
|
|
|
+ graphics.fillRect(pxy[0], pxy[1], shapeStyle.getWidth(), shapeStyle.getHeight());
|
|
|
}
|
|
|
- } else if (Objects.equals(shapeStyle.getShapeType(), 2)) {
|
|
|
+ } else if (Objects.equals(shapeStyle.getPointType(), 2)) {
|
|
|
//三角形
|
|
|
- int[] xPoints = {pxy[0], pxy[0] - shapeStyle.getPointHeight(), pxy[0] + shapeStyle.getPointHeight()};
|
|
|
- int[] yPoints = {pxy[1] - shapeStyle.getPointHeight(), pxy[1] + shapeStyle.getPointHeight(), pxy[1] + shapeStyle.getPointHeight()};
|
|
|
+ int[] xPoints = {pxy[0], pxy[0] - shapeStyle.getHeight(), pxy[0] + shapeStyle.getHeight()};
|
|
|
+ int[] yPoints = {pxy[1] - shapeStyle.getHeight(), pxy[1] + shapeStyle.getHeight(), pxy[1] + shapeStyle.getHeight()};
|
|
|
int nPoints = 3; // 顶点数量
|
|
|
graphics.drawPolygon(xPoints, yPoints, nPoints);
|
|
|
- if (BooleanUtil.isTrue(shapeStyle.getPointFill())) {
|
|
|
+ if (BooleanUtil.isTrue(shapeStyle.getIsFill())) {
|
|
|
graphics.fillPolygon(xPoints, yPoints, nPoints);
|
|
|
}
|
|
|
- } else if (Objects.equals(shapeStyle.getShapeType(), 3)) {
|
|
|
+ } else if (Objects.equals(shapeStyle.getPointType(), 3)) {
|
|
|
//圆形
|
|
|
- graphics.drawOval(pxy[0], pxy[1], shapeStyle.getPointWidth(), shapeStyle.getPointHeight());
|
|
|
- if (BooleanUtil.isTrue(shapeStyle.getPointFill())) {
|
|
|
- graphics.fillOval(pxy[0], pxy[1], shapeStyle.getPointWidth(), shapeStyle.getPointHeight());
|
|
|
+ graphics.drawOval(pxy[0], pxy[1], shapeStyle.getWidth(), shapeStyle.getHeight());
|
|
|
+ if (BooleanUtil.isTrue(shapeStyle.getIsFill())) {
|
|
|
+ graphics.fillOval(pxy[0], pxy[1], shapeStyle.getWidth(), shapeStyle.getHeight());
|
|
|
}
|
|
|
} else {
|
|
|
//画一个简单的点
|
|
|
- graphics.drawArc(pxy[0], pxy[1], shapeStyle.getPointWidth(), shapeStyle.getPointHeight(), 0, 360);
|
|
|
+ graphics.drawArc(pxy[0], pxy[1], shapeStyle.getWidth(), shapeStyle.getHeight(), 0, 360);
|
|
|
//是否填充
|
|
|
- if (BooleanUtil.isTrue(shapeStyle.getPointFill())) {
|
|
|
- graphics.fillArc(pxy[0], pxy[1], shapeStyle.getPointWidth(), shapeStyle.getPointHeight(), 0, 360);
|
|
|
+ if (BooleanUtil.isTrue(shapeStyle.getIsFill())) {
|
|
|
+ graphics.fillArc(pxy[0], pxy[1], shapeStyle.getWidth(), shapeStyle.getHeight(), 0, 360);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -289,7 +272,7 @@ public class ShapeUtils {
|
|
|
return clickSelectedDataList;
|
|
|
}
|
|
|
|
|
|
- public static void renderAndDetectClick(BufferedImage image, String bboxStr, List<POI> dataList, ShapeStyle shapeStyle, int x, int y, List<POI> clickSelectedDataList, Boolean isClick) {
|
|
|
+ public static void renderAndDetectClick(BufferedImage image, String bboxStr, List<POI> dataList, ShapeStyle shapeStyle) {
|
|
|
String[] split = bboxStr.split(",");
|
|
|
double[] bbox = new double[split.length];
|
|
|
for (int i = 0; i < split.length; i++) {
|
|
@@ -306,38 +289,7 @@ public class ShapeUtils {
|
|
|
} else if (StringUtils.equals(shape.getGeometryType(), "Point")) {
|
|
|
drawPointShape(bbox, graphics, shape, poi, shapeStyle);
|
|
|
}
|
|
|
- if (BooleanUtil.isTrue(isClick)) {
|
|
|
- //如果选中
|
|
|
- int rgb = image.getRGB(x, y);
|
|
|
- System.out.println("rgb---->" + image.getRGB(x, y));
|
|
|
- int alpha = (rgb >> 24) & 0xff; // 提取alpha值
|
|
|
-// System.out.println("RGB->"+alpha);
|
|
|
- if (alpha > 0) {
|
|
|
- // 像素被填充
|
|
|
- clickSelectedDataList.add(poi);
|
|
|
- }
|
|
|
- }
|
|
|
});
|
|
|
-// for (POI poi : dataList) {
|
|
|
-// Geometry shape = GeoUtils.getGeoUtils().createGeometry(poi.getShape());
|
|
|
-// //判断数据点线面
|
|
|
-// if (StringUtils.equals(shape.getGeometryType(), "Polygon")) {
|
|
|
-// drawPolygonShape(bbox, graphics, shape, poi, shapeStyle);
|
|
|
-// } else if (StringUtils.equalsAny(shape.getGeometryType(), "LinearRing", "LineString", "MultiLineString")) {
|
|
|
-// drawLineShape(bbox, graphics, shape, shapeStyle);
|
|
|
-// } else if (StringUtils.equals(shape.getGeometryType(), "Point")) {
|
|
|
-// drawPointShape(bbox, graphics, shape, poi, shapeStyle);
|
|
|
-// }
|
|
|
-// if (BooleanUtil.isTrue(isClick)) {
|
|
|
-// //如果选中
|
|
|
-// int rgb = image.getRGB(x, y);
|
|
|
-// int alpha = (rgb >> 24) & 0xff; // 提取alpha值
|
|
|
-// if (alpha > 0) {
|
|
|
-// // 像素被填充
|
|
|
-// clickSelectedDataList.add(poi);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
}
|