• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#ArcEngine二次开发之动态图层

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

  ArcEngine搭载C#进行GIS的二次开发,关于目标显示的问题,由于考虑到设置定时器刷新目标位置和方向,因此在显示图层上采用的是动态图层DynamicLayer,主要用到的dll文件是ESRI.ArcGIS.ADF.BaseClasses,通过继承BaseDynamicLayer设计一个自己的动态图层基类,这样在加载其他图层时可以很方便的调用。先上基类的代码

using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using System;
using System.Windows.Forms;

namespace GIS
{
    public abstract class myDynamicLayer : BaseDynamicLayer
    {
        protected IDynamicGlyph DynamicGlyph;

        private readonly Timer timer = new Timer();
        private bool isUpdate;

        public IColor TransparenyColor { get; set; }

        public int Level { get; set; }

        public double Scale
        {
            get { return MapElement.GetScale(Level); }
        }

        public IPoint MouseMvePoint { get; set; }


        public string LayerName
        {
            get { return m_sName; }
            set { m_sName = value; }
        }

        public int TimerInterval
        {
            get { return timer.Interval; }
            set
            {
                timer.Enabled = false;
                timer.Interval = value;
                timer.Enabled = true;
            }
        }

        public void BeginUpdate()
        {
            isUpdate = true;
        }

        public void EndUpdate()
        {
            isUpdate = false;
        }

        protected FisDynamicLayer()
        {
            Level = 11;
            timer.Interval = 15;
            timer.Tick += timer_Tick;
            timer.Enabled = true;
            TransparenyColor = MapElement.SetColor(255, 255, 255, 64);
        }

        public override void DrawDynamicLayer(esriDynamicDrawPhase DynamicDrawPhase, IDisplay Display, IDynamicDisplay DynamicDisplay)
        {
            if (!m_bIsImmediateDirty) return;

            if (DynamicDrawPhase != esriDynamicDrawPhase.esriDDPImmediate)
            {
                return;
            }

            if (!m_bValid || !m_visible)
            {
                return;
            }

            if (isUpdate)
            {
                return;
            }

            IDynamicSymbolProperties2 DynamicSymbolProps = DynamicDisplay as IDynamicSymbolProperties2;
            IDynamicGlyphFactory2 DynamicGlyphFactory2 = DynamicDisplay.DynamicGlyphFactory as IDynamicGlyphFactory2;

            if (DynamicSymbolProps == null || DynamicGlyphFactory2 == null)
            {
                return;
            }

            DrawDynamicLayerEx(DynamicDisplay, DynamicGlyphFactory2, DynamicSymbolProps);

            m_bIsImmediateDirty = false;
        }
        private void timer_Tick(object sender, EventArgs e)
        {
            if (!m_bIsImmediateDirty)
                m_bIsImmediateDirty = true;
        }
   }
}

此外需要在动态图层基类中创建一个abstract方法以方便继承时写入不同图层的需要

public abstract void DrawDynamicLayerEx(IDynamicDisplay DynamicDisplay, IDynamicGlyphFactory2 DynamicGlyphFactory2, IDynamicSymbolProperties2 DynamicSymbolProps);

  这样你就有了一个可以继承的动态图层基类了,生成新图层时重写上面的抽象方法即可,例如:

public override void DrawDynamicLayerEx(IDynamicDisplay DynamicDisplay, IDynamicGlyphFactory2 DynamicGlyphFactory2, IDynamicSymbolProperties2 DynamicSymbolProps)
        {
            if (MouseMvePoint == null)
            {
                return;
            }

            if (!IsClicked)
            {
                return;
            }

            if (pPointCollection.PointCount > 1)
            {
                pPointCollection.RemovePoints(0, pPointCollection.PointCount);
            }

            if (pPointCollection.PointCount > 0)
            {
                if (IsMoved)
                {
                    Radius = CircleRadius(pPointCollection.Point[0], MouseMvePoint);

                }

                points = CirclePointCollection(pPointCollection.Point[0], Radius, 80);
            }

            DynamicSymbolProps.SetScale(esriDynamicSymbolType.esriDSymbolMarker, 6.0f, 6.0f);
            DynamicSymbolProps.SetColor(esriDynamicSymbolType.esriDSymbolMarker, 255.0f, 0.0f, 0.0f, 1.0f);
            DynamicDisplay.DrawMarker(CenterPoint);

            DynamicSymbolProps.SetScale(esriDynamicSymbolType.esriDSymbolMarker, 1.0f, 1.0f);
            DynamicSymbolProps.SetColor(esriDynamicSymbolType.esriDSymbolMarker, 255.0f, 0.0f, 0.0f, 1.0f);
            DynamicDisplay.DrawPolyline(points);

            DynamicSymbolProps.SetScale(esriDynamicSymbolType.esriDSymbolMarker, 1.0f, 1.0f);
            DynamicSymbolProps.SetColor(esriDynamicSymbolType.esriDSymbolMarker, 255.0f, 0.0f, 0.0f, 0.5f);
            DynamicDisplay.DrawPolygon(points);
        }

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
14.C#/.NET编程中的常见异常(持续更新)发布时间:2022-07-14
下一篇:
c#阿拉伯数字转成中文发布时间:2022-07-14
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap