【发布时间】:2015-01-09 00:42:03
【问题描述】:
我在 Geotools MapPane 中添加了一个图层,其中包含各种 WKT 字符串功能。图层显示正确。现在,单击 UI 上的按钮,我想向该层添加另一个功能。
最初,我创建图层并使用以下内容显示它:
List<SimpleFeature> list = featuresFromWkt(wktString, name); //method name explains what it does..
ListFeatureCollection col = new ListFeatureCollection(getFeatureType(), list);
Color color = Color.BLUE;
Style style = SLD.createPolygonStyle(color, color.brighter(), 0.5f);
FeatureLayer layer = new FeatureLayer(col, style);
layer.setVisible(true);
layer.setTitle(name);
mapContent.layers().add(layer)
现在,要向图层添加一些内容,我从内容中获取图层,使用:
FeatureLayer layer = (FeatureLayer) mapContent.layers().get(0);
我现在可以使用 layer.getSimpleFeatureSource() 来检索源,但似乎没有办法将此源转换回我可以调用 .addFeature(someNewFeature) 以向地图添加内容的东西。
我可以保留对 ListFeatureCollection 的引用并使用它来添加新功能,但我更愿意只使用 mapConent.layers.get(layerNumber) 方法,然后使用图层添加内容。
到目前为止,我看到的所有示例都只是添加了具有新功能的另一层。我不想添加另一层,而只是向现有层添加一些内容,其内容位于内存中。我在这里错过了什么吗?是否有我不知道的 GeoTools 类?
【问题讨论】: