ArcGIS.Server.9.2.DotNet实现EditorTask功能扩展(自带例子 十、三)
目的:
1.arcgis server9.2 ADF实现EditorTask功能扩展。在EditorTask控件上添加地理元素框选裁剪和选中元素数量统计功能。
准备工作:
1.参考DeveloperKit\SamplesNET\Server\Web_Applications目录下的Common_CustomEditorTaskCSharp.zip。
2.本例是在ArcGIS.Server.9.2.DotNet实现在线编辑EditorTask使用(自带例子 十、二) 基础上做的。
完成后的效果图:

开始:
1.在上一篇中已经实现了EditorTask控件的使用,已经编辑属性的过滤控制等功能,本篇在上一篇的基础上实现 EditorTask功能扩展,在Editor面板上添加一个框选裁剪和选中数量统计功能两个自定义功能。
2.首先在Page_Init页面事件中添加EditorTask1的ToolsCreated事件,代码如下:
6.这里例子中还有一个自定义 TooledEditorPanel的实现了,觉得不是太有用了这里就不详细讲了贴一下代码和说明。
1.arcgis server9.2 ADF实现EditorTask功能扩展。在EditorTask控件上添加地理元素框选裁剪和选中元素数量统计功能。
准备工作:
1.参考DeveloperKit\SamplesNET\Server\Web_Applications目录下的Common_CustomEditorTaskCSharp.zip。
2.本例是在ArcGIS.Server.9.2.DotNet实现在线编辑EditorTask使用(自带例子 十、二) 基础上做的。
完成后的效果图:

开始:
1.在上一篇中已经实现了EditorTask控件的使用,已经编辑属性的过滤控制等功能,本篇在上一篇的基础上实现 EditorTask功能扩展,在Editor面板上添加一个框选裁剪和选中数量统计功能两个自定义功能。
2.首先在Page_Init页面事件中添加EditorTask1的ToolsCreated事件,代码如下:
1
protected void Page_Init(object sender, EventArgs e)
2
{
3
//ToolsCreated事件
4
EditorTask1.ToolsCreated += new ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.ToolsCreatedEventHandler(EditorTask1_ToolsCreated);
5


6
}
3.在EditorTask1_ToolsCreated方法中实现框选裁剪和数量统计2个功能按钮的添加,具体代码和说明如下:

2

3

4

5



6

1
void EditorTask1_ToolsCreated(object sender, ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.ToolsCreatedEventArgs e)
2
{
3
//编辑panel
4
if (e.Parent == EditorTask1.Editor.ExistingFeatureEditor)
5
{
6
//编辑panel包含两个toolbars: GeometryToolbar1和GeometryToolbar2
7
foreach (ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorToolbar editorToolbar in e.Toolbars)
8
{
9
string ToolbarID=editorToolbar.ID;
10
if (ToolbarID == "GeometryToolbar1")
11
{
12
//name,mapID,useSnapping,geometryType,minSelectedFeatures
13
//EditorTool的名称,ID,是否扑捉,元素类型,最小选择数
14
ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorTool clip =new ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorTool("Clip",((ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditExistingFeaturePanel)e.Parent).ParentEditor.MapID, false,ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.ToolGeometry.Line | ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.ToolGeometry.Polygon, 1);
15
//EditorTool的客户端Action,设置设置成矩形操作
16
clip.ClientAction = ESRI.ArcGIS.ADF.Web.UI.WebControls.Constants.HTML_DRAG_RECTANGLE;
17
//设置EditorTool的图片和tip
18
clip.DefaultImage = "~/images/clip.png";
19
clip.SelectedImage = "~/images/clip_ON.png";
20
clip.HoverImage = "~/images/clip_OVER.png";
21
clip.ToolTip = "Clip feature(s)";
22
23
//设置EditorTool的功能类
24
clip.ServerActionAssembly = "CustomEditorTask";
25
clip.ServerActionClass = "CustomEditorTask.ClipFeatures";
26
//把这个EditorTool添加到Toolbar上
27
editorToolbar.ToolbarItems.Add(clip);
28
//设置宽
29
editorToolbar.Width = new Unit(editorToolbar.Width.Value + 35, UnitType.Pixel);
30
}
31
}
32
33
//新建EditorToolbar
34
ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorToolbar newEditorToolbar =new ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorToolbar();
35
//只显示图标
36
newEditorToolbar.ToolbarStyle = ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolbarStyle.ImageOnly;
37
//id
38
newEditorToolbar.ID = "MyCustomToolbar";
39
//
40
newEditorToolbar.BuddyControlType = ESRI.ArcGIS.ADF.Web.UI.WebControls.BuddyControlType.Map;
41
//设置EditorToolbar的Map控件
42
newEditorToolbar.BuddyControls.Add(new ESRI.ArcGIS.ADF.Web.UI.WebControls.BuddyControl(((ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditExistingFeaturePanel)e.Parent).ParentEditor.MapID));
43
44
//新建EditorCommand
45
ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorCommand vertCount =new ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorCommand("VerticeCount", ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.ToolGeometry.All, 1);
46
//设置EditorCommand的图片和tip
47
vertCount.DefaultImage = "~/images/verticecount.png";
48
vertCount.SelectedImage = "~/images/verticecount_ON.png";
49
vertCount.HoverImage = "~/images/verticecount_OVER.png";
50
vertCount.ToolTip = "Count the number of vertices in the selected feature";
51
//设置EditorCommand的功能类
52
vertCount.ServerActionAssembly = "CustomEditorTask";
53
vertCount.ServerActionClass = "CustomEditorTask.VerticeCount";
54
55
//把新建EditorCommand添加到EditorToolbar
56
newEditorToolbar.ToolbarItems.Add(vertCount);
57
newEditorToolbar.Width = new Unit(newEditorToolbar.ToolbarItems.Count * 35, UnitType.Pixel);
58
59
//把新建的EditorToolbar添加到EditorTask1
60
e.Toolbars.Add(newEditorToolbar);
61
}
4.上面把2个功能按钮添加到Editor面板上后还需要编写实现具体功能的代码,就上面代码中clip.ServerActionClass = "CustomEditorTask.ClipFeatures";和vertCount.ServerActionClass = "CustomEditorTask.VerticeCount";的ClipFeatures类和VerticeCount类,新建CustomEditorTools.cs文件,然后添加如下代码:

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

1
namespace CustomEditorTask
2
{
3
class ClipFeatures : EditorServerToolAction
4
{
5
private List<int> features = new List<int>();
6
7
public List<int> Features
8
{
9
get { return features; }
10
}
11
12
protected override bool Init(Editor editor)
13
{
14
features.Clear();
15
return base.Init(editor);
16
}
17
18
protected override void EditorServerAction()
19
{
20
//区域
21
IEnvelope env = Geometry as IEnvelope;
22
//map描述
23
MapDescription mapDesc = Editor.MapFunctionality.MapDescription;
24
//选中的Feature数量
25
int[] fidSet = LayerDescription.SelectionFeatures;
26
if (fidSet != null && fidSet.Length > 0)
27
{
28
//geometry拓扑逻辑操作
29
ITopologicalOperator3 topo3 = null;
30
IFeature feature = null;
31
try
32
{
33
//开始编辑
34
StartEditOperation();
35
//IFeatureCursor提供枚举features集合的成员方法,游标
36
IFeatureCursor cursor = FeatureLayer.FeatureClass.GetFeatures(fidSet, false);
37
//获取下一个features
38
feature = cursor.NextFeature();
39
//进行循环
40
while (feature != null)
41
{
42
topo3 = (ITopologicalOperator3)feature.ShapeCopy;
43
topo3.Clip(env);
44
IGeometry geometry = (IGeometry)topo3;
45
if (!geometry.IsEmpty)
46
{
47
feature.Shape = geometry;
48
//存储Feature,存储row
49
feature.Store();
50
51
features.Add(feature.OID);
52
}
53
feature = cursor.NextFeature();
54
}
55
//停止编辑
56
StopEditOperation();
57
}
58
catch (Exception e)
59
{
60
//终止编辑操作
61
AbortEditOperation(e);
62
}
63
if (features.Count > 0)
64
{
65
// Refresh the Editor, Map, vertices, etc. with the new selection set
66
Refresh(features, true);
67
}
68
}
69
}
70
}
71
72
class VerticeCount : EditorServerCommandAction
73
{
74
protected override void EditorServerAction()
75
{
76
ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDesc = Editor.MapFunctionality.MapDescription;
77
int[] fidSet = LayerDescription.SelectionFeatures;
78
if (fidSet != null && fidSet.Length > 0)
79
{
80
IFeature feature = null;
81
82
int pointCount = 0;
83
//IFeatureCursor提供枚举features集合的成员方法,游标
84
IFeatureCursor cursor = FeatureLayer.FeatureClass.GetFeatures(fidSet, false);
85
feature = cursor.NextFeature();
86
while (feature != null)
87
{
88
//如果是点类型
89
if (feature.Shape is IPoint)
90
{
91
pointCount += 1;
92
}
93
else//非点类型
94
{
95
IPointCollection pointCollection = (IPointCollection)feature.Shape;
96
pointCount += pointCollection.PointCount;
97
}
98
feature = cursor.NextFeature();
99
}
100
string status = string.Format("alert( '选中数量为:{0}个');", pointCount);
101
ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult jsStatusCallbackResult =new ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult(null, null, "javascript", status);
102
this.ToolbarItemInfo.Toolbar.CallbackResults.Add(jsStatusCallbackResult);
103
}
104
}
105
}
106
107
public class CustomEditorTools
108
{
109
110
}
111
}
112
5.这样就完成了2个自定义功能的开发,测试运行。
2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

6.这里例子中还有一个自定义 TooledEditorPanel的实现了,觉得不是太有用了这里就不详细讲了贴一下代码和说明。
1
namespace CustomEditorTask
2
{
3
public class CustomCreateFeaturePanel : TooledEditorPanel
4
{
5
public CustomCreateFeaturePanel(EditorTask task): base("Custom Create Feature Panel", task, "customCreateFeaturePanel")
6
{ }
7
8
protected override void OnLoad(EventArgs e)
9
{
10
base.OnLoad(e);
11
//ParentEditor的Layer变换事件
12
this.ParentEditor.LayerChanged += new ESRI.ArcGIS.ADF.ArcGISServer.Editor.Editor.LayerChangedHandler(Editor_LayerChanged);
13
}
14
15
//当选择图层的类型变换时间显示相应的编辑工具
16
void Editor_LayerChanged(ESRI.ArcGIS.Carto.IFeatureLayer featureLayer)
17
{
18
//获取EditorToolbar
19
ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorToolbar toolbar =(ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorToolbar)this.Toolbars[0];
20
//获取EditorTool
21
ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorTool tool =(ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorTool)toolbar.ToolbarItems[0];
22
//设置FeatureTool属性
23
SetCreateFeatureToolProperties(featureLayer, ref tool);
24
//刷新EditorToolbar
25
toolbar.Refresh();
26
//进行回调登记
27
ParentEditor.CallbackResults.CopyFrom(toolbar.CallbackResults);
28
29
//设置tool的属性js
30
string jsToolbarItemEnable = "var toolbar = Toolbars['" + toolbar.ClientID + "']; var toolbaritem = toolbar.items['" + tool.Name + "'];toolbaritem.clientAction = 'Map" + tool.ClientAction + "'; toolbaritem.defaultImage = '" + tool.DefaultImage + "'; toolbaritem.hoverImage = '" + tool.HoverImage + "';toolbaritem.selectedImage = '" + tool.SelectedImage + "';toolbaritem.disabledImage = '" + tool.DisabledImage + "';EditorToolbars['" + toolbar.ClientID + "'].tools['" + tool.Name + "'].shapeType = '" + tool.GeometryType.ToString() + "';";
31
//CallbackResult就可以将信息传回客户端,执行js脚本
32
ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult setToolPropertiesCallbackResult =new ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult(null, null, "javascript", jsToolbarItemEnable);
33
ParentEditor.CallbackResults.Add(setToolPropertiesCallbackResult);
34
}
35
36
private void SetCreateFeatureToolProperties(ESRI.ArcGIS.Carto.IFeatureLayer featureLayer, ref ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorTool tool)
37
{
38
string shapeType = "";
39
if(featureLayer == null)
40
{
41
shapeType="esriGeometryPoint";
42
}
43
else
44
{
45
shapeType = featureLayer.FeatureClass.ShapeType.ToString();
46
}
47
string shapeString;
48
string clientAction;
49
switch (shapeType)
50
{
51
//线对象
52
case "esriGeometryPolyline":
53
shapeString = "line";
54
clientAction = "Polyline";
55
tool.GeometryType = ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.ToolGeometry.Line;
56
break;
57
//面、多边形
58
case "esriGeometryPolygon":
59
shapeString = "polygon";
60
clientAction = "Polygon";
61
tool.GeometryType = ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.ToolGeometry.Polygon;
62
break;
63
//点
64
case "esriGeometryPoint":
65
default:
66
tool.GeometryType = ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.ToolGeometry.Point;
67
shapeString = "point";
68
clientAction = "Point";
69
break;
70
}
71
//设置tool的显示图标
72
tool.DefaultImage = this.Page.ClientScript.GetWebResourceUrl(typeof(ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditorTask), string.Format("ESRI.ArcGIS.ADF.ArcGISServer.Editor.Resources.images.edCreate-{0}.gif", shapeString));
73
tool.DisabledImage = this.Page.ClientScript.GetWebResourceUrl(typeof(ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditorTask), string.Format("ESRI.ArcGIS.ADF.ArcGISServer.Editor.Resources.images.edCreate-{0}.gif", shapeString));
74
tool.HoverImage = this.Page.ClientScript.GetWebResourceUrl(typeof(ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditorTask), string.Format("ESRI.ArcGIS.ADF.ArcGISServer.Editor.Resources.images.edCreate-{0}-OVER.gif", shapeString));
75
tool.SelectedImage = this.Page.ClientScript.GetWebResourceUrl(typeof(ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditorTask), string.Format("ESRI.ArcGIS.ADF.ArcGISServer.Editor.Resources.images.edCreate-{0}-ON.gif", shapeString));
76
//设置tool的客户端动作
77
tool.ClientAction = clientAction;
78
}
79
80
protected override System.Collections.Generic.List<ESRI.ArcGIS.ADF.Web.UI.WebControls.Toolbar> CreateToolbars()
81
{
82
List<ESRI.ArcGIS.ADF.Web.UI.WebControls.Toolbar> toolbars =new List<ESRI.ArcGIS.ADF.Web.UI.WebControls.Toolbar>();
83
ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorToolbar editorToolbar =new ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorToolbar();
84
editorToolbar.ID = "customCreateFeatureToolbar";
85
editorToolbar.BuddyControlType = BuddyControlType.Map;
86
editorToolbar.BuddyControls.Add(new BuddyControl(this.ParentEditor.MapID));
87
editorToolbar.ToolbarStyle = ToolbarStyle.ImageOnly;
88
editorToolbar.Group = "EditorToolbarGroup";
89
90
ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorTool tool =new ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorTool();
91
tool.Name = "customCreateFeatureTool";
92
tool.MapID = this.ParentEditor.MapID;
93
tool.UseSnapping = true;
94
SetCreateFeatureToolProperties(this.ParentEditor.FeatureLayer, ref tool);
95
tool.ServerActionAssembly = "ESRI.ArcGIS.ADF.ArcGISServer.Editor";
96
tool.ServerActionClass = "ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.CreateFeature";
97
98
editorToolbar.ToolbarItems.Add(tool);
99
editorToolbar.Width = new Unit(editorToolbar.ToolbarItems.Count * 35, UnitType.Pixel);
100
101
toolbars.Add(editorToolbar);
102
103
return toolbars;
104
}
105
}
106
}
107

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107
