我是新手使用gwt-openlayers。我尝试修改PostGIS DB中的几何体。我可以在UI中修改它,但我无法保存修改后的几何体。 这是我编辑和保存的代码:
private void saveFeature(WFSProtocol wfsProtocol, Vector wfsLayer, SaveStrategy saveStrategy) {
Callback callbackSave = new Callback()
{
public void computeResponse(Response response)
{
System.out.println("Saved: " + response.getRequestType());
}
};
saveStrategy.save();
WFSProtocolCRUDOptions saveOptions = new WFSProtocolCRUDOptions(callbackSave);
wfsProtocol.commit(wfsLayer.getFeatures(), saveOptions);
}
private void editableLayer(Vector wfsLayer, Map map, VectorOptions vectorOptions, SaveStrategy saveStrategy) {
//Create some styles for the wfs
final Style normalStyle = new Style(); //the normal style
normalStyle.setStrokeWidth(3);
normalStyle.setStrokeColor("#FF0000");
normalStyle.setFillColor("#FFFF00");
normalStyle.setFillOpacity(0.8);
normalStyle.setStrokeOpacity(0.8);
final Style selectedStyle = new Style(); //the style when a feature is selected, or temporaly selected
selectedStyle.setStrokeWidth(3);
selectedStyle.setStrokeColor("#FFFF00");
selectedStyle.setFillColor("#FF0000");
selectedStyle.setFillOpacity(0.8);
selectedStyle.setStrokeOpacity(0.8);
final StyleMap styleMap = new StyleMap(normalStyle, selectedStyle,
selectedStyle);
wfsLayer.setStyleMap(styleMap);
//Create a ModifyFeature control that enables WFS modification
final ModifyFeatureOptions modifyFeatureControlOptions = new ModifyFeatureOptions();
modifyFeatureControlOptions.setMode(ModifyFeature.RESHAPE); //options are RESHAPE, RESIZE, ROTATE and DRAG
final ModifyFeature modifyFeatureControl = new ModifyFeature(wfsLayer,
modifyFeatureControlOptions);
map.addControl(modifyFeatureControl);
modifyFeatureControl.activate();
saveStrategy.activate();
}
答案 0 :(得分:0)
解决!问题是连接到几何名称。在postgis中,默认名称是“the-geom”,在我的例子中,名称是“geom”。我忘了在WfsProtocolOptions中指定它: wfsProtocolOptions.setGeometryName( “的geom”);
现在一切正常!