Client-side StreamLayer
This sample shows how to add a client-side StreamLayer to your map and start streaming features to it by calling its sendMessageToClient() method.
Since the StreamLayer requires a schema, several properties need to be set when creating a layer purely on the client-side. The geometry type of the features must be indicated by setting the geometryType property. The StreamLayer requires an objectId field along with an array of field objects, providing the schema of each field. Each field schema in the fields array should match the feature attributes being streamed to the layer to ensure data accuracy. The StreamLayer also requires the trackIdField to be set in the layer's timeInfo property and the field schema must exist in the fields array.
The send
can be called once the layer is successfully initialized and added to the map. There are three predefined client-side only message types you can send to the layer: features
, delete
, and clear
. This sample uses features
message to instruct the layer to start streaming features. The following table explains this message.
Message type | Message parameters | Message explanation |
---|---|---|
features | features: | Adds features from features array to a stream layer on client. Features are esri Feature json object. |
How it works
When the application starts, a client-side StreamLayer is initialized with the following parameters:
Then you can start streaming features to the layer by calling its send
method with features
message as shown below: