• supermap布局设定地图网格及布局网格


    地图网格设定

      LayoutElements elements = m_mapLayoutControl.MapLayout.Elements;               
                    //构造GeoMap
                    GeoMap geoMap = new GeoMap();
                    geoMap.MapName = "京津地区交通干线图";
                    // 新建一个 GeoMapGrid 对象。
                    GeoMapGrid geoMapGrid = new GeoMapGrid();
    
                    // 设置 GeoMapGrid 对象的相关属性,即设置地图的经纬网的风格。
    
                    // 设置为地图添加经纬网。
                    geoMapGrid.GridType = GeoMapGridType.Graticule;
                    // 设置经纬网的格网线的线型风格。
                    geoMapGrid.GridLineStyle.LineSymbolID = 9;
                    geoMapGrid.GridLineStyle.LineColor = Color.Black;
                    // 设置经纬网的格网线的水平、竖直间距。
                    geoMapGrid.HorizontalGridDistance = 40;
                    geoMapGrid.VerticalGridDistance = 40;
                    // 设置经纬网的格网线的类型为实线。
                    geoMapGrid.GridLineType = GeoMapGridLineType.SolidLine;
                    // 设置经纬网的边框风格。
                    GeoStyle style = new GeoStyle();
                    style.LineSymbolID = 6;
                    style.LineColor = Color.Blue;
                    style.LineWidth = 0.2;
                    geoMapGrid.BorderLineStyle = style;
                    // 设置经纬网文本标注的水平、竖直位置。
                    geoMapGrid.HorizontalTextPosition = HorizontalTextPositionType.Middle;
                    geoMapGrid.VerticalTextPosition = VerticalTextPositionType.Middle;
                    // 设置经纬网文本标注的文本风格。
                    geoMapGrid.GridLineTextStyle.ForeColor = Color.Black;
                    geoMapGrid.GridLineTextStyle.FontHeight = 60;
                    // 为地图对象添加经纬网。
                    geoMap.IsGridVisible = true;
                    geoMap.MapGrid = geoMapGrid;
    
    
                    //设置GeoMap对象的外切矩形
                    Rectangle2D rect = new Rectangle2D(new Point2D(850, 1300), new Size2D(1500, 1500));
                    GeoRectangle geoRect = new GeoRectangle(rect, 0);
                    geoMap.Shape = geoRect;
                    elements.AddNew(geoMap);
                    m_mapID = elements.GetID();
    
                    //构造指北针
                    GeoNorthArrow northArrow = new GeoNorthArrow(
                                                NorthArrowStyleType.EightDirection,
                                                new Rectangle2D(new Point2D(1400, 2250), new Size2D(350, 350)),
                                                0);
                    northArrow.BindingGeoMapID = m_mapID;
    
                    elements.AddNew(northArrow);
    
                    //构造比例尺
                    GeoMapScale scale = new GeoMapScale(m_mapID, new Point2D(125, 400), 50, 50);
                    scale.LeftDivisionCount = 2;
                    scale.ScaleUnit = Unit.Kilometer;
                    scale.SegmentCount = 4;
    
                    elements.AddNew(scale);
    地图网格设定

    布局网格设定

     /*
                //背景色
                GeoStyle  s=new GeoStyle();
                s.FillForeColor = background.BackColor;
                m_mapLayoutControl.MapLayout.BackgroundStyle = s;     
         
                //刻度尺
                RulerSetting ssss = m_mapLayoutControl.MapLayout.RulerSetting;
                ssss.IsRulerVisible = false;
                //压盖
                m_mapLayoutControl.MapLayout.IsOverlapDisplayed = true;
                //布局文字反走样式
                m_mapLayoutControl.MapLayout.IsTextAntialias = true;
               //最小缩放比例
                m_mapLayoutControl.MapLayout.MinZoomRatio = 0.01;
                //最大缩放比例
                m_mapLayoutControl.MapLayout.MaxZoomRatio = 0.01;
                //是否显示水平滚动条
                m_mapLayoutControl.IsHorizontalScrollbarVisible = true;
                //是否显示垂直滚动条
                m_mapLayoutControl.IsVerticalScrollbarVisible = true;
                //是否支持对象修改后启用实时刷新
               // m_mapLayoutControl.RefreshAtTracked = true;
                //获取设置格网是否可以捕捉
                m_mapLayoutControl.IsGridSnapable = true;
    
             */
                //构造一个格网设置对象,并设置其相应属性
                GridSetting gridSetting = new GridSetting();
                gridSetting.IsSizeFixed = true;
                gridSetting.IsSnapable = true;
                gridSetting.IsVisible = true;
                gridSetting.VerticalSpacing = 50;
                gridSetting.Type = GridType.Cross;
                gridSetting.HorizontalSpacing = 50;
    
                GeoStyle style1 = new GeoStyle();
                style1.LineColor = Color.Gray;
                gridSetting.DashStyle = style1;
    
                GeoStyle style2 = new GeoStyle();
                style2.LineColor = Color.Gold;
                gridSetting.SolidStyle = style2;
                //设置地图对象的格网设置
                m_mapLayoutControl.MapLayout.Paper.Grid = gridSetting;
    
               // m_mapLayoutControl.MapLayout.Paper.IsVisible = false;
               // m_mapLayoutControl.MapLayout.Elements.AddNew(geoMap);
              
               m_mapLayoutControl.MapLayout.Refresh();
    布局网格设定
     /// <summary>
            /// 布局添加要素方法事件
            /// cwj
            /// 2017-07-19
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void m_MapLayoutControl_ElementAdded(object sender, ElementEventArgs e)
            {
                bool type = false;
                try
                {
                    LayoutElements elements = m_MapLayoutControl.MapLayout.Elements;
                    if (elements.SeekID(e.ID))
                    {
                        Geometry gemetry = elements.GetGeometry();
                        if (gemetry != null)
                        {
                            GeoNorthArrow northArrow = gemetry as GeoNorthArrow;
                            if (northArrow != null)
                            {
                                if (mapLayoutGeolend < 0) return;
                                type = false;
                                northArrow.BindingGeoMapID = mapLayoutGeolend;
                                elements.SeekID(northArrow.ID); 
                            }
                            GeoMapScale mapScale = gemetry as GeoMapScale;
                            if (mapScale != null)
                            {
                                if (mapLayoutGeolend < 0) return;
                                type = false;
                                mapScale.BindingGeoMapID = mapLayoutGeolend;
                                elements.SeekID(mapScale.ID); 
                            }
    
                            GeoLegend geoLegend = gemetry as GeoLegend;                       
                            if (geoLegend != null)
                            {
                                if (mapLayoutGeolend < 0) return;
                                type = false;
                                elements.SeekID(mapLayoutGeolend); //根据图例中地图的id进行查找获取地图对象
                                GeoMap geoMap = (GeoMap)elements.GetGeometry();                          
                                string geoMapName = geoMap.MapName;
                                geoLegend.MapName = geoMapName;                      
                                geoLegend.Load(false);
                                elements.SeekID(geoLegend.ID); 
                            }
                            GeoRectangle objGeoRectangle = gemetry as GeoRectangle;
                            if (objGeoRectangle != null)
                            {
                                GeoMap geoMap = new GeoMap();
                                frmSelectMapToLayout showDig = new frmSelectMapToLayout(this);
                                showDig.ShowDialog();
                                if (string.IsNullOrWhiteSpace(showDig.mapNameDisplay)) return;
                                geoMap.MapName = showDig.mapNameDisplay;                        
                                geoMap.Shape = objGeoRectangle; 
                                 int[] id = new int[] { e.ID };
                                //对绘制的矩形先删除,再把地图展示出来
                                 //一箫一剑走江湖,环球愿景已荒芜。
                                 elements.Delete(id);
                                 elements.AddNew(geoMap);                         
                                 type = true;                        
    
                            }
                            if (type)
                            {
                               // elements.AddNew(gemetry);
                                this.m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.Select2;
                            }
                            //当初是出于什么原因把这段代码加上呢???????  
                                //原因是 当不加入一下代码是 添加用addnew方法会导致在拖动 控件时 多出一个白色的框,暂不理解addnew 和setgeometry的原理,看api解析不好使,猜测是绘制框显示的问题
                            else
                            {
                               
                                elements.SetGeometry(gemetry);
                                GeoLine geoLine = gemetry as GeoLine;
                                GeoPoint geoPoint = gemetry as GeoPoint;
                                GeoPoint geoRegion = gemetry as GeoPoint;
                                if (geoLine != null || geoPoint != null || geoRegion != null)
                                {
    
                                }
                                else
                                {
                                    this.m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.Select2;
                                }
                            }
                            elements.Refresh();                     
                            m_MapLayoutControl.MapLayout.Refresh();
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorTrapping.WriteLog(ex);
                }
            }
            //选择地图
            public int GetMapID()
            {
                int mapID = -1;
                int count = 0;
                LayoutSelection layoutSelection = m_MapLayoutControl.MapLayout.Selection;
                LayoutElements layoutElements = m_MapLayoutControl.MapLayout.Elements;
                layoutElements.Refresh();
                for (int i = 0; i < layoutSelection.Count; i++)
                {
                    int ID = layoutSelection[i];
                    layoutElements.SeekID(ID);
                    Geometry geometry = layoutElements.GetGeometry();
                    if (geometry.Type == GeometryType.GeoMap)
                    {
                        mapID = ID;
                        count++;
                    }
                    if (count > 1)
                    {
                        mapID = -1;
                    }
                }
                return mapID;
            }
            //选择指南针
            public int GetArrowID()
            {
                int ArrowID = -1;
                int count = 0;
                LayoutSelection layoutSelection = m_MapLayoutControl.MapLayout.Selection;
                LayoutElements layoutElements = m_MapLayoutControl.MapLayout.Elements;
                layoutElements.Refresh();
                for (int i = 0; i < layoutSelection.Count; i++)
                {
                    int ID = layoutSelection[i];
                    layoutElements.SeekID(ID);
                    Geometry geometry = layoutElements.GetGeometry();
                    if (geometry.Type == GeometryType.GeoNorthArrow)
                    {
                        ArrowID = ID;
                        count++;
                    }
                    if (count > 1)
                    {
                        ArrowID = -1;
                    }
                }
                return ArrowID;
            }
            //选择比例尺
            public int GetScaleID()
            {
                int ScaleID = -1;
                int count = 0;
                LayoutSelection layoutSelection = m_MapLayoutControl.MapLayout.Selection;
                LayoutElements layoutElements = m_MapLayoutControl.MapLayout.Elements;
                layoutElements.Refresh();
                for (int i = 0; i < layoutSelection.Count; i++)
                {
                    int ID = layoutSelection[i];
                    layoutElements.SeekID(ID);
                    Geometry geometry = layoutElements.GetGeometry();
                    if (geometry.Type == GeometryType.GeoMapScale)
                    {
                        ScaleID = ID;
                        count++;
                    }
                    if (count > 1)
                    {
                        ScaleID = -1;
                    }
                }
                return ScaleID;
            }
            //选择比例尺
            public int GetlendID()
            {
                int lendID = -1;
                int count = 0;
                LayoutSelection layoutSelection = m_MapLayoutControl.MapLayout.Selection;
                LayoutElements layoutElements = m_MapLayoutControl.MapLayout.Elements;
                layoutElements.Refresh();
                for (int i = 0; i < layoutSelection.Count; i++)
                {
                    int ID = layoutSelection[i];
                    layoutElements.SeekID(ID);
                    Geometry geometry = layoutElements.GetGeometry();
                    if (geometry.Type == GeometryType.GeoLegend)
                    {
                        lendID = ID;
                        count++;
                    }
                    if (count > 1)
                    {
                        lendID = -1;
                    }
                }
                return lendID;
            }
    
            /// <summary>
            /// cwj 2017-07-19 ******
            /// 指南针点击事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void arrorwAttri_Click(object sender, EventArgs e)
            {
                int ID = GetArrowID();
                if (ID > 0)
                {
                    LayoutElements layoutElements = m_MapLayoutControl.MapLayout.Elements; 
                  
                    layoutElements.SeekID(ID);
                    Geometry objGeometry = layoutElements.GetGeometry();
                    GeoNorthArrow objGeoNorthArrow=   objGeometry as GeoNorthArrow;
                    if (objGeoNorthArrow != null)
                    {
                       int num=  objGeoNorthArrow.BindingGeoMapID;
                      //  int ss = mapLayoutGeolend;
                       layoutElements.SeekID(num);
                        GeoMap objGeoMap = layoutElements.GetGeometry() as GeoMap;
                        string name = objGeoMap.MapName;
                        //layoutElements.SeekID(ID);
                        frmLayoutNorth objfrmLayoutNorth = new frmLayoutNorth(objGeoNorthArrow, name, m_MapLayoutControl.MapLayout, num);
                        objfrmLayoutNorth.Show();
                      
                    }
                }
    
            }
            /// <summary>
            /// cwj 2017-07-19 ******
            /// 比例尺点击事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void layoutmapScalem_Click(object sender, EventArgs e)
            {
                int ID = GetScaleID();
                if (ID > 0)
                {
                    LayoutElements layoutElements = m_MapLayoutControl.MapLayout.Elements;
                    layoutElements.SeekID(ID);
                    Geometry objGeometry = layoutElements.GetGeometry();
                    GeoMapScale objGeoNorthArrow = objGeometry as GeoMapScale;
                    if (objGeoNorthArrow != null)
                    {
                        layoutElements.SeekID(mapLayoutGeolend);
                        GeoMap objGeoMap = layoutElements.GetGeometry() as GeoMap;
                        string name = "";
                        if (objGeoMap != null) {
                            name = objGeoMap.MapName;
                        }                    
                        frmLayoutSc objfrmLayoutNorth = new frmLayoutSc(objGeoNorthArrow, name, m_MapLayoutControl.MapLayout);
                        objfrmLayoutNorth.Show();
    
                    }
                }
            }
            /// <summary>
            /// cwj 2017-07-19 ******
            /// 图例点击事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void maptuli_Click(object sender, EventArgs e)
            {
                int ID = GetlendID();
                if (ID > 0)
                {
                    LayoutElements layoutElements = m_MapLayoutControl.MapLayout.Elements;
                    layoutElements.SeekID(ID);
                    Geometry objGeometry = layoutElements.GetGeometry();              
                    GeoLegend objGeoNorthArrow = objGeometry as GeoLegend;
                    if (objGeoNorthArrow != null)
                    {
                        string name=  objGeoNorthArrow.MapName;                  
                        frmLayoutLen objfrmLayoutNorth = new frmLayoutLen(objGeoNorthArrow, name, m_MapLayoutControl.MapLayout);
                        objfrmLayoutNorth.Show();
                    }
                }
            }
    绘制布局要素
  • 相关阅读:
    华为全联接大会2019,共创智能新高度
    CTDC2019首席技术官领袖峰会,AI赋能 智享5G
    2019全球体验设计峰会:体验赋能商业,创造更好体验
    全球闪存峰会旨在深化技术创新,增进闪存产业链上下游
    PyCon 2019火热来袭,与大数据、人工智能等专家一起探讨Python语言
    PHPConChina 2019 PHP开发者大会将于8月在上海举办!
    2019腾讯Live开发者大会(TLC),引领技术新趋势
    2019 HTML5深度应用开发实践
    2019年5G物联网关键技术与应用培训,了解5G网络发展现状及进展
    2019第二届企业云服务大会 -- 企业智变,云化未来
  • 原文地址:https://www.cnblogs.com/tianyiwuying/p/6255213.html
Copyright © 2020-2023  润新知