import StreamConnection from "@arcgis/core/layers/support/StreamConnection.js";const StreamConnection = await $arcgis.import("@arcgis/core/layers/support/StreamConnection.js");- Inheritance:
- StreamConnection→
Accessor
- Since
- ArcGIS Maps SDK for JavaScript 4.25
A web socket connection to a stream service. The connection to the stream service can be established by calling StreamLayer's connect() method.
- See also
Example
// get layer's connection configurationsconst parameters = layer.createConnectionParameters();
// set the spatial reference of the service geometriesparameters.spatialReference = new SpatialReference({ wkid: 2154});
const connection = await layer.connect(parameters);
// listen to date-received event once the connection is established// create a graphic from the JSON object returned and add them to viewconnection.on("data-received", (feature) => { const graphic = Graphic.fromJSON(feature); graphic.symbol = myPointSymbol; view.graphics.push(graphic);});
// close the connection when it is not needed anymoreconnection.destroy();Properties
| Property | Type | Class |
|---|---|---|
connectionError readonly | | |
connectionStatus readonly | | |
declaredClass readonly inherited |
Methods
| Method | Signature | Class |
|---|---|---|
destroy(): 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 | |
on inherited | on<Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle |
destroy
- Signature
-
destroy (): void
Destroys the existing connection instance to the stream service.
- Returns
- void
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);});Events
| Name | Type |
|---|---|
data-received
data-received: CustomEvent<Feature> Fires when the stream connection receives data. The event object contains the message properties received from the stream service.
Type definitions
FeatureMessage
A message to add Features to a StreamLayer on the client by calling its sendMessageToClient() method. An array of JSON Features that can be added to a StreamLayer on the client by calling its sendMessageToClient() method. Each feature is an esri Feature JSON object as defined in the Feature object specification.
DeleteMessage
A message to delete features from a StreamLayer on the client by calling its sendMessageToClient() method.
trackIds
- Type
- number[]
An array of track IDs identifying the features to delete from a StreamLayer on the client.
objectIds
- Type
- ObjectId[]
An array of object IDs identifying the features to delete from a StreamLayer on the client.
ClearMessage
A message to clear all features from a StreamLayer on the client by calling its sendMessageToClient() method.
Message
The message to send to a StreamLayer on the client by calling its sendMessageToClient() method.
- Type
- FeatureMessage | DeleteMessage | ClearMessage | object