ArcObjects Library Reference  

MapGraphicTrackExtension

About the Move a graphic along a path in ArcMap Sample

[C#]

MapGraphicTrackExtension.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using ESRI.ArcGIS.Animation;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Framework;

namespace AnimationDeveloperSamples
{
    [Guid("A18921C8-275B-4CDC-B830-C7F8DB1E92EC")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("CustomMapAnimation1.MapGraphicTrackExtension")]
    public class MapGraphicTrackExtension:IMapGraphicTrackExtension,IPersistStream
    {
        private IPropertySet propSet;
        private IPersistStream persist;

        #region constructor
        public MapGraphicTrackExtension()
        {
            ILineElement traceElement = new LineElementClass();
            SetDefaultSymbol(traceElement);
            //add a tag to the trace line
            IElementProperties elemProps = (IElementProperties)traceElement;
            elemProps.Name = "{E63706E1-B13C-4184-8AB8-97F67FA052D4}";
            bool showTrace = true;
            propSet = new PropertySetClass();
            propSet.SetProperty("Line Element", traceElement);
            propSet.SetProperty("Show Trace", showTrace);
            persist = (IPersistStream)propSet;
        }
        #endregion

        #region IMapGraphicTrackExtension members
        public ILineElement TraceElement
        {
            get {
                return (ILineElement)propSet.GetProperty("Line Element");
            }
            set {
                ILineElement temp = value;
                propSet.SetProperty("Line Element", temp);
            }
        }

        public bool ShowTrace
        {
            get {
                return (bool)propSet.GetProperty("Show Trace");
            }
            set {
                bool temp = value;
                propSet.SetProperty("Show Trace", temp);
            }
        }

        public void ClearTrace()
        {
            IElement elem = (IElement)propSet.GetProperty("Line Element");
            elem.Geometry.SetEmpty();
        }
        #endregion

        #region IPersistStream Members
        public void GetSizeMax(out _ULARGE_INTEGER pcbSize)
        {
            persist.GetSizeMax(out pcbSize);
        }

        public void GetClassID(out Guid pClassID)
        {
            pClassID = this.GetType().GUID;
        }

        public void Load(IStream pstm)
        {
            persist.Load(pstm);
        }

        public void IsDirty()
        {
            persist.IsDirty();
        }

        public void Save(IStream pstm, int fClearDirty)
        {
            persist.Save(pstm, fClearDirty);
        }
        #endregion

        #region private methods
        private void SetDefaultSymbol(ILineElement elem)
        {
            ILineSymbol defaultLineSym = null;
            String esriStylePath;
            IStyleGallery styleGallery = new StyleGalleryClass();
            IStyleGalleryStorage styleStor = (IStyleGalleryStorage)styleGallery;
            esriStylePath = styleStor.DefaultStylePath + "ESRI.style";

            IEnumStyleGalleryItem styleItems = styleGallery.get_Items("Line Symbols",esriStylePath,"Dashed");
            styleItems.Reset();
            IStyleGalleryItem styleGalleryItem = styleItems.Next();
            while (!(styleGalleryItem == null))
            {
                if (styleGalleryItem.Name == "Dashed 4:4")
                {
                    defaultLineSym = (ILineSymbol)styleGalleryItem.Item;
                    defaultLineSym.Width = 1.50;
                    IRgbColor rgbColor = new RgbColorClass();
                    rgbColor.Red = 255;
                    rgbColor.Blue = 0;
                    rgbColor.Green = 0;
                    rgbColor.Transparency = 50;
                    defaultLineSym.Color = rgbColor;
                    break;
                }
                else
                {
                    styleGalleryItem = styleItems.Next();
                }
            }
            elem.Symbol = defaultLineSym;
        }
        #endregion
    }

    public interface IMapGraphicTrackExtension
    {
        ILineElement TraceElement
        {
            get;
            set;
        }

        bool ShowTrace
        {
            get;
            set;
        }

        void ClearTrace();
        
    }
}

[Visual Basic .NET]

MapGraphicTrackExtension.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports ESRI.ArcGIS.Animation
Imports ESRI.ArcGIS.ADF
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.Framework

<Guid("829D5FE5-D6FB-44FE-8729-FC9454D8B171"), ClassInterface(ClassInterfaceType.None), ProgId("AnimationDeveloperSamples.MapGraphicTrackExtension")> _
Public Class MapGraphicTrackExtension : Implements IPersistStream, IMapGraphicTrackExtension

    Private propSet As IPropertySet
    Private persist As IPersistStream

#Region "constructor"
    Public Sub New()
        Dim traceElem As ILineElement = New LineElementClass()
        SetDefaultSymbol(traceElem)
        'add a tag to the trace line
        Dim elemProps As IElementProperties = CType(traceElem, IElementProperties)
        elemProps.Name = "{E63706E1-B13C-4184-8AB8-97F67FA052D4}"
        Dim bShowTrace As Boolean = True
        propSet = New PropertySetClass()
        propSet.SetProperty("Line Element", traceElem)
        propSet.SetProperty("Show Trace", bShowTrace)
        persist = CType(propSet, IPersistStream)
    End Sub
#End Region

#Region "IPersistStream Members"
    Public Sub GetSizeMax(<System.Runtime.InteropServices.Out()> ByRef pcbSize As _ULARGE_INTEGER) Implements IPersistStream.GetSizeMax
        persist.GetSizeMax(pcbSize)
    End Sub

    Public Sub GetClassID(<System.Runtime.InteropServices.Out()> ByRef pClassID As Guid) Implements IPersist.GetClassID
        pClassID = Me.GetType().GUID
    End Sub

    Public Sub GetClassID1(<System.Runtime.InteropServices.Out()> ByRef pClassID As Guid) Implements IPersistStream.GetClassID
        pClassID = Me.GetType().GUID
    End Sub

    Public Sub Load(ByVal pstm As IStream) Implements IPersistStream.Load
        persist.Load(pstm)
    End Sub

    Public Sub IsDirty() Implements IPersistStream.IsDirty
        persist.IsDirty()
    End Sub

    Public Sub Save(ByVal pstm As IStream, ByVal fClearDirty As Integer) Implements IPersistStream.Save
        persist.Save(pstm, fClearDirty)
    End Sub
#End Region

#Region "IMapGraphicTrackExtension members"
    Public Property TraceElement() As ILineElement Implements IMapGraphicTrackExtension.TraceElement
        Get
            Return CType(propSet.GetProperty("Line Element"), ILineElement)
        End Get
        Set(ByVal value As ILineElement)
            Dim temp As ILineElement = CType(value, ILineElement)
            propSet.SetProperty("Line Element", temp)
        End Set
    End Property

    Public Property ShowTrace() As Boolean Implements IMapGraphicTrackExtension.ShowTrace
        Get
            Return CBool(propSet.GetProperty("Show Trace"))
        End Get
        Set(ByVal value As Boolean)
            Dim temp As Boolean = value
            propSet.SetProperty("Show Trace", temp)
        End Set
    End Property

    Public Sub ClearTrace() Implements IMapGraphicTrackExtension.ClearTrace
        Dim elem As IElement = CType(propSet.GetProperty("Line Element"), IElement)
        elem.Geometry.SetEmpty()
    End Sub
#End Region

#Region "private methods"
    Private Sub SetDefaultSymbol(ByVal elem As ILineElement)
        Dim defaultLineSym As ILineSymbol = Nothing
        Dim esriStylePath As String
        Dim styleGallery As IStyleGallery = New StyleGalleryClass()
        Dim styleStor As IStyleGalleryStorage = CType(styleGallery, IStyleGalleryStorage)
        esriStylePath = styleStor.DefaultStylePath & "ESRI.style"

        Dim styleItems As IEnumStyleGalleryItem = styleGallery.Items("Line Symbols", esriStylePath, "Dashed")
        styleItems.Reset()
        Dim styleGalleryItem As IStyleGalleryItem = styleItems.Next()
        Do While Not (styleGalleryItem Is Nothing)
            If styleGalleryItem.Name = "Dashed 4:4" Then
                defaultLineSym = CType(styleGalleryItem.Item, ILineSymbol)
                defaultLineSym.Width = 1.5
                Dim rgbColor As IRgbColor = New RgbColorClass()
                rgbColor.Red = 255
                rgbColor.Blue = 0
                rgbColor.Green = 0
                rgbColor.Transparency = 50
                defaultLineSym.Color = rgbColor
                Exit Do
            Else
                styleGalleryItem = styleItems.Next()
            End If
        Loop
        elem.Symbol = defaultLineSym
    End Sub
#End Region
End Class

Public Interface IMapGraphicTrackExtension
    Property TraceElement() As ILineElement

    Property ShowTrace() As Boolean

    Sub ClearTrace()

End Interface