- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我向 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) 以向 map 添加内容的内容。
我可以保留对 ListFeatureCollection 的引用并使用它来添加新功能,但我更愿意仅使用 mapConent.layers.get(layerNumber) 方法,然后使用图层添加内容。
到目前为止,我看到的所有示例都只是添加了具有新功能的另一层。我不想添加另一层,而只是向现有层添加一些内容,其内容位于内存中。我在这里错过了什么吗?有没有我不知道的 GeoTools 类?
最佳答案
看看http://osgeo-org.1560.x6.nabble.com/Adding-geometry-to-layer-td4324729.html .这听起来与您的问题非常相似,不久前在 GeoTools 邮件列表中被问到。
基本思路,以防上面链接的邮件列表存档在某个时间点变得不可用:
根据邮件列表上的声明:“当您将要素添加到集合中时, map Pane 应该自动重新绘制(从要素集合到 map 图层到图层列表再到 map Pane 有一系列事件发送)”
关于java - 将要素添加到 Geotools 中的现有图层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26882297/
我从 mapbox 中获取了这个演示: https://docs.mapbox.com/mapbox-gl-js/example/hover-styles/ 我用自己的 GeoJson 文件替换了演示
链接:http://www1.qhoach.com/ 当您拖动时,这张 map 会被平移...但是如果您拖动 KML 要素(带圆圈的图标),则什么也不会发生 最佳答案 首先,在您的应用程序中有四个级别
我是一名优秀的程序员,十分优秀!