添加图层

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
//判断地图视图中是否有处于显示状态中的地图
if (this.mapCtrl.ActiveMap == null)
{
MessageBox.Show("请先在地图视图中显示一幅地图!!!");
return;
}

//选择待添加的图层
GDBOpenFileDialog ofDlg = new GDBOpenFileDialog();
ofDlg.Filter = "简单要素类、注记类|sfcls;acls";
if (ofDlg.ShowDialog() != DialogResult.OK)
return;
string fileName = ofDlg.FileName;

SFeatureCls sfcls = new SFeatureCls();
sfcls.Open(fileName);

this._Tree.WorkSpace.BeginUpdateTree();

//附加矢量图层
VectorLayer vecLayer = new VectorLayer(VectorLayerType.SFclsLayer);
vecLayer.AttachData(sfcls);
//将图层添加到地图中
vecLayer.Name = sfcls.ClsName;
//获取激活地图
Map activeMap = this.mapCtrl.ActiveMap;
activeMap.Append(vecLayer);
//复位
this.mapCtrl.ActiveMap = activeMap;
this.mapCtrl.Restore();

this._Tree.WorkSpace.EndUpdateTree();

return;

获取OID

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//打开简单要素类
SFeatureCls sfcls2 = new SFeatureCls();
bool rnt2 = sfcls2.Open(URL);
//queryDef = new QueryDef();
//Rect rect = new Rect();
//mapControl.Transformation.WpToLp(e.X, e.Y, ref x, ref y);
//rect.XMax = x;
//rect.XMin = x;
//rect.YMax = y;
//rect.YMin = y;
//queryDef.SetRect(rect, SpaQueryMode.Intersect);
//recordSet = sFeatureCls.Select(queryDef);
_RecordSet = sfcls2.Select(null);
List<long> strList = new List<long>();
bool rnt = _RecordSet.MoveFirst();//移到第一个位置
while (!_RecordSet.IsEOF)
{
long OID = _RecordSet.CurrentID;
strList.Add(OID);
rnt = _RecordSet.MoveNext();
}
string str = string.Join(" ", strList.ToArray());//用空格串联字符串
MessageBox.Show(str);

获取图层列表

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
public Dictionary<string, string> LayerList = new Dictionary<string, string>();
/// <summary>
/// 获取左侧目录树图层列表
/// </summary>
/// <returns></returns>
public Dictionary<string, string> GetLayerList()
{
LayerList.Clear();
try
{
Map map = WorkSpacePanel.Tree.Document.GetMaps().GetMap(0);
for (int i = 0; i < map.LayerCount; i++)
{
if (map.get_Layer(i) is MapLayer)
{
string layerName = map.get_Layer(i).Name;
string layerURL = map.get_Layer(i).URL;
string TargetName = GetTargetName(layerName);
if (TargetName != null)
{
LayerList.Add(TargetName, layerURL);
}
}
}
return LayerList;
}
catch {
return LayerList;
}

}

高亮显示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
try
{
this.mapCtr.EndFlash();
Map map = WorkSpacePanel.Tree.Document.GetMaps().GetMap(0);
for (int i = 0; i < map.LayerCount; i++)
{
if (map.get_Layer(i) is MapLayer)
{
string layerURL = map.get_Layer(i).URL;
this.mapCtr.PushFocusData(map.get_Layer(i), theItem.Value);
}
}
this.mapCtr.StartFlash();
}
catch
{
return false;
}

Scene(场景)添加Map(地图)

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
if (this.app.Document.GetMaps().GetMap(0).LayerCount == 0)
{
MessageBox.Show("请先打开文档");
return;
}
Document doc = this.app.Document;

this.app.WorkSpaceEngine.BeginUpdateTree();

Scene scene = new Scene();
scene.Name = "New Scene";
scene.Mode = SceneMode.GLOBE;
TerrainLayer terrainLayer = new TerrainLayer();
terrainLayer.Name = "DEM";
terrainLayer.URL = "gdbp://MapGISLocalPlus/sample/ras/n08e116";
terrainLayer.ConnectData();
scene.Append(terrainLayer);

doc.GetScenes().Append(scene1);

MapRefLayer relayer = new MapRefLayer();
Map map = doc.GetMaps().GetMap(0);
//关联图层
relayer.URL = terrainLayer.URL;
relayer.ConnectData();
//关联地图文档
relayer.SetProperty("新地图", map);
terrainLayer.Append(relayer);

this.app.WorkSpaceEngine.EndUpdateTree();

PreviewScene scene1View = new PreviewScene();
scene1View.OnCreate(this.app.WorkSpaceEngine);
scene1View.OnClick(scene);