Skip to content
import TrackViewModel from "@arcgis/core/widgets/Track/TrackViewModel.js";
Inheritance:
TrackViewModelGeolocationPositioningAccessor
Since
ArcGIS Maps SDK for JavaScript 4.0

Provides the logic for the Track component and Track widget, which animates the View to the user's location when clicked and tracks it as the location is updated.

The Track widget is only available in secure contexts, such as HTTPS. Note that localhost is considered "potentially secure" and can be used for easy testing in browsers that support Window.isSecureContext.

For additional information regarding this, visit the ArcGIS blog, Increased web API security in Google Chrome.

See also
Example
let trackWidget = new Track({
viewModel: { // autocasts as new TrackViewModel()
view: view, // attaches the Track to the view
}
};

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor
Since
ArcGIS Maps SDK for JavaScript 4.7

The name of the class. The declared class name is formatted as esri.folder.className.

error

Property
Type
GeolocationPositionError | Error | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.29

Error that caused the last track-error event to fire.

Example
if(track.viewModel.state === 'error')
console.error(track.viewModel.error);

geolocationOptions

inherited Property
Type
PositionOptions | null | undefined
Inherited from: GeolocationPositioning

An object used for setting optional position parameters. Refer to the Geolocation API Specification for details on using these parameters.

Example
const track = new Track({
view: view,
// Set optional position parameters
geolocationOptions: {
maximumAge: 0,
timeout: 15000,
enableHighAccuracy: true
}
});

goToLocationEnabled

inherited Property
Type
boolean
Inherited from: GeolocationPositioning

Indicates whether to navigate the view to the position and scale of the geolocated result.

Default value
true

goToOverride

inherited Property
Type
GoToOverride | null | undefined
Inherited from: GoTo
Since
ArcGIS Maps SDK for JavaScript 4.8

This function provides the ability to override either the MapView goTo() or SceneView goTo() methods.

See also
Example
// The following snippet uses Search but can be applied to any
// widgets that support the goToOverride property.
search.goToOverride = function(view, goToParams) {
goToParams.options = {
duration: updatedDuration
};
return view.goTo(goToParams.target, goToParams.options);
};

graphic

autocast inherited Property
Type
Graphic
Inherited from: GeolocationPositioning

The graphic used to show the user's location on the map.

Example
const trackWidget = new Track({
// Assign the track widget to a view
view: view,
// Overwrite the default symbol used for the
// graphic placed at the location of the user
graphic: new Graphic ({
symbol: {
// autocasts as new SimpleMarkerSymbol()
type: "simple-marker",
size: "12px",
color: "blue",
// autocasts as new SimpleLineSymbol()
outline: {
color: "#efefef",
width: "1.5px"
}
}
})
});

positionFilterFunction

Property
Type
PositionFilterFunction | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.27

A function that is used as an expression to evaluate geolocation points, and returns a boolean value. If the function returns true, the widget will draw a graphic and navigate to the position. The widget will ignore false values and not draw a graphic and not navigate to the position.

Example use cases include smoothing out geolocation anomalies and geofencing.

Example
// Exclude locations that full outside an extent.
track.viewModel.positionFilterFunction = (value) => {
const { longitude, latitude } = value.position.coords;
const myLocation = new Point({ longitude, latitude });
const geofenceExtent = new Extent({
// whatever
});
return geometryEngine.within(myLocation, geofenceExtent);
};

rotationEnabled

Property
Type
boolean
Since
ArcGIS Maps SDK for JavaScript 4.33

Indicates whether the component will automatically rotate to the device heading based on the Geolocation APIs GeolocationCoordinates.heading property. The map will not rotate if the speed is 0, or if the device is unable to provide heading information.

Default value
true

scale

inherited Property
Type
number | null | undefined
Inherited from: GeolocationPositioning
Since
ArcGIS Maps SDK for JavaScript 4.7

Indicates the scale to set on the view when navigating to the position of the geolocated result, after a location is returned.

By default, the view will navigate to a scale of 2500 for 3D and 4514 for 2D. To override the default in 2D, set the scale property and also set snapToZoom to false. For 2D views the value should be within the effectiveMinScale and effectiveMaxScale.

state

readonly Property
Type
TrackViewModelState

The current state of the widget.

Default value
"disabled"

tracking

readonly Property
Type
boolean

Indicates whether new positions are being watched.

Default value
false

view

inherited Property
Type
MapViewOrSceneView | null | undefined
Inherited from: GeolocationPositioning

The view associated with the widget.

Methods

MethodSignatureClass
emit
inherited
emit<Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
hasEventListener
inherited
hasEventListener<Type extends EventNames<this>>(type: Type): boolean
on
inherited
on<Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
start(): void
stop(): void

emit

inherited Method
Signature
emit <Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin
Since
ArcGIS Maps SDK for JavaScript 4.5

Emits an event on the instance. This method should only be used when creating subclasses of this class.

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

event
this["@eventTypes"][Type]

The event payload.

Returns
boolean

true if a listener was notified

hasEventListener

inherited Method
Signature
hasEventListener <Type extends EventNames<this>>(type: Type): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

Indicates whether there is an event listener on the instance that matches the provided event name.

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

Returns
boolean

Returns true if the class supports the input event.

on

inherited Method
Signature
on <Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

Registers an event handler on the instance. Call this method to hook an event with a listener.

Parameters
ParameterTypeDescriptionRequired
type
Type

An event or an array of events to listen for.

listener
EventedCallback<this["@eventTypes"][Type]>

The function to call when the event fires.

Returns
ResourceHandle

Returns an event handler with a remove() method that should be called to stop listening for the event(s).

PropertyTypeDescription
removeFunctionWhen called, removes the listener from the event.
Example
view.on("click", function(event){
// event is the event handle returned after the event fires.
console.log(event.mapPoint);
});

start

Method
Signature
start (): void

When executed, tracking starts at the user's location.

Returns
void

stop

Method
Signature
stop (): void

Stops tracking the user's location when executed.

Returns
void

Events

track

Event

Fires after the Track.start() method is called and a position is found.

bubbles composed cancelable
Example
track.on("track", ({ position }) => {
const { longitude, latitude } = position.coords;
console.log("Track", `${longitude.toFixed(4)}, ${latitude.toFixed(4)}`);
});

track-error

Event

Fires after the Track.start() method is called and an error is returned.

bubbles composed cancelable

Type definitions

TrackViewModelState

Type definition
Type
"error" | "disabled" | "ready" | "waiting" | "tracking" | "feature-unsupported"

TrackViewModelTrackEvent

Type definition

position

Property
Type
GeolocationPosition

Geolocation coordinates returned from the Geolocation API.

TrackViewModelTrackErrorEvent

Type definition

error

Property
Type
GeolocationPositionError | Error

The Error object returned if an error occurred while tracking.