-
Notifications
You must be signed in to change notification settings - Fork 2
/
SingleSymbol.cs
170 lines (156 loc) · 6.02 KB
/
SingleSymbol.cs
1
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.DisplayUI;
namespace WindowsFormsApplication1
{
public partial class SingleSymbol : Form
{
IHookHelper m_hookHelper = null;
IActiveView m_activeView = null;
IMap m_map = null;
IFeatureLayer layer2Symbolize = null;
public SingleSymbol(IHookHelper hookHelper)
{
InitializeComponent();
m_hookHelper = hookHelper;
m_activeView = m_hookHelper.ActiveView;
m_map = m_hookHelper.FocusMap;
}
private void SingleSymbol_Load(object sender, EventArgs e)
{
CbxLayersAddItems();
}
private void cbxLayers2Symbolize_SelectedIndexChanged(object sender, EventArgs e)
{
if (cbxLayers2Symbolize.SelectedItem != null)
{
string strLayer2Symbolize = cbxLayers2Symbolize.SelectedItem.ToString();
layer2Symbolize = GetFeatureLayer(strLayer2Symbolize);
}
}
private void CbxLayersAddItems()
{
if (GetLayers() == null) return;
IEnumLayer layers = GetLayers();
layers.Reset();
ILayer layer = layers.Next();
while (layer != null)
{
if (layer is IFeatureLayer)
{
cbxLayers2Symbolize.Items.Add(layer.Name);
}
layer = layers.Next();
}
}
#region "GetLayers"
private IEnumLayer GetLayers()
{
UID uid = new UIDClass();
uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";// IFeatureLayer
//uid.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; // IGeoFeatureLayer
//uid.Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}"; // IDataLayer
if (m_map.LayerCount != 0)
{
IEnumLayer layers = m_map.get_Layers(uid, true);
return layers;
}
return null;
}
#endregion
#region "GetFeatureLayer"
private IFeatureLayer GetFeatureLayer(string layerName)
{
//get the layers from the maps
if (GetLayers() == null) return null;
IEnumLayer layers = GetLayers();
layers.Reset();
ILayer layer = null;
while ((layer = layers.Next()) != null)
{
if (layer.Name == layerName)
return layer as IFeatureLayer;
}
return null;
}
#endregion
private void btnSymbolize_Click(object sender, EventArgs e)
{
if (layer2Symbolize == null) return;
ISymbol symbol = GetSymbolByControl(layer2Symbolize.FeatureClass.ShapeType);
if (symbol == null) return;
ISimpleRenderer pSimpleRenderer = new SimpleRendererClass();
pSimpleRenderer.Symbol = symbol;
pSimpleRenderer.Label = "单一符号化";
IGeoFeatureLayer pGeoFeatureL = layer2Symbolize as IGeoFeatureLayer;
pGeoFeatureL.Renderer = pSimpleRenderer as IFeatureRenderer;
m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent);
}
private ISymbol GetSymbolByControl(esriGeometryType geometryType)
{
GetSymbolByControl symbolForm = null;
ISymbol symbol = null;
switch (geometryType)
{
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
symbolForm = new GetSymbolByControl(esriSymbologyStyleClass.esriStyleClassMarkerSymbols);
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
symbolForm = new GetSymbolByControl(esriSymbologyStyleClass.esriStyleClassLineSymbols);
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
symbolForm = new GetSymbolByControl(esriSymbologyStyleClass.esriStyleClassFillSymbols);
break;
default:
break;
}
symbolForm.ShowDialog();
if (symbolForm.m_styleGalleryItem != null)
symbol = symbolForm.m_styleGalleryItem.Item as ISymbol;
symbolForm.Dispose();
return symbol;
}
private ISymbol GetSymbolBySymbolSelector(esriGeometryType geometryType)
{
ISymbolSelector pSymbolSelector = new SymbolSelectorClass();
ISymbol symbol = null;
switch (geometryType)
{
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
symbol = new SimpleMarkerSymbolClass();
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
symbol = new SimpleLineSymbolClass();
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
symbol = new SimpleFillSymbolClass();
break;
default:
break;
}
pSymbolSelector.AddSymbol(symbol);
bool response = pSymbolSelector.SelectSymbol(0);
if (response)
{
symbol = pSymbolSelector.GetSymbolAt(0);
return symbol;
}
return null;
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}