import DirectionalPadViewModel from "@arcgis/core/widgets/DirectionalPad/DirectionalPadViewModel.js";const DirectionalPadViewModel = await $arcgis.import("@arcgis/core/widgets/DirectionalPad/DirectionalPadViewModel.js");- Inheritance:
- DirectionalPadViewModel→
Accessor
- Since
- ArcGIS Maps SDK for JavaScript 4.29
Provides the logic for the DirectionalPad widget and component.
- See also
DirectionalPad widget - Deprecated since 4.32. Use the DirectionalPad component instead.
Programming patterns: Widget viewModel pattern
The DirectionalPad widget is not supported in 3d.
Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
Properties
| Property | Type | Class |
|---|---|---|
angle readonly | | |
declaredClass readonly inherited | ||
| | ||
goToOverride inherited | ||
| | ||
state readonly | | |
| |
angle
- Type
- DirectionalPadAngle | null | undefined
The closest angle that matches the current mouse position
relative to the widget's center. There are eight possible angles, -45, 0, 45, -90, 90, -135, 180, and 135. If the widget is not in motion, the value is undefined.
disabled
- Type
- boolean
Indicates whether interaction is allowed on the widget. When true, this property sets the widget to a disabled state to stop user interaction.
- Default value
- false
goToOverride
- Type
- GoToOverride | null | undefined
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);}; rotation
- Type
- number
The angle of rotation of the map. Ranges from 0 to 360
- Default value
- 0
Example
reactiveUtils.watch( ()=>directionalPadViewModel.rotation, (newAngle,oldAngle)=> console.log({ newAngle, oldAngle }));Methods
| Method | Signature | Class |
|---|---|---|
beginFollowingPointer(pointerLocation: Vector & Partial<Pick<PointerEvent, "target">>, widgetCenter: Vector): void | | |
emit inherited | emit<Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean | |
hasEventListener inherited | hasEventListener<Type extends EventNames<this>>(type: Type): boolean | |
moveOnce(angle: number): void | | |
on inherited | on<Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle |
beginFollowingPointer
- Signature
-
beginFollowingPointer (pointerLocation: Vector & Partial<Pick<PointerEvent, "target">>, widgetCenter: Vector): void
Starts movement in the correct direction according to pointer location, and listens for pointer move (to change direction) or release (to stop movement)
This method should be called in response to pointerdown event on a button
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| pointerLocation | Vector & Partial<Pick<PointerEvent, "target">> | Current pointer location | |
| widgetCenter | The center of the DirectionalPad widget | |
- Returns
- void
Example
moveLeftButton.addEventListener("pointerDown", (event) => { const { x, y, width, height } = buttonsContainer.getBoundingClientRect(); const widgetCenter = { x: x + width / 2, y: y + height / 2 }; directionalPadViewModel.beginFollowingPointer(event, widgetCenter);}); emit
- Signature
-
emit <Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
- Type parameters
- <Type extends EventNames<this>>
Emits an event on the instance. This method should only be used when creating subclasses of this class.
hasEventListener
- Signature
-
hasEventListener <Type extends EventNames<this>>(type: Type): boolean
- Type parameters
- <Type extends EventNames<this>>
Indicates whether there is an event listener on the instance that matches the provided event name.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| type | Type | The name of the event. | |
- Returns
- boolean
Returns true if the class supports the input event.
on
- Signature
-
on <Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
- Type parameters
- <Type extends EventNames<this>>
Registers an event handler on the instance. Call this method to hook an event with a listener.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| 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).Property Type Description remove Function When 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);});