Browse Source

修改偏移

zhouyuexiang 1 year ago
parent
commit
c592b77202

+ 4 - 4
tile-service/src/main/java/cn/com/taiji/tile/util/ShapeUtils.java

@@ -112,10 +112,10 @@ public class ShapeUtils {
     }
     }
 
 
     public static void drawPointShape(double[] bbox, Graphics2D graphics, Geometry geometry, Map<String, Object> poi, ShapeStyle shapeStyle) {
     public static void drawPointShape(double[] bbox, Graphics2D graphics, Geometry geometry, Map<String, Object> poi, ShapeStyle shapeStyle) {
-//        int[] pxy = TileUtils.toPixelXY(geometry.getCoordinate().x, geometry.getCoordinate().y, bbox[0], bbox[1], bbox[2], bbox[3]);
-        int dx = (int) (256.0D * (geometry.getCoordinate().x - bbox[0]) / (bbox[2] - bbox[0]));
-        int dy = 256 - (int) (256.0D * (geometry.getCoordinate().y - bbox[1]) / (bbox[3] - bbox[1]));
-        int[] pxy = new int[]{dx, dy};
+        int[] pxy = TileUtils.toPixelXY(geometry.getCoordinate().x, geometry.getCoordinate().y, bbox[0], bbox[1], bbox[2], bbox[3]);
+//        int dx = (int) (256.0D * (geometry.getCoordinate().x - bbox[0]) / (bbox[2] - bbox[0]));
+//        int dy = 256 - (int) (256.0D * (geometry.getCoordinate().y - bbox[1]) / (bbox[3] - bbox[1]));
+//        int[] pxy = new int[]{dx-10, dy-10};
         //设置边框 实现轮廓
         //设置边框 实现轮廓
         graphics.setColor(shapeStyle.getColor());
         graphics.setColor(shapeStyle.getColor());
         graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
         graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

+ 19 - 3
tile-service/src/main/java/cn/com/taiji/tile/util/TileUtils.java

@@ -126,9 +126,25 @@ public class TileUtils {
 
 
 
 
     public static int[] toPixelXY(double x, double y, double minX, double minY, double maxX, double maxY) {
     public static int[] toPixelXY(double x, double y, double minX, double minY, double maxX, double maxY) {
-        int dx = (int) (256.0D * (x - minX) / (maxX - minX));
-        int dy = 256 - (int) (256.0D * (y - minY) / (maxY - minY));
-        return new int[]{dx, dy};
+//        int dx = (int) (256.0D * (x - minX) / (maxX - minX));
+//        int dy = 256 - (int) (256.0D * (y - minY) / (maxY - minY));
+//        return new int[]{dx, dy};
+        // 图片尺寸
+        int imageSize = 256;
+
+        // 计算经度和纬度的范围
+        double lonRange = maxX - minX;
+        double latRange = maxY - minY;
+
+        // 归一化经度和纬度
+        double normLon = (x - minX) / lonRange;
+        double normLat = (y - minY) / latRange;
+
+        // 转换成像素坐标(注意纬度是反向的,因为图片坐标系统中y是向下增加的)
+        int pixelX = (int)(normLon * (imageSize - 1));
+        int pixelY = (int)((1 - normLat) * (imageSize - 1));
+
+        return new int[]{pixelX-15, pixelY-30};
     }
     }