我通过在图层上添加一个点,然后在地图上添加一个图层,来向地图添加1点。我这样做了,添加屏幕图层的时间闪烁了,要求所有人避免闪烁
我使用Java 8 + Geotools
private void addClickPoint(MapMouseEvent ev){
DirectPosition2D pos = ev.getMapPosition();
double x = pos.x;
double y = pos.y;
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName("MyFeatureType");
builder.setCRS(DefaultGeographicCRS.WGS84); // set crs
builder.add("location", MultiPoint.class); // add geometry
// build the type
SimpleFeatureType TYPE = builder.buildFeatureType();
// create features using the type defined
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
// ===> Tạo ra 1 point khi click
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
Coordinate coord = new Coordinate(x, y);
Point point = geometryFactory.createPoint(coord);
DefaultFeatureCollection featureCollection = new
DefaultFeatureCollection();
featureBuilder.add(point);
SimpleFeature feature = featureBuilder.buildFeature("FeaturePoint");
featureCollection.add(feature); // Add feature 1, 2, 3, etc
Style style = SLD.createPointStyle("circle", Color.BLUE, Color.BLUE, 0.3f, 15);
Layer layer = new FeatureLayer(featureCollection, style);
layer.setTitle("Click Point");
map.layers().add(layer);
}
我希望屏幕不闪烁