C#C# ArcEngine二次支付之动态图层

  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);
        }

 

相关文章