针对ArcEngine项目需要,开始由JAVA转向C#开发,最近狂乱的google加baidu,再加上esrichina做升级,搜索出来的内容全部无法进入他的论坛查看,还好有baidu快照,帮了我很大的忙,再说esrichina论坛,提问比回答的人多。就一个二三维联动,不知道有多少贴子,VB的,C++的,C#的很少。没有一个好的贴子能直接解决我的问题,郁闷之极,最主要是那个论坛分权限,刚注册的用户想看牛人的博客还进不去,我是ArcEngine+C#的新手,我的项目很急,但是面对这样的论坛我很悲剧。决定将我花按天去google和baidu所找出的
答案
八年级地理上册填图题岩土工程勘察试题省略号的作用及举例应急救援安全知识车间5s试题及答案
在这里记下来,同时也供和我一样的新手学习学习。
多的话说了没用,看代码如下:
1.导入shp文件到MapControl,按个button 同步到SceneControl中
C#代码
1. //加载shp文件到MapControl中
2. private void btnItem9_1_SHP_Click(object sender, EventArgs e)
3. {
4. OpenFileDialog openFileDialog1 = new OpenFileDialog();
5. openFileDialog1.CheckFileExists = true;
6. openFileDialog1.CheckFileExists = true;
7. openFileDialog1.Multiselect = true;
8. openFileDialog1.Filter = "shape files(*.shp)|*.shp";
9. openFileDialog1.Title = "请选择shp格式文件";
10.
11. if (openFileDialog1.ShowDialog() == DialogResult.OK)
12. {
13. foreach (string fname in openFileDialog1.FileNames)
14. {
15. if (fname != null)
16. {
17. string pathToWorkspace = System.IO.Path.GetDirectoryName(fname);
18. string shapefileName = System.IO.Path.GetFileNameWithoutExtension(fname);
19.
20. axMapControl1.AddShapeFile(pathToWorkspace, shapefileName);
21. }
22. }
23. }
24.
25. IActiveView pActiveView = (IActiveView)axMapControl1.Map;
26. pActiveView.Refresh();
27. }
OK,接下来是同步的方法:
C#代码
1. //重新同步MapControl中的所有图层到SceneControl
2. private void synLayersToSceneControl()
3. {
4. if (axMapControl1.ActiveView != null)
5. {
6. if (axMapControl1.Map.LayerCount > 0)
7. {
8. axSceneControl1.Scene.ClearLayers();
9. UID uid = new UIDClass();
10. uid.Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}"; //所有图层
11. axSceneControl1.Scene.AddLayers(axMapControl1.Map.get_Layers(uid, true), true);
12. }
13. }
14. axSceneControl1.SceneGraph.RefreshViewers();
15.
16. }
2.点击一个button,让二维和三维一起放大,即同步放大
C#代码
1. //同步放大
2. private void btnItem9_5_ZoomInFixed_Click(object sender, EventArgs e)
3. {
4. //得到接口
5. IActiveView pActiveView = this.axMapControl1.Map as IActiveView;
6.
7. //获得显示范围
8. IEnvelope pEnvelope = (IEnvelope)pActiveView.Extent;
9.
10. //刷新
11. pEnvelope.Expand(0.9, 0.9, true);
12. pActiveView.Extent = pEnvelope;
13. pActiveView.Refresh();
14.
15. //三维
16. //获得现场的相机
17. ICamera pCamera = this.axSceneControl1.Camera as ICamera;
18.
19. //拓宽视野
20. double dAngle;
21. dAngle = pCamera.ViewFieldAngle;
22. pCamera.ViewFieldAngle = dAngle * 0.9;
23.
24. //重绘现场
25. ISceneViewer pSceneViewer = this.axSceneControl1.SceneGraph.ActiveViewer as ISceneViewer;
26. pSceneViewer.Redraw(false);
27. }