|
@@ -14,6 +14,7 @@ import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
|
|
/**
|
|
|
* @author zzyx 2024/1/5
|
|
@@ -34,20 +35,24 @@ 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];
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
+// 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);
|
|
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
|
|
try {
|
|
|
ImageIO.write(image, "png", buffer);
|
|
@@ -251,5 +256,88 @@ public class ShapeUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static List<POI> detectClick(String bboxStr, List<POI> dataList, ShapeStyle shapeStyle, int x, int y) {
|
|
|
+ List<POI> clickSelectedDataList = new CopyOnWriteArrayList<>();
|
|
|
+// renderAndDetectClick(image, bboxStr, dataList, shapeStyle, x, y, clickSelectedDataList, true);
|
|
|
+ String[] split = bboxStr.split(",");
|
|
|
+ double[] bbox = new double[split.length];
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ bbox[i] = Double.parseDouble(split[i]);
|
|
|
+ }
|
|
|
+ dataList.parallelStream().forEach(poi -> {
|
|
|
+ BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
|
|
|
+ Graphics2D graphics = image.createGraphics();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ //如果选中
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return clickSelectedDataList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void renderAndDetectClick(BufferedImage image, String bboxStr, List<POI> dataList, ShapeStyle shapeStyle, int x, int y, List<POI> clickSelectedDataList, Boolean isClick) {
|
|
|
+ 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();
|
|
|
+ dataList.parallelStream().forEach(poi -> {
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ }
|
|
|
|
|
|
}
|