require(["esri/layers/support/StreamConnection"], (StreamConnection) => { /* code goes here */ });
import StreamConnection from "@arcgis/core/layers/support/StreamConnection.js";
esri/layers/support/StreamConnection
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
// get layer's connection configurations
const parameters = layer.createConnectionParameters();
// set the spatial reference of the service geometries
parameters.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 view
connection.on("data-received", (feature) => {
const graphic = Graphic.fromJSON(feature);
graphic.symbol = myPointSymbol;
view.graphics.push(graphic);
});
// close the connection when it is not needed anymore
connection.destroy();
Property Overview
Name | Type | Summary | Object |
---|---|---|---|
The error that explains an unsuccessful attempt to connect to the stream service or an unexpected disconnection from the stream service. | StreamConnection | ||
The status of the Web Socket connection with the stream service. | StreamConnection |
Property Details
-
connectionError
connectionError Errorreadonly
-
The error that explains an unsuccessful attempt to connect to the stream service or an unexpected disconnection from the stream service.
-
connectionStatus
connectionStatus Stringreadonly
-
The status of the Web Socket connection with the stream service. This property can be watched to see if the connection is lost unexpectedly.
Possible Values:"connected" |"disconnected"
Method Overview
Name | Return Type | Summary | Object |
---|---|---|---|
Destroys the existing connection instance to the stream service. | StreamConnection |
Method Details
Event Overview
Name | Type | Summary | Object |
---|---|---|---|
|
{attributes: Object,geometry: Object} |
Fires when the stream connection receives data. |
StreamConnection |
Event Details
-
Fires when the stream connection receives data. The event object contains the message properties received from the stream service.