In this topic
- Connecting to ArcGIS Tracking Server
- Creating the renderer for the tracking service
- Loading the Tracking Analyst extension
- Initializing the tracking environment
- Creating the temporal layer and hooking it with the service
Connecting to ArcGIS Tracking Server
Consuming real-time data using Tracking Server is done through a temporal layer. Once you establish the connection to the Tracking Server and get the workspace from the Tracking Server, you can open any available tracking service as a feature class. Once you assign the feature class to a temporal layer and set its renderer, you can load it in your map and let the Tracking Server update the items as long as the tracking environment's display manager is set to automatic mode.
To connect to ArcGIS Tracking Server, follow these steps:
- Create a PropertySet and define the connection properties. For more information on Tracking Server connection properties, see AMSWorkspaceFactoryClass. See the following code example:
IPropertySet propSet=new PropertySetClass();
propSet.SetProperty("SERVERNAME", "the name of the server");
propSet.SetProperty("AMS_CONNECTOR_EDITOR", "{1C6BA545-2F59-11D5-B7E2-00010265ADC5}")
;
propSet.SetProperty("AMS_CONNECTION_NAME", "the name of the connection");
propSet.SetProperty("AMS_CONNECTOR", "{F6FC70F5-5778-11D6-B841-00010265ADC5}");
propSet.SetProperty("AMS_USER_NAME", "add your username");
propSet.SetProperty("TMS_USER_PWD", "add your password here");
propSet.SetProperty("CONNECTOR_PORT", "5506");
[VB.NET] Dim propSet As IPropertySet
propSet=New PropertySetClass()
propSet.SetProperty("SERVERNAME", "the name of the server")
propSet.SetProperty("AMS_CONNECTOR_EDITOR", "{1C6BA545-2F59-11D5-B7E2-00010265ADC5}")
propSet.SetProperty("AMS_CONNECTION_NAME", "the name of the connection")
propSet.SetProperty("AMS_CONNECTOR", "{F6FC70F5-5778-11D6-B841-00010265ADC5}")
propSet.SetProperty("AMS_USER_NAME", "add your username")
propSet.SetProperty("TMS_USER_PWD", "add your password here")
propSet.SetProperty("CONNECTOR_PORT", "5506")
- Create the WorkspaceFactory and open the workspace as shown in the following code example:
IWorkspaceFactory2 workspaceFactory=new AMSWorkspaceFactoryClass()as
IWorkspaceFactory2;
IWorkspace workspace=workspaceFactory.Open(propSet, 0);
[VB.NET] Dim workspaceFactory As IWorkspaceFactory2
workspaceFactory=New AMSWorkspaceFactoryClass()
Dim workspace As IWorkspace
workspace=workspaceFactory.Open(propSet, 0)
- Open the service; the service is opened as a feature class. See the following code example:
IAMSWorkspace amsWorkspace=(IAMSWorkspace)workspace;
IFeatureClass featureClass=amsWorkspace.OpenFeatureClass(
"The name of the service goes here");
[VB.NET] Dim amsWorkspace As IAMSWorkspace
amsWorkspace=workspace
Dim featureClass As IFeatureClass
featureClass=amsWorkspace.OpenFeatureClass("The name of the service goes here")
Creating the renderer for the tracking service
In this section, you will instantiate a TrackSymbologyRenderer class, set the name of the temporal field that holds the temporal data in the tracking service, then create the renderer used to symbolize your data in the map.
There are different types of renderers that you can set for your tracking data; for example, you can set a UniqueValueRenderer to symbolize the most current items (items that were recently updated), set a renderer for the trail to display the previous locations of the tracked data, set a labeling renderer, and so on. For more information on assigning renderers to tracking data, see CoTrackSymbologyRendererClass and Play back tracking data.
To create the renderer for the tracking service, follow these steps:
-
Instantiate the TrackSymbologyRenderer class as shown in the following code example:
CoTrackSymbologyRenderer trackingRenderer=new CoTrackSymbologyRendererClass();
[VB.NET] Dim trackingRenderer As CoTrackSymbologyRenderer
trackingRenderer=New CoTrackSymbologyRendererClass()
- Cast TrackSymbologyRenderer into ITemporalRenderer and set the temporal field name. See the following code example:
ITemporalRenderer temporalRenderer=(ITemporalRenderer)trackingRenderer;
temporalRenderer.TemporalFieldName=
"set the name of the temporal field on the tracking service";
[VB.NET] Dim temporalRenderer As ITemporalRenderer
temporalRenderer=trackingRenderer
temporalRenderer.TemporalFieldName="set the name of the temporal field on the tracking service"
- Set a new private method to create a simple renderer for the feed. In the following code example, you will create a simple renderer to symbolize only the most current items. However, you can also create other types of renderers, such as UniqueValueRenderer, UniqueValueTextRenderer, and ProportionalSymbolRenderer. Scroll down to the bottom of your class and add the following private method:
/// <summary>
/// Creates a simple renderer to be used by the layer.
/// </summary>
/// <returns></returns>
private ISimpleRenderer CreateSimpleRenderer(){}
[VB.NET] '''<summary>
''' Creates a simple renderer to be used by the layer.
'''</summary>
''' <returns></returns>
Private Function CreateSimpleRenderer()
End Function
- In the following method, you will create color to be used by the renderer as well as a character marker symbol that will serve as the symbol for the renderer. See the following code example:
IRgbColor color=new RgbColorClass();
color.Red=255;
color.Green=0;
color.Blue=0;
[VB.NET] Dim color As IRgbColor
color=New RgbColorClass()
color.Red=255
color.Green=0
color.Blue=0
- Create the character marker symbol used to symbolize the real-time items. Use the Application Developer Framework (ADF) converter to convert the .NET font into IFontDisp. See the following code example:
ICharacterMarkerSymbol charMarkersymbol=new CharacterMarkerSymbolClass();
charMarkersymbol.Font=ESRI.ArcGIS.ADF.Connection.Local.Converter.ToStdFont(new
Font(new FontFamily("ESRI Default Marker"), 10.0f));
charMarkersymbol.CharacterIndex=111;
charMarkersymbol.Size=14.0;
charMarkersymbol.Color=(IColor)color;
[VB.NET] Dim charMarkersymbol As ICharacterMarkerSymbol
charMarkersymbol=New CharacterMarkerSymbolClass()
Dim font As Font
font=New Font(New FontFamily("ESRI Default Marker"), 10.0F)
charMarkersymbol.Font=ESRI.ArcGIS.ADF.Connection.Local.Converter.ToStdFont(font)
charMarkersymbol.CharacterIndex=111
charMarkersymbol.Size=14.0
charMarkersymbol.Color=color
- Instantiate a new SimpleRenderer and assign it the character marker symbol created in the previous step. See the following code example:
ISimpleRenderer simpleRenderer=new SimpleRendererClass();
simpleRenderer.Label="Airplane";
simpleRenderer.Symbol=(ISymbol)charMarkersymbol;
[VB.NET] Dim simpleRenderer As ISimpleRenderer
simpleRenderer=New SimpleRendererClass()
simpleRenderer.Label="Airplane"
simpleRenderer.Symbol=charMarkersymbol
- Return the newly created renderer as shown in the following code example:
return simpleRenderer;
[VB.NET] CreateSimpleRenderer=simpleRenderer
- Scroll back to where you cast ITemporalRenderer (Step 2 in this section) and use the CreateSimpleRenderer() method to create the renderer used by the temporal layer. See the following code example:
ISimpleRenderer simpleRenderer=CreateSimpleRenderer();
[VB.NET] Dim simpleRenderer As ISimpleRenderer
simpleRenderer=CreateSimpleRenderer()
- To orient the real-time items according to their true heading, use the rotational renderer. To use the rotational renderer, you need a heading attribute as part of your tracking service. Cast the rotational renderer from the simple renderer or any other renderer that you are using. See the following code example:
IRotationRenderer rotationRenderer=(IRotationRenderer)simpleRenderer;
rotationRenderer.RotationField="set the heading field name here";
rotationRenderer.RotationType=esriSymbolRotationType.esriRotateSymbolGeographic;
[VB.NET] Dim rotationRenderer As IRotationRenderer
rotationRenderer=simpleRenderer
rotationRenderer.RotationField="set the heading field name here"
rotationRenderer.RotationType=esriSymbolRotationType.esriRotateSymbolGeographic
- Assign the simple renderer as the layer's most current element renderer. This means that the layer will draw the items that were recently updated using this renderer. See the following code example:
((ITemporalRenderer2)temporalRenderer).MostCurrentRenderer=(IFeatureRenderer)
simpleRenderer;
((ITemporalRenderer2)temporalRenderer).MostCurrentRendererEnabled=true;
[VB.NET] Dim temporalRenderer2 As ITemporalRenderer2
temporalRenderer2=temporalRenderer
temporalRenderer2.MostCurrentRenderer=simpleRenderer
temporalRenderer2.MostCurrentRendererEnabled=True
Loading the Tracking Analyst extension
To load the temporal layers to your map, you must load and enable the Tracking Analyst extension. In the following code example, you will use IExtensionManagerAdmin to create the extension and initialize it by passing the map container (MapControl or ArcMap). For that reason, you will first need to obtain the map from the HookHelper.
To load the Tracking Analyst extension, follow these steps:
- Get the map from the HookHelper as shown in the following code example:
object mapObj=null;
if (m_hookHelper.Hook is IToolbarControl2)
{
IToolbarControl2 toolbarCtrl=(IToolbarControl2)m_hookHelper.Hook;
mapObj=toolbarCtrl.Buddy;
}
else
{
mapObj=m_hookHelper.Hook;
}
[VB.NET] Dim mapObj
mapObj=My.ArcMap.Application
- Create a unique identifier (UID) using the Tracking Engine utility extension's ProgID. See the following code example:
UID uid=new UIDClass();
uid.Value="esriTrackingAnalyst.TrackingEngineUtil";
[VB.NET] Dim uid As UID
uid=New UIDClass()
uid.Value="esriTrackingAnalyst.TrackingEngineUtil"
- Get a reference to ExtensionManager. ExtensionManager is a singleton object that allows you to enable licensed extensions. See Interacting with singleton objects for details, as well as the following code example:
IExtensionManager extensionManager=new ExtensionManagerClass();
[VB.NET] Dim extensionManager As IExtensionManager
extensionManager=New ExtensionManagerClass()
- Add and initialize the Tracking Analyst extension as shown in the following code example:
((IExtensionManagerAdmin)extensionManager).AddExtension(uid, ref mapObj);
[VB.NET] Dim extensionManagerAdmin As IExtensionManagerAdmin
extensionManagerAdmin=extensionManager
extensionManagerAdmin.AddExtension(uid, mapObj)
Initializing the tracking environment
TrackingEnvironment is a singleton object that controls configuration and state information used by the different Tracking Analyst objects. By using the TrackingEnvironment object, you specify whether to work in playback mode or in real-time mode, use default temporal reference for common perspective in time between tracking components, and so on.
To initialize the tracking environment, follow these steps:
- Get a reference for the tracking environment as shown in the following code example:
ITrackingEnvironment trackingEnv=new TrackingEnvironmentClass();
[VB.NET] Dim trackingEnv As ITrackingEnvironment
trackingEnv=New TrackingEnvironmentClass()
- Initialize the tracking environment as shown in the following code example:
trackingEnv.Initialize(ref mapObj);
[VB.NET] trackingEnv.Initialize(mapObj)
- Set the temporal mode to real time as shown in the following code example:
trackingEnv.DefaultTemporalReference.TemporalMode=enumTemporalMode.enumRealTime;
[VB.NET] trackingEnv.DefaultTemporalReference.TemporalMode=enumTemporalMode.enumRealTime
- Set the update mode to automatic. This means that the visible time stamp and the update of the display are controlled by the tracking service. See the following code example:
trackingEnv.DisplayManager.ManualUpdate=false;
[VB.NET] trackingEnv.DisplayManager.ManualUpdate=False
- Set the refresh rate to one second as shown in the following code example:
trackingEnv.DisplayManager.RefreshRate=1.0;
[VB.NET] trackingEnv.DisplayManager.RefreshRate=1.0
Creating the temporal layer and hooking it with the service
In this section, you will create a new instance of a temporal layer, assign the service and the renderer to the layer, then add the layer to the map.
-
Create the temporal layer as shown in the following code example:
ITemporalLayer temporalLayer=new TemporalFeatureLayerClass();
[VB.NET] Dim temporalLayer As ITemporalLayer
temporalLayer=New TemporalFeatureLayerClass()
- Assign the tracking service to the temporal layer. Since you are keeping the service as a feature class, assign it to the layer as another feature layer. See the following code example:
((IFeatureLayer)temporalLayer).FeatureClass=featureClass
[VB.NET] Dim featureLayer As IFeatureLayer
featureLayer=temporalLayer
featureLayer.FeatureClass=featureClass
- Set the renderer for the layer as shown in the following code example:
temporalLayer.Renderer=temporalRenderer as IFeatureRenderer;
[VB.NET] temporalLayer.Renderer=temporalRenderer
- Set the layer so that it only displays the last item's location to prevent it from drawing a trail of previous locations. See the following code example:
temporalLayer.DisplayOnlyLastKnownEvent=true;
[VB.NET] temporalLayer.DisplayOnlyLastKnownEvent=True
- Add the layer to the map as shown in the following code example:
m_hookHelper.FocusMap.AddLayer((ILayer)temporalLayer);
[VB.NET] My.ArcMap.Document.FocusMap.AddLayer(temporalLayer)
See Also:
Interacting with singleton objectsSamples:
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine: Tracking Analyst |
ArcGIS for Desktop Basic: Tracking Analyst | ArcGIS for Desktop Basic: Tracking Analyst |
ArcGIS for Desktop Standard: Tracking Analyst | ArcGIS for Desktop Standard: Tracking Analyst |
ArcGIS for Desktop Advanced: Tracking Analyst | ArcGIS for Desktop Advanced: Tracking Analyst |