コード例 #1
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                if (!m_bConnected)
                {
                    //show the tracking type selection dialog (whether to track the element from above or follow it from behind)
                    TrackSelectionDlg dlg = new TrackSelectionDlg();
                    if (System.Windows.Forms.DialogResult.OK != dlg.ShowDialog())
                    {
                        return;
                    }

                    //get the required tracking mode
                    m_bTrackAboveTarget = dlg.UseOrthoTrackingMode;

                    //do only once initializations
                    if (m_once)
                    {
                        //create the graphics layer to manage the dynamic object
                        m_globeGraphicsLayer = new GlobeGraphicsLayerClass();
                        ((ILayer)m_globeGraphicsLayer).Name = "DynamicObjects";

                        IScene scene = (IScene)m_globeDisplay.Globe;

                        //add the new graphic layer to the globe
                        scene.AddLayer((ILayer)m_globeGraphicsLayer, false);

                        //activate the graphics layer
                        scene.ActiveGraphicsLayer = (ILayer)m_globeGraphicsLayer;

                        //redraw the GlobeDisplay
                        m_globeDisplay.RefreshViewers();

                        //open a polyline featurelayer that would serve the real-time feed GPS simulator
                        IFeatureLayer featureLayer = GetFeatureLayer();
                        if (featureLayer == null)
                        {
                            return;
                        }

                        //assign the featurelayer to the GPS simulator
                        m_realTimeFeedManager.RealTimeFeedSimulator.FeatureLayer = featureLayer;

                        m_once = false;
                    }

                    //get the GlobeViewUtil which is needed for coordinate transformations
                    m_sceneViwer = m_globeDisplay.ActiveViewer;

                    //Set the globe mode to terrain mode, since otherwise it will not be possible to set the target position
                    ((IGlobeCamera)m_sceneViwer.Camera).OrientationMode = esriGlobeCameraOrientationMode.esriGlobeCameraOrientationLocal;


                    //set the simulator elapsed time
                    m_realTimeFeedManager.RealTimeFeedSimulator.TimeIncrement = 0.1; //sec

                    //wire the real-time feed PositionUpdate event
                    ((IRealTimeFeedEvents_Event)m_realTimeFeed).PositionUpdated += new IRealTimeFeedEvents_PositionUpdatedEventHandler(OnPositionUpdated);

                    //start the real-time listener
                    m_realTimeFeed.Start();
                }
                else
                {
                    //stop the real-time listener
                    m_realTimeFeed.Stop();

                    //un-wire the PositionUpdated event handler
                    ((IRealTimeFeedEvents_Event)m_realTimeFeed).PositionUpdated -= new IRealTimeFeedEvents_PositionUpdatedEventHandler(OnPositionUpdated);
                }

                //switch the connection flag
                m_bConnected = !m_bConnected;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }
コード例 #2
0
    /// <summary>
    /// Occurs when this command is clicked
    /// </summary>
    public override void OnClick()
    {
      try
      {

        if (!m_bConnected)
        {
          //show the tracking type selection dialog (whether to track the element from above or follow it from behind)
          TrackSelectionDlg dlg = new TrackSelectionDlg();
          if (System.Windows.Forms.DialogResult.OK != dlg.ShowDialog())
            return;

          //get the required tracking mode
          m_bTrackAboveTarget = dlg.UseOrthoTrackingMode;

          //do only once initializations
          if (m_once)
          {
            //create the graphics layer to manage the dynamic object
            m_globeGraphicsLayer = new GlobeGraphicsLayerClass();
            ((ILayer)m_globeGraphicsLayer).Name = "DynamicObjects";

            IScene scene = (IScene)m_globeDisplay.Globe;

            //add the new graphic layer to the globe
            scene.AddLayer((ILayer)m_globeGraphicsLayer, false);

            //activate the graphics layer
            scene.ActiveGraphicsLayer = (ILayer)m_globeGraphicsLayer;

            //redraw the GlobeDisplay
            m_globeDisplay.RefreshViewers();

            //open a polyline featurelayer that would serve the real-time feed GPS simulator
            IFeatureLayer featureLayer = GetFeatureLayer();
            if (featureLayer == null)
              return;
            
            //assign the featurelayer to the GPS simulator
            m_realTimeFeedManager.RealTimeFeedSimulator.FeatureLayer = featureLayer;

            m_once = false;
          }

          //get the GlobeViewUtil which is needed for coordinate transformations
          m_sceneViwer = m_globeDisplay.ActiveViewer;

          //Set the globe mode to terrain mode, since otherwise it will not be possible to set the target position
         ((IGlobeCamera)m_sceneViwer.Camera).OrientationMode = esriGlobeCameraOrientationMode.esriGlobeCameraOrientationLocal;


          //set the simulator elapsed time
          m_realTimeFeedManager.RealTimeFeedSimulator.TimeIncrement = 0.1; //sec

          //wire the real-time feed PositionUpdate event
          ((IRealTimeFeedEvents_Event)m_realTimeFeed).PositionUpdated += new IRealTimeFeedEvents_PositionUpdatedEventHandler(OnPositionUpdated);

          //start the real-time listener
          m_realTimeFeed.Start();
        }
        else
        {
          //stop the real-time listener
          m_realTimeFeed.Stop();

          //un-wire the PositionUpdated event handler
          ((IRealTimeFeedEvents_Event)m_realTimeFeed).PositionUpdated -= new IRealTimeFeedEvents_PositionUpdatedEventHandler(OnPositionUpdated);
        }

        //switch the connection flag
        m_bConnected = !m_bConnected;
      }
      catch (Exception ex)
      {
        System.Diagnostics.Trace.WriteLine(ex.Message);
      }
    }