首页 / 浏览问题 / 组件GIS / 问题详情
布局窗口中绘制图片
31EXP 2017年05月11日
布局窗口中绘制图片怎么实现?

1个回答

使用获取布局的元素集合对象MapLayout.Elements ,然后通过LayoutElements.AddNew 方法,向布局中加入GeoPicture对象即可,具体使用方法可以参考帮助文档
1,747EXP 2017年05月11日
/// <summary>
        /// 对象添加事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void m_mapLayoutControl_ElementAdded(object sender, ElementEventArgs e)
        {
            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)
                        {
                            northArrow.BindingGeoMapID = m_mapID;
                        }

                        GeoMapScale mapScale = gemetry as GeoMapScale;
                        if (mapScale != null)
                        {
                            mapScale.BindingGeoMapID = m_mapID;
                        }
                        GeoPoint point = gemetry as GeoPoint;
                        if (point != null)
                        {
                            //打开图片对话框
                            using (OpenFileDialog op = new OpenFileDialog())
                            {
                                op.Title = "打开图片文件";
                                op.Multiselect = false;
                                op.CheckFileExists = true;
                                op.Filter = "支持的图像格式(*.png,*.jpg,*.jpeg,*.gif,*.bmp)|*.png;*.jpg;*.jpeg;*.gif;*.bmp";
                                if (op.ShowDialog() == DialogResult.OK)
                                {
                                    string fileName = op.FileName;
                                    if (!System.IO.File.Exists(fileName)) return;

                                    Point2D pt2d = new Point2D(point.X,point.Y);
                                    GeoPicture geoPicture = new GeoPicture(fileName, pt2d, 1, 1, 0);
                                    gemetry = geoPicture as Geometry;
                                }
                            }
                        }
                        GeoText geoText = gemetry as GeoText;
                        //绘制文本
                        if (geoText != null)
                        {
                            
                            geoText.TextStyle.ForeColor = Color.Green;
                            geoText.TextStyle.FontHeight = 32;
                            geoText[0].Text = m_text;
                        }
                        GeoCompound geoCompound = gemetry as GeoCompound;
                        //绘制沿线文本
                        if (geoCompound != null)
                        {
                            GeoText _geoText = geoCompound[0] as GeoText;
                            _geoText.TextStyle.ForeColor = Color.Green;
                            _geoText.TextStyle.FontHeight = 32;
                            _geoText[0].Text = m_text;
                        }
                        elements.SetGeometry(gemetry);
                        elements.Refresh();
                        m_mapLayoutControl.MapLayout.Refresh();
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }

我这样写添加图片了没反应
你这个 GeoPicture geoPicture = new GeoPicture(fileName, pt2d, 1, 1, 0);对象构造的有问题吧,高宽就一个像素,加布局肯定看不见啊
...