参考论坛一些朋友的帖子,实现点的在线添加。但是也存在问题,问题是新加入的点在WebContent进行刷新后,不能马上显示出来,需要重新打开一个浏览器窗口浏览才能看到刚加入的点。希望大家给予指导谢谢。
public void addPoint(MapEvent event){
AGSLocalMapResource res = (AGSLocalMapResource)this.webContext.getResources().get("ags0");
try{
// 建立一个工作空间工厂对象,并设置它的参数信息。
SdeWorkspaceFactory sdewf = (SdeWorkspaceFactory)res.getServerContext().createObject(SdeWorkspaceFactory.getClsid());
PropertySet pset = (PropertySet)res.getServerContext().createObject(PropertySet.getClsid());
pset.setProperty("SERVER", "gxk");// 服务器名称
pset.setProperty("INSTANCE", "5151");// 实例名
pset.setProperty("USER", "sa"); // SDE数据表空间的用户名
pset.setProperty("PASSWORD", "sa");// 密码
pset.setProperty("VERSION", "DBO.gxk");// SDE数据的版本
Workspace iws =(Workspace) sdewf.open(pset, 0);
WebPoint screenPoint = (WebPoint)event.getWebGeometry();
WebMap mapctrl = event.getWebContext().getWebMap();
WebPoint mappnt =WebPoint.toMapPoint(screenPoint, mapctrl.getCurrentExtent(), (int)mapctrl.getWidth(), (int)mapctrl.getHeight());
Geometry soapgeo=AGSUtil.toAGSGeometry(mappnt);
String soapString = com.esri.adf.web.ags.util.AGSUtil.serializeStub(soapgeo);
soapString = soapString.replaceAll("xsi:type=\"soapenc:Array\"", "");
IPoint mypoint = (IPoint)AGSUtil.deserializeArcObject(soapString, res.getServerContext());
IWorkspaceEdit wse = (IWorkspaceEdit)iws;
wse.startEditing(false);
wse.startEditOperation();
IFeatureClass featureclass = iws.openFeatureClass("sde.DBO.Respt");
IFeature feature = featureclass.createFeature();
feature.setShapeByRef((IGeometry)mypoint);
feature.setValue(feature.getFields().findField("NAME"), "kkk");
feature.store();
wse.stopEditOperation();
wse.stopEditing(true);
this.webContext.refresh();
}catch(Exception e){
e.printStackTrace();
}
}
刷新地图后不能显示新加入的数据的原因是:由于在开始编辑时新打开了一个工作空间,该工作空间并不是浏览器中看到地图所在的工作空间。