Skip to content
Types
import type { Viewport2DMixin } from "@arcgis/core/views/Viewport2DMixin.js";
Subclasses:
View2D, VideoView
Since
ArcGIS Maps SDK for JavaScript 5.0

Mixin that adds event handling capabilities to View2D and VideoView.

Methods

MethodSignatureClass
on
on<Type extends EventNames<this>>(type: Type, listener: (event: this["@eventTypes"][Type]) => void): ResourceHandle
on
on<Type extends EventNames<this>>(type: Type, modifiers: string[], listener: (event: this["@eventTypes"][Type]) => void): ResourceHandle

on

Method
Signature
on <Type extends EventNames<this>>(type: Type, listener: (event: this["@eventTypes"][Type]) => void): ResourceHandle
Type parameters
<Type extends EventNames<this>>

Registers an event handler on the instance. Call this method to hook an event with a listener. See the Events summary table for a list of listened events.

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event or events to listen for.

listener
(event: this["@eventTypes"][Type]) => void

The function to call when the event is fired, if modifiers were specified.

Returns
ResourceHandle

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

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);
});
// Fires `pointer-move` event when user clicks on "Shift"
// key and moves the pointer on the view.
view.on("pointer-move", ["Shift"], function(event){
let point = view2d.toMap({x: event.x, y: event.y});
bufferPoint(point);
});

on

Method
Signature
on <Type extends EventNames<this>>(type: Type, modifiers: string[], listener: (event: this["@eventTypes"][Type]) => void): ResourceHandle
Type parameters
<Type extends EventNames<this>>
Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event or events to listen for.

modifiers
string[]

Additional modifier keys to filter events. Please see Key Values for possible values. All the standard key values are supported. Alternatively, if no modifiers are required, the function will call when the event fires.

The following events don't support modifier keys: blur, focus, layerview-create, layerview-destroy, resize.

listener
(event: this["@eventTypes"][Type]) => void

The function to call when the event is fired, if modifiers were specified.

Returns
ResourceHandle

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

PropertyTypeDescription
removeFunctionWhen called, removes the listener from the event.

Events

analysis-view-create

inherited Event
analysis-view-create: CustomEvent<AnalysisViewCreateEvent>
Inherited from: AnalysisViewEvents

Fires when the view for an Analysis is created.

See also
bubbles composed cancelable

analysis-view-create-error

inherited Event
analysis-view-create-error: CustomEvent<AnalysisViewCreateErrorEvent>
Inherited from: AnalysisViewEvents

Fires when an error occurs during the creation of an Analysis after an analysis is added to the view.

See also
bubbles composed cancelable

analysis-view-destroy

inherited Event
analysis-view-destroy: CustomEvent<AnalysisViewDestroyEvent>
Inherited from: AnalysisViewEvents

Fires after an analysis view is destroyed.

bubbles composed cancelable

blur

inherited Event
Inherited from: ViewEventTypes

Fires when browser focus is moved away from the view.

bubbles composed cancelable

click

inherited Event
Inherited from: ViewEventTypes

Fires after a user clicks on the view. This event emits slightly slower than an View.@immediate-click event to make sure that a View.@double-click event isn't triggered instead. The View.@immediate-click event can be used for responding to a click event without delay.

See also
bubbles composed cancelable
Examples
view.on("click", function(event){
// event is the event object returned after the event fires
// Prints the map coordinates of the clicked location
console.log(event.mapPoint);
});
// Set up a click event handler and retrieve the screen point
view.on("click", function(event) {
// the hitTest() checks to see if any graphics in the view
// intersect the given screen x, y coordinates
view.hitTest(event)
.then(getGraphics);
});
view.on("click", function(event) {
// you must overwrite default click-for-popup
// behavior to display your own popup
view.popupEnabled = false;
// Get the coordinates of the click on the view
let lat = Math.round(event.mapPoint.latitude * 1000) / 1000;
let lon = Math.round(event.mapPoint.longitude * 1000) / 1000;
view.popup.open({
// Set the popup's title to the coordinates of the location
title: "Reverse geocode: [" + lon + ", " + lat + "]",
location: event.mapPoint // Set the location of the popup to the clicked location
content: "This is a point of interest" // content displayed in the popup
});
});

double-click

inherited Event
double-click: CustomEvent<DoubleClickEvent>
Inherited from: ViewEventTypes

Fires after double-clicking on the view.

bubbles composed cancelable
Example
view.on("double-click", function(event) {
// The event object contains the mapPoint and the screen coordinates of the location
// that was clicked.
console.log("screen point", event.x, event.y);
console.log("map point", event.mapPoint);
});

double-tap-drag

inherited Event
double-tap-drag: CustomEvent<DoubleTapDragEvent>
Inherited from: ViewEventTypes

Fires while the pointer is drag following a double-tap gesture on the view.

bubbles composed cancelable
Example
view.on("double-tap-drag", (event) => {
// Display the distance moved from the drag origin.
console.log("x distance:", event.x, "y distance:", event.y);
});

drag

inherited Event
Inherited from: ViewEventTypes

Fires during a pointer drag on the view.

bubbles composed cancelable
Example
view.on("drag", function(event){
// Print out the current state of the
// drag event.
console.log("drag state", event.action);
});

focus

inherited Event
Inherited from: ViewEventTypes

Fires when browser focus is on the view.

bubbles composed cancelable

hold

inherited Event
Inherited from: ViewEventTypes

Fires after holding either a mouse button or a single finger on the view for a short amount of time.

bubbles composed cancelable
Example
view.on("hold", function(event) {
// The event object contains the mapPoint and the screen coordinates of the location
// that was clicked.
console.log("hold at screen point", event.x, event.y);
console.log("hold at map point", event.mapPoint);
});

immediate-click

inherited Event
immediate-click: CustomEvent<ImmediateClickEvent>
Inherited from: ViewEventTypes

Fires right after a user clicks on the view. In contrast to the View.@click event, the immediate-click event is emitted as soon as the user clicks on the view, and is not inhibited by a View.@double-click event. This event is useful for interactive experiences that require feedback without delay.

bubbles composed cancelable
Example
// Set up an immediate-click event handler and retrieve the screen point
view.on("immediate-click", function(event) {
// the hitTest() checks to see if any graphics in the view
// intersect the given screen x, y coordinates
view.hitTest(event)
.then(getGraphics);
});

immediate-double-click

inherited Event
immediate-double-click: CustomEvent<ImmediateDoubleClickEvent>
Inherited from: ViewEventTypes

Is emitted after two consecutive View.@immediate-click events. In contrast to View.@double-click, an immediate-double-click cannot be prevented by use of stopPropagation on the View.@immediate-click event and can therefore be used to react to double-clicking independently of usage of the View.@immediate-click event.

bubbles composed cancelable

key-down

inherited Event
Inherited from: ViewEventTypes

Fires after a keyboard key is pressed.

bubbles composed cancelable
Example
// Zoom in when user clicks on "a" button
// Zoom out when user clicks on "s" button
view.on("key-down", function(event){
console.log("key-down", event);
if (event.key === "a"){
let zm = view.zoom + 1;
view.goTo({
target: view.center,
zoom: zm
});
}
else if(event.key == "s"){
let zm = view.zoom - 1;
view.goTo({
target: view.center,
zoom: zm
});
}
});

key-up

inherited Event
Inherited from: ViewEventTypes

Fires after a keyboard key is released.

bubbles composed cancelable

layerview-create

inherited Event
layerview-create: CustomEvent<LayerViewCreateEvent>
Inherited from: ViewBaseEventTypes

Fires after each layer in the map has a corresponding LayerView created and rendered in the view.

See also
bubbles composed cancelable
Example
// This function fires each time a layer view is created for a layer in
// the map of the view.
view.on("layerview-create", function(event) {
// The event contains the layer and its layer view that has just been
// created. Here we check for the creation of a layer view for a layer with
// a specific id, and log the layer view
if (event.layer.id === "satellite") {
// The LayerView for the desired layer
console.log(event.layerView);
}
});

layerview-create-error

inherited Event
layerview-create-error: CustomEvent<LayerViewCreateErrorEvent>
Inherited from: ViewBaseEventTypes

Fires when an error occurs during the creation of a LayerView after a layer has been added to the map.

See also
bubbles composed cancelable
Example
// This function fires each time an error occurs during the creation of a layerview
view.on("layerview-create-error", function(event) {
console.error("LayerView failed to create for layer with the id: ", event.layer.id);
});

layerview-destroy

inherited Event
layerview-destroy: CustomEvent<LayerViewDestroyEvent>
Inherited from: ViewBaseEventTypes

Fires after a LayerView is destroyed and is no longer rendered in the view. This happens for example when a layer is removed from the map of the view.

bubbles composed cancelable

mouse-wheel

inherited Event
Inherited from: ViewEventTypes

Fires when a wheel button of a pointing device (typically a mouse) is scrolled on the view.

bubbles composed cancelable
Example
view.on("mouse-wheel", function(event){
// deltaY value is positive when wheel is scrolled up
// and it is negative when wheel is scrolled down.
console.log(event.deltaY);
});

pointer-down

inherited Event
pointer-down: CustomEvent<PointerDownEvent>
Inherited from: ViewEventTypes

Fires after a mouse button is pressed, or a finger touches the display.

bubbles composed cancelable

pointer-enter

inherited Event
pointer-enter: CustomEvent<PointerEnterEvent>
Inherited from: ViewEventTypes

Fires after a mouse cursor enters the view, or a display touch begins.

bubbles composed cancelable

pointer-leave

inherited Event
pointer-leave: CustomEvent<PointerLeaveEvent>
Inherited from: ViewEventTypes

Fires after a mouse cursor leaves the view, or a display touch ends.

bubbles composed cancelable

pointer-move

inherited Event
pointer-move: CustomEvent<PointerMoveEvent>
Inherited from: ViewEventTypes

Fires after the mouse or a finger on the display moves.

bubbles composed cancelable
Example
// Fires `pointer-move` event when user clicks on "Shift"
// key and moves the pointer on the view.
view.on('pointer-move', ["Shift"], function(event){
let point = view.toMap({x: event.x, y: event.y});
bufferPoint(point);
});

pointer-up

inherited Event
Inherited from: ViewEventTypes

Fires after a mouse button is released, or a display touch ends.

bubbles composed cancelable

resize

inherited Event
Inherited from: ViewBaseEventTypes

Fires when the view's size changes.

See also
bubbles composed cancelable

vertical-two-finger-drag

inherited Event
vertical-two-finger-drag: CustomEvent<VerticalTwoFingerDragEvent>
Inherited from: ViewEventTypes

Fires while the two pointers are dragged on the view.

bubbles composed cancelable
Example
view.on("vertical-two-finger-drag", (event) => {
// Display the distance moved vertically from the drag origin.
console.log("y distance:", event.y);
});

Type definitions