当我向mapcontent添加新图层时,屏幕闪烁。怎么不这样
打开shp文件并显示地图后。我向MapContent添加了新图层,如下所示:每次添加新图层时,屏幕都会闪烁一次:
public class AddLayer extends SafeAction {
private File sourceFile;
private SimpleFeatureSource featureSource;
public AddLayer(String name) {
super(name);
// TODO Auto-generated constructor stub
}
@Override
public void action(ActionEvent e) throws Throwable {
addLayer();
}
方法添加层
private void addLayer() throws IOException {
sourceFile = JFileDataStoreChooser.showOpenFile("shp", null);
if (sourceFile == null) {
return;
}
FileDataStore store = FileDataStoreFinder.getDataStore(sourceFile);
featureSource = store.getFeatureSource();
Style style = SLD.createSimpleStyle(featureSource.getSchema());
Layer layer = new FeatureLayer(featureSource, style);
layer.setTitle("Add Layer: " + MapUI.map.layers().size());
// MapUI.map is MapContent
MapUI.map.layers().add(layer);
}
即使我按如下方法在MapContent上绘制一个点,每次单击以选择屏幕绘制点时,它们也会闪烁:
public class AddClickPoint {
public void action(MapMouseEvent ev) {
addClickPoint(ev);
}
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);
创建1点
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");
MapUI.map.layers().add(layer);
}
}