import type { Viewport2DMixin } from "@arcgis/core/views/Viewport2DMixin.js";- Since
- ArcGIS Maps SDK for JavaScript 5.0
Mixin that adds event handling capabilities to View2D and VideoView.
Methods
on
- 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
- Returns
- ResourceHandle
Returns an event handler with a
remove()method that can be called to stop listening for the event.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);});// 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
- Signature
-
on <Type extends EventNames<this>>(type: Type, modifiers: string[], listener: (event: this["@eventTypes"][Type]) => void): ResourceHandle
- Type parameters
- <Type extends EventNames<this>>
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| 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: | |
| listener | 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.Property Type Description remove Function When called, removes the listener from the event.
Events
| Name | Type |
|---|---|
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited | |
| inherited |
analysis-view-create
analysis-view-create: CustomEvent<AnalysisViewCreateEvent> Fires when the view for an Analysis is created.
analysis-view-create-error
analysis-view-create-error: CustomEvent<AnalysisViewCreateErrorEvent> Fires when an error occurs during the creation of an Analysis after an analysis is added to the view.
analysis-view-destroy
analysis-view-destroy: CustomEvent<AnalysisViewDestroyEvent> Fires after an analysis view is destroyed.
blur
blur: CustomEvent<ViewBlurEvent> Fires when browser focus is moved away from the view.
click
click: CustomEvent<ClickEvent> 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.
- Examples
- view.on("click", function(event){// event is the event object returned after the event fires// Prints the map coordinates of the clicked locationconsole.log(event.mapPoint);});// Set up a click event handler and retrieve the screen pointview.on("click", function(event) {// the hitTest() checks to see if any graphics in the view// intersect the given screen x, y coordinatesview.hitTest(event).then(getGraphics);});view.on("click", function(event) {// you must overwrite default click-for-popup// behavior to display your own popupview.popupEnabled = false;// Get the coordinates of the click on the viewlet 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 locationtitle: "Reverse geocode: [" + lon + ", " + lat + "]",location: event.mapPoint // Set the location of the popup to the clicked locationcontent: "This is a point of interest" // content displayed in the popup});});
double-click
double-click: CustomEvent<DoubleClickEvent> Fires after double-clicking on the view.
- 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
double-tap-drag: CustomEvent<DoubleTapDragEvent> Fires while the pointer is drag following a double-tap gesture on the view.
- 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
drag: CustomEvent<DragEvent> Fires during a pointer drag on the view.
- Example
- view.on("drag", function(event){// Print out the current state of the// drag event.console.log("drag state", event.action);});
focus
focus: CustomEvent<ViewFocusEvent> Fires when browser focus is on the view.
hold
hold: CustomEvent<HoldEvent> Fires after holding either a mouse button or a single finger on the view for a short amount of time.
- 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
immediate-click: CustomEvent<ImmediateClickEvent> 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.
- Example
- // Set up an immediate-click event handler and retrieve the screen pointview.on("immediate-click", function(event) {// the hitTest() checks to see if any graphics in the view// intersect the given screen x, y coordinatesview.hitTest(event).then(getGraphics);});
immediate-double-click
immediate-double-click: CustomEvent<ImmediateDoubleClickEvent> 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.
key-down
key-down: CustomEvent<KeyDownEvent> Fires after a keyboard key is pressed.
- Example
- // Zoom in when user clicks on "a" button// Zoom out when user clicks on "s" buttonview.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
key-up: CustomEvent<KeyUpEvent> Fires after a keyboard key is released.
layerview-create
layerview-create: CustomEvent<LayerViewCreateEvent> Fires after each layer in the map has a corresponding LayerView created and rendered in the view.
- See also
- 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 viewif (event.layer.id === "satellite") {// The LayerView for the desired layerconsole.log(event.layerView);}});
layerview-create-error
layerview-create-error: CustomEvent<LayerViewCreateErrorEvent> Fires when an error occurs during the creation of a LayerView after a layer has been added to the map.
- See also
- Example
- // This function fires each time an error occurs during the creation of a layerviewview.on("layerview-create-error", function(event) {console.error("LayerView failed to create for layer with the id: ", event.layer.id);});
layerview-destroy
layerview-destroy: CustomEvent<LayerViewDestroyEvent> 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.
mouse-wheel
mouse-wheel: CustomEvent<ViewMouseWheelEvent> Fires when a wheel button of a pointing device (typically a mouse) is scrolled on the view.
- 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
pointer-down: CustomEvent<PointerDownEvent> Fires after a mouse button is pressed, or a finger touches the display.
pointer-enter
pointer-enter: CustomEvent<PointerEnterEvent> Fires after a mouse cursor enters the view, or a display touch begins.
pointer-leave
pointer-leave: CustomEvent<PointerLeaveEvent> Fires after a mouse cursor leaves the view, or a display touch ends.
pointer-move
pointer-move: CustomEvent<PointerMoveEvent> Fires after the mouse or a finger on the display moves.
- 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
pointer-up: CustomEvent<PointerUpEvent> Fires after a mouse button is released, or a display touch ends.
resize
resize: CustomEvent<ViewResizeEvent> Fires when the view's size changes.
vertical-two-finger-drag
vertical-two-finger-drag: CustomEvent<VerticalTwoFingerDragEvent> Fires while the two pointers are dragged on the view.
- Example
- view.on("vertical-two-finger-drag", (event) => {// Display the distance moved vertically from the drag origin.console.log("y distance:", event.y);});