ArcObjects Library Reference  

MoleDisplay

About the Displaying symbol-based MOLE graphics on a MapControl Sample

[C#]

MoleDisplay.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.DefenseSolutions;
using ESRI.ArcGIS.Display;

namespace MoleBasicDisplay
{
    public partial class MoleDisplay : Form
    {        
        ESRI.ArcGIS.Display.IScreenDisplay sc;
        String[] sic = { "SFAPC----------",
			             "SFAPCF---------",
			             "SFAPFH---------",
			             "SFAPCL---------",
			             "SFAPM----------" };
        Random m = new Random();
        public MoleDisplay()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            LoadDefaultMapData();
        }

		// Load the MOLE Base Map file on the map control.
        private void LoadDefaultMapData()
        {
            string dataPath = GetSdkDataPath() + @"MilitaryOverlayEditor\";
            string defaultMxDoc = dataPath + "molebasemap.mxd";            

            object missing = System.Reflection.Missing.Value;

            if (this.axMapControl1.CheckMxFile(defaultMxDoc))
                this.axMapControl1.LoadMxFile(defaultMxDoc, missing, missing);
            else
            {
                string errorMsg = "Could not load default map document - Application may not work!";
                errorMsg += "\n" + defaultMxDoc;
                System.Diagnostics.Trace.WriteLine(errorMsg);
                MessageBox.Show(errorMsg);
            }
        }

		// Adds multiple MOLE graphics to the screen display.
        private void btnAddGraphics_Click(object sender, EventArgs e)
        {
			// Get a screen display object.
            sc = axMapControl1.ActiveView.ScreenDisplay;
            sc.StartDrawing (0,(short)ESRI.ArcGIS.Display.esriDisplayCacheFlags.esriDisplayCacheNoFlags );
			
			for (int i = 0; i < sic.Length; i++)
			{
				IMoleSymbol markerSymbol = new MoleMarkerSymbolClass();
				markerSymbol.SymbolID = sic[i];
							
				IPoint point = new PointClass();
				point = createRandomPoint();
						
				ESRI.ArcGIS.Display.IMarkerSymbol mm = (IMarkerSymbol)markerSymbol;
				mm.Color = ceateRandomColor();

				ISymbol moleSym = mm as ISymbol;

				sc.SetSymbol(moleSym);
				sc.DrawPoint(point);
			}
			sc.FinishDrawing();
        }
		
        public IPoint createRandomPoint()
	    {
		    IPoint point =  null;		
	        point = new PointClass();            
            point.PutCoords(m.Next(-170, 170), m.Next(-80, 80));	        
		    return point ;
	    }
		
        public ESRI.ArcGIS.Display.IColor ceateRandomColor()
        {
            IRgbColor rgb = new RgbColorClass();
            rgb.Red = m.Next(0, 255);
            rgb.Green = m.Next(0, 255);
            rgb.Blue = m.Next(0, 255);
            return rgb as IColor;
        }

		// Clears all graphics from the screen display.
        private void btnClearGraphics_Click(object sender, EventArgs e)
        {
            if (sc != null)
                sc.Invalidate(axMapControl1.Extent, true, 0);
            
        }

        private string GetSdkDataPath()
        {
            //get the ArcGIS path from the registry
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ESRI\ArcGIS_SXS_SDK");
            string path = Convert.ToString(key.GetValue("InstallDir"));

            //set the of the logo
            string str = System.IO.Path.Combine(path, @"Samples\data\");

            if (!System.IO.Directory.Exists(str))
            {
                MessageBox.Show("Path :" + str + " does not exist!");
                return string.Empty;
            }

            return str;
        }
    }
}
[Visual Basic .NET]

MoleDisplay.vb


Public Class MoleDisplay
    Dim COUNT As Int32
    Dim m_Random As New Random
    Dim sicArray() As String = {"SFAPC----------", "SFAPCF---------", "SFAPFH---------", "SFAPCL---------", "SFAPM----------"}
    Dim sd As ESRI.ArcGIS.Display.IScreenDisplay


#Region "class constructor"
    Public Sub New()
        ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine)
        InitializeComponent()
    End Sub
#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        COUNT = 5
        AxMapControl1.LoadMxFile(GetSdkDataPath() + "MilitaryOverlayEditor\MoleBasemap.mxd")
        ' drawSymbols()

    End Sub

    Private Sub drawSymbols()

        ' get screen display from active view

        sd = AxMapControl1.ActiveView.ScreenDisplay
        sd.StartDrawing(sd.hDC, ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache)


        Dim i As String
        For Each i In sicArray
            'create point
            Dim point As ESRI.ArcGIS.Geometry.IPoint
            point = CreateRandomPoint()

            'create marker symbol from mole marker symbol class
            Dim markerSym As ESRI.ArcGIS.DefenseSolutions.IMoleSymbol
            markerSym = New ESRI.ArcGIS.DefenseSolutions.MoleMarkerSymbolClass()

            'set the symbol id on the marker symbol
            markerSym.SymbolID = i

            'assign color to the symbol
            Dim m As ESRI.ArcGIS.Display.IMarkerSymbol
            m = markerSym
            m.Color = CreateRandomColor()

            'now that we have the symbol add it to screen display
            sd.SetSymbol(m)
            sd.DrawPoint(point)
        Next i
        sd.FinishDrawing()

    End Sub

    Public Function CreateRandomPoint() As ESRI.ArcGIS.Geometry.IPoint
        ' Create a new point and set its properties
        Dim point As ESRI.ArcGIS.Geometry.IPoint
        point = New ESRI.ArcGIS.Geometry.PointClass()
        point.PutCoords(m_Random.Next(-30, 30), m_Random.Next(-30, 30))
        Return point

    End Function

    Public Function CreateRandomColor() As ESRI.ArcGIS.Display.IColor

        Dim rgb As ESRI.ArcGIS.Display.IRgbColor
        rgb = New ESRI.ArcGIS.Display.RgbColorClass()
        rgb.Red = m_Random.Next(0, 255)
        rgb.Green = m_Random.Next(0, 255)
        rgb.Blue = m_Random.Next(0, 255)

        Return rgb

    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        drawSymbols()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        sd.Invalidate(AxMapControl1.Extent, True, ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache)

    End Sub

    Private Function GetSdkDataPath() As String
        'get the ArcGIS path from the registry
        Dim key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\ESRI\ArcGIS_SXS_SDK")
        Dim path As String = Convert.ToString(key.GetValue("InstallDir"))

        'set the of the logo
        Dim str As String = System.IO.Path.Combine(path, "Samples\data\")
        If (Not System.IO.Directory.Exists(str)) Then
            MessageBox.Show("Path :" & str & " does not exist!")
            Return String.Empty
        End If

        Return str
    End Function

End Class