gushoubang 1 год назад
Родитель
Сommit
93c99026b3

+ 3 - 12
onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/service/impl/ImageServiceImpl.java

@@ -130,8 +130,10 @@ public class ImageServiceImpl implements IImageService {
         org.geotools.map.FeatureLayer layer = new org.geotools.map.FeatureLayer(featureCollection, style);
         map.addLayer(layer);
 
-        // 计算几何图形的包络
+        // 计算几何图形的包络并添加填充
         Envelope envelope = geometry.getEnvelopeInternal();
+        double padding = envelope.getWidth() * 0.1; // 添加10%的填充
+        envelope.expandBy(padding);
 
         // 设置 MapViewport
         MapViewport viewport = new MapViewport();
@@ -153,17 +155,6 @@ public class ImageServiceImpl implements IImageService {
 
         System.out.println("Image saved to " + file.getAbsolutePath());
     }
-
-    private static String convertToGeoJson(DefaultFeatureCollection featureCollection) {
-        StringWriter writer = new StringWriter();
-        FeatureJSON fjson = new FeatureJSON();
-        try {
-            fjson.writeFeatureCollection(featureCollection, writer);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        return writer.toString();
-    }
 }
 
 

+ 26 - 0
onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/util/GeojsonUtil.java

@@ -0,0 +1,26 @@
+package com.onemap.spatial.util;
+
+import org.geotools.feature.DefaultFeatureCollection;
+import org.geotools.geojson.feature.FeatureJSON;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+public class GeojsonUtil {
+    /**
+     * 默认FeatureCollection转GeoJson
+     *
+     * @param featureCollection
+     * @return
+     */
+    private static String collectionToGeoJson(DefaultFeatureCollection featureCollection) {
+        StringWriter writer = new StringWriter();
+        FeatureJSON fjson = new FeatureJSON();
+        try {
+            fjson.writeFeatureCollection(featureCollection, writer);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return writer.toString();
+    }
+}