|
@@ -23,6 +23,7 @@ import org.geotools.styling.Stroke;
|
|
|
import org.geotools.styling.*;
|
|
|
import org.geotools.util.factory.Hints;
|
|
|
import org.locationtech.jts.geom.Geometry;
|
|
|
+import org.locationtech.jts.geom.MultiPolygon;
|
|
|
import org.locationtech.jts.io.WKTReader;
|
|
|
import org.opengis.feature.simple.SimpleFeature;
|
|
|
import org.opengis.filter.FilterFactory2;
|
|
@@ -103,30 +104,63 @@ public class ImageServiceImpl implements IImageService {
|
|
|
|
|
|
Geometry geometry = wktReader.read(wkt);
|
|
|
|
|
|
- SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
|
|
|
- typeBuilder.setName("geometry");
|
|
|
- typeBuilder.setCRS(DefaultGeographicCRS.WGS84);
|
|
|
- typeBuilder.add("the_geom", Geometry.class);
|
|
|
- SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(typeBuilder.buildFeatureType());
|
|
|
+ if (geometry instanceof MultiPolygon) {
|
|
|
+ MultiPolygon multiPolygon = (MultiPolygon) geometry;
|
|
|
+ for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
|
|
|
+ Geometry polygon = multiPolygon.getGeometryN(i);
|
|
|
|
|
|
- featureBuilder.add(geometry);
|
|
|
- SimpleFeature feature = featureBuilder.buildFeature(null);
|
|
|
+ // 对每个单独的 Polygon 进行渲染
|
|
|
+ SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
|
|
|
+ typeBuilder.setName("geometry");
|
|
|
+ typeBuilder.setCRS(DefaultGeographicCRS.WGS84);
|
|
|
+ typeBuilder.add("the_geom", Geometry.class);
|
|
|
+ SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(typeBuilder.buildFeatureType());
|
|
|
|
|
|
- DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
|
|
|
- featureCollection.add(feature);
|
|
|
+ featureBuilder.add(polygon);
|
|
|
+ SimpleFeature feature = featureBuilder.buildFeature(null);
|
|
|
|
|
|
- Style wktStyle = createStyle(wktInfo.getBorderColor(), wktInfo.getBorderOpacity(), wktInfo.getFillColor(), wktInfo.getFillOpacity());
|
|
|
- Layer wktLayer = new FeatureLayer(featureCollection, wktStyle);
|
|
|
- // 添加图层
|
|
|
- mapContent.addLayer(wktLayer);
|
|
|
+ DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
|
|
|
+ featureCollection.add(feature);
|
|
|
|
|
|
- combinedBounds.expandToInclude(featureCollection.getBounds());
|
|
|
+ Style wktStyle = createStyle(wktInfo.getBorderColor(), wktInfo.getBorderOpacity(), wktInfo.getFillColor(), wktInfo.getFillOpacity());
|
|
|
+ Layer wktLayer = new FeatureLayer(featureCollection, wktStyle);
|
|
|
+ // 添加图层
|
|
|
+ mapContent.addLayer(wktLayer);
|
|
|
+
|
|
|
+ combinedBounds.expandToInclude(featureCollection.getBounds());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
|
|
|
+ typeBuilder.setName("geometry");
|
|
|
+ typeBuilder.setCRS(DefaultGeographicCRS.WGS84);
|
|
|
+ typeBuilder.add("the_geom", Geometry.class);
|
|
|
+ SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(typeBuilder.buildFeatureType());
|
|
|
+
|
|
|
+ featureBuilder.add(geometry);
|
|
|
+ SimpleFeature feature = featureBuilder.buildFeature(null);
|
|
|
+
|
|
|
+ DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
|
|
|
+ featureCollection.add(feature);
|
|
|
+
|
|
|
+ Style wktStyle = createStyle(wktInfo.getBorderColor(), wktInfo.getBorderOpacity(), wktInfo.getFillColor(), wktInfo.getFillOpacity());
|
|
|
+ Layer wktLayer = new FeatureLayer(featureCollection, wktStyle);
|
|
|
+ // 添加图层
|
|
|
+ mapContent.addLayer(wktLayer);
|
|
|
+
|
|
|
+ combinedBounds.expandToInclude(featureCollection.getBounds());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 增加长和宽的10%
|
|
|
- double expandWidth = combinedBounds.getWidth() * (1 + 0.01);
|
|
|
- double expandHeight = combinedBounds.getHeight() * (1 + 0.01);
|
|
|
- combinedBounds.expandBy(expandWidth, expandHeight);
|
|
|
+// double expandWidth = combinedBounds.getWidth() * (1 + 0.01);
|
|
|
+// double expandHeight = combinedBounds.getHeight() * (1 + 0.01);
|
|
|
+
|
|
|
+ double expandWidth = combinedBounds.getWidth() ;
|
|
|
+ double expandHeight = combinedBounds.getHeight();
|
|
|
+ double bian = expandWidth>expandHeight?expandWidth:expandHeight;
|
|
|
+
|
|
|
+
|
|
|
+ combinedBounds.expandBy(bian, bian);
|
|
|
|
|
|
// 将地图绘制到图片
|
|
|
File outputFile = new File(filePath);
|