我们都知道ArcGIS Server中的服务分为池化和非池化两种类型,对于编辑功能而言,池化和非池化类型服务都是可以进行编辑,区别在于:
如果是非池化的服务,服务中的数据可以是注册了版本或者没有注册版本的,如果是注册了版本的数据,所有的编辑操作是可以进行redo,undo操作,并且有冲突解决的方案。如果是没有注册版本的数据,就不可以进行redo,undo的操作,但是可以对编辑内容选择一次的保存和不保存。
如果是池化的服务,那么服务中的数据就只能是非版本的。这种情况下的编辑功能是最简单的,编辑的内容一旦完成就进行了保存,没有办法Redo,Undo。比如对一个多边形进行了节点移动的操作,一旦操作完成就不可以进行恢复。
但是无论哪种类型,shapefile和personal gdb中的数据都是不能被编辑任务编辑的,但是这两种数据可以进行作为捕捉的数据来源.
1 编辑功能的使用
ArcGIS Server 的编辑功能是现成提供的,主要提供了空间和属性数据的编辑。编辑过程中可以对编辑的图层和版本进行设定,并且在编辑过程中有捕捉的功能。
除了新创建要素之外,对现有要素的编辑功能分别是:
点的编辑功能:移动,拷贝,删除
线的编辑功能:移动,拷贝,切割,合并,删除,添加节点,移动节点,删除节点
面的编辑功能:移动,拷贝,切割,合并,删除,添加节点,移动节点,删除节点
编辑的操作可以进行回退,重做的操作。
见附图编辑任务对话框.
2 编辑功能的定制
编辑功能定制要使用到的命名空间是ESRI.ArcGIS.ADF.ArcGISServer.Editor
ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools
这两个命名空间中提供了组成编辑任务的各个组成控件以及类。这些控件和类是我们实现编辑功能定制的前提。
1)添加自己的工具到编辑任务中
2)添加自己的工具条到编辑任务中
见编辑任务对话框的定制附图,
编辑任务对话框的定制附图的代码如下,在EditorTask的ToolsCreated的事件中添加进自己的命令,工具和工具条。
protected void EditorTask1_ToolsCreated(object sender, ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.ToolsCreatedEventArgs e)
{
//在主工具条中添加工具
if (e.Parent == EditorTask1.Editor)
{
Toolbar toolbar = e.Toolbars[0];
// 创建工具
EditorTool tool = new EditorTool("MyTool2", Map1.ClientID, true, ToolGeometry.All, 1);
tool.ClientAction = "Point";
tool.DefaultImage = "~/images/identify_ON.gif";
tool.HoverImage = "~/images/identify_HOVER.gif";
tool.SelectedImage = "~/images/identify_OFF.gif";
tool.ServerActionAssembly = "App_Code";
tool.ServerActionClass = "CustomToolLibrary.IdentifyAllTool";
tool.ToolTip = "IdentifyAllTool";
//添加工具
toolbar.ToolbarItems.Add(tool);
toolbar.Width = new Unit(toolbar.Width.Value + 35, UnitType.Pixel);
}
//在编辑要素panel中添加工具条
else if (e.Parent == EditorTask1.Editor.ExistingFeatureEditor)
{
//创建工具,并把这个工具添加到编辑要素panel中的一个工具条中
EditorTool clip = new EditorTool("Clip", Map1.ClientID, false, ToolGeometry.All , 1);
clip.ClientAction = "Point";
clip.DefaultImage = "~/images/zoom-in_ON.gif";
clip.SelectedImage = "~/images/zoom-in_OFF.gif";
clip.HoverImage = "~/images/zoom-in_HOVER.gif";
clip.ToolTip = "AddVertex";
clip.ServerActionAssembly = "ESRI.ArcGIS.ADF.ArcGISServer.Editor";
clip.ServerActionClass = "ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.AddVertex";
e.Toolbars[0].ToolbarItems.Add(clip);
double oldWidth = e.Toolbars[0].Width.Value;
e.Toolbars[0].Width = new Unit(oldWidth + 35, UnitType.Pixel);
//创建工具条
EditorToolbar toolbar = new EditorToolbar();
toolbar.ID = "MyToolbar";
toolbar.BuddyControlType = BuddyControlType.Map;
toolbar.BuddyControls.Add(new BuddyControl("Map1"));
toolbar.ToolbarStyle = ToolbarStyle.ImageOnly;
//创建工具
EditorTool tool = new EditorTool("MyTool2", Map1.ClientID, true, ToolGeometry.All , 1);
tool.ClientAction = "Point";
tool.DefaultImage = "~/images/identify_ON.gif";
tool.HoverImage = "~/images/identify_HOVER.gif";
tool.SelectedImage = "~/images/identify_OFF.gif";
tool.ServerActionAssembly = "App_Code";
tool.ServerActionClass = "CustomToolLibrary.IdentifyAllTool";
tool.ToolTip = "IdentifyAllTool";
toolbar.ToolbarItems.Add(tool);
//创建命令
EditorCommand command = new EditorCommand("MyCommand", ToolGeometry.All, 0);
command.DefaultImage = "~/images/fixedzoomin.gif";
command.HoverImage = "~/images/fixedzoomin.gif";
command.SelectedImage = "~/images/fixedzoomin.gif";
command.ServerActionAssembly = "App_Code";
command.ServerActionClass = "CustomToolLibrary.ExtentCommand";
command.ToolTip = "ExtentCommand";
toolbar.ToolbarItems.Add(command);
// 添加工具条
toolbar.Width = new Unit(toolbar.ToolbarItems.Count * 35, UnitType.Pixel);
e.Toolbars.Add(toolbar);
}
3)添加自己的panel到编辑任务中,除了editortask本身提供的panel之外,还可以添加自己的panel.
见编辑任务对话框的定制2附图.
通过这三种方式,你就可以按照自己的需求来对编辑任务进行定制。
2 编辑功能的扩展
添加到编辑任务对话框中的工具和命令的实现是非常灵活和方便的,我们只要去实现ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorServerToolAction就可以了。下面是一个clip工具的例子代码。
public class ClipFeatures : ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorServerToolAction
{
List<int> features = new List<int>();
public List<int> Features
{
get { return features; }
}
protected override bool Init(Editor editor)
{
features.Clear();
return base.Init(editor);
}
//clip的功能就在editoserveraction中实现。
protected override void EditorServerAction()
{
IEnvelope env = Geometry as IEnvelope;
ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDesc = Editor.MapFunctionality.MapDescription;
int[] fidSet = LayerDescription.SelectionFeatures;
if (fidSet != null && fidSet.Length > 0)
{
ITopologicalOperator3 topo3 = null;
IFeature feature = null;
try
{
StartEditOperation();
IFeatureCursor cursor = FeatureLayer.FeatureClass.GetFeatures(fidSet, false);
feature = cursor.NextFeature();
while (feature != null)
{
topo3 = (ITopologicalOperator3)feature.ShapeCopy;
topo3.Clip(env);
IGeometry geometry = (IGeometry)topo3;
if (!geometry.IsEmpty)
{
feature.Shape = geometry;
feature.Store();
features.Add(feature.OID);
}
feature = cursor.NextFeature();
}
StopEditOperation();
}
catch (Exception e)
{
AbortEditOperation(e);
}
if (features.Count > 0)
{
// 刷新
Refresh(features, true);
}
}
}


