【发布时间】:2016-06-18 23:14:04
【问题描述】:
我在我的 java 项目中使用GeoTools 将不同大小、颜色和不透明度的点绘制到地图中。 由于它们有很多不同的样式,我最终在我的地图中添加了 数千层。目前每个添加的点都有自己的图层,因为我没有设法将它们添加到一个图层中。
我从我的 Entity 对象中获得分数。来自同一实体的每个点都具有相同的颜色。有更多具有相同名称/颜色的实体。
这是在地图上绘制一个实体的方式:
点的大小在下面的代码sn-p中动态计算:
public class Stackoverflow {
private final MapContent mapContent;
public Stackoverflow() {
this.mapContent = new MapContent();
}
public void addPoints(final HashMap<String, Color> colorsForEntities, final List<Entity> toDraw){
final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
// Create SimpleFeatureType for Point
final SimpleFeatureTypeBuilder pointTb = new SimpleFeatureTypeBuilder();
pointTb.setName("points");
pointTb.setCRS(DefaultGeographicCRS.WGS84);
pointTb.add("point", Point.class);
final SimpleFeatureBuilder pointFeatureBuilder = new SimpleFeatureBuilder(pointTb.buildFeatureType());
for (final Entity entity : toDraw) {
final List<Point2D> pathPoints = entity.getPoints();
Color color = colorsForEntities.get(entity.getName());
Layer layerPoints;
Style pointStyle;
final float maxOpacity = MyProperties.getFloat(Constants.POINT_STYLE_OPACITY);
final float maxSize = MyProperties.getFloat(Constants.POINT_STYLE_SIZE);
final int NumPoints = pathPoints.size();
float opacity = maxOpacity;
float size = maxSize;
final float deltaOpacity = maxOpacity / NumPoints;
final float deltaSize = maxSize / NumPoints;
for (final Point2D point2D : pathPoints) {
final Point point = geometryFactory.createPoint(new Coordinate(point2D.getX(), point2D.getY()));
pointFeatureBuilder.add(point);
final SimpleFeature feature = pointFeatureBuilder.buildFeature(null);
final DefaultFeatureCollection pointCollection = new DefaultFeatureCollection();
pointCollection.add(feature);
pointStyle = SLD.createPointStyle("Circle", color, color, opacity, size);
opacity = opacity - deltaOpacity;
size = size - deltaSize;
layerPoints = new FeatureLayer(pointCollection, pointStyle);
mapContent.addLayer(layerPoints);
}
}
}
}
是否可以将点添加到单个图层或至少获得更少的图层?
【问题讨论】:
标签: java geolocation geocoding geotools