Arcengine 加载mxd模板

   ***由于在视图布局上加载.mxd文件会直接会覆盖原数据,所以需要进行一定的处理,一下有两种方式:
   方法一、使用FeatureLayer的render方法对每个图层分布进行渲染:***
                         //获取图层
                        List<ILayer> layerlist = new List<ILayer>();
                        for (int i = 0; i < _pageLayoutControl.ActiveView.FocusMap.LayerCount; i++)
                        {
                            layerlist.Add(_pageLayoutControl.ActiveView.FocusMap.get_Layer(i));
                        }
                      
                        _pageLayoutControl.LoadMxFile(filePath);
                        IMapDocument mapDocument = new MapDocument();
                        mapDocument.Open(filePath, "");
                        //对插入控件进行引用,但是这里没有对控件的样式进行处理
                        IGraphicsContainer graphicsContainer = mapDocument.PageLayout as IGraphicsContainer;
                        graphicsContainer.Reset();
                        IElement pElement = graphicsContainer.Next();
                        _pageLayoutControl.GraphicsContainer.DeleteAllElements();
                        while (pElement != null)//循环遍历
                        {
                            if (pElement is IMapSurroundFrame)//地图整饰要素
                            {
                                IMapSurroundFrame pMapSurroundFrame = pElement as IMapSurroundFrame;
                                IMapSurround pMapSurround = pMapSurroundFrame.MapSurround;

                                IEnvelope enlp = mapDocument.PageLayout.Page.PrintableBounds;
                                pElement.Geometry = enlp as IGeometry;
                                _pageLayoutControl.GraphicsContainer.AddElement(pElement, 0);
                            }
                            pElement = graphicsContainer.Next();
                        }

//遍历图层进行渲染
                        for (int i = 0; i < mapDocument.ActiveView.FocusMap.LayerCount; i++)
                        {
                            IGeoFeatureLayer featureLayer = mapDocument.ActiveView.FocusMap.get_Layer(i) as IGeoFeatureLayer;
                            IGeoFeatureLayer featureLayer1 = layerlist.Find(c => c.Name ==  featureLayer.Name) as IGeoFeatureLayer;
                            if (featureLayer != null)
                            {
                                featureLayer1.Renderer = featureLayer.Renderer;
                            }
                        }
_pageLayoutControl.Refresh();

方法二、先加载整个的.mxd模板,在对模板进行遍历,对每个图层的FeatureClass重新赋值:

  //获取图层
                        List<ILayer> layerlist = new List<ILayer>();
                        for (int i = 0; i < _pageLayoutControl.ActiveView.FocusMap.LayerCount; i++)
                        {
                            layerlist.Add(_pageLayoutControl.ActiveView.FocusMap.get_Layer(i));
                        }
                        _pageLayoutControl.ActiveView.FocusMap.ClearLayers();
                        _pageLayoutControl.LoadMxFile(filePath);
                            for (int i = 0; i < _pageLayoutControl.ActiveView.FocusMap.LayerCount; i++)
                        {
                            IFeatureLayer featureLayer = _pageLayoutControl.ActiveView.FocusMap.get_Layer(i) as IFeatureLayer;
                            IFeatureLayer featureLayer1 = layerlist.Find(c => c.Name == Global.TableRegInfo.Instance.LayerCollection.Find(b => b.TableName == featureLayer.Name)?.LayerName) as IFeatureLayer;
                            if (featureLayer != null)
                            {
                                featureLayer.FeatureClass = featureLayer1.FeatureClass;
                            }
                        }
                        _pageLayoutControl.Refresh();

比较:方法二优点是可以不用对模板的引用控件进行处理。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值