View on GitHub Sample viewer app

Create a custom dynamic entity data source and display it using a dynamic entity layer.

AddCustomDynamicEntityDataSource

Use case

Developers can create a custom DynamicEntityDataSource to be able to visualize data from a variety of different feeds as dynamic entities using a DynamicEntityLayer. An example of this is in a mobile situational awareness app, where a custom DynamicEntityDataSource can be used to connect to peer-to-peer feeds in order to visualize real-time location tracks from teammates in the field.

How to use the sample

Run the sample to view the map and the dynamic entity layer displaying the latest observation from the custom data source.

How it works

Configure the custom data source:

  1. Create a custom data source implementation of a DynamicEntityDataSource.
  2. Override onLoadAsync() to specify the DynamicEntityDataSourceInfo for a given unique entity ID field and a list of Field objects matching the fields in the data source.
  3. Override onConnectAsync() to begin processing observations from the custom data source.
  4. Loop through the observations and deserialize each observation into a Geometry object and a Map<String, Object> containing the attributes.
  5. Use DynamicEntityDataSource.addObservation(geometry, attributes) to add each observation to the custom data source.

Configure the map view:

  1. Create a DynamicEntityLayer using the custom data source implementation.
  2. Update values in the layer’s TrackDisplayProperties to customize the layer’s appearance.
  3. Set up the layer’s LabelDefinitions to display labels for each dynamic entity.

Relevant API

  • DynamicEntity
  • DynamicEntityDataSource
  • DynamicEntityLayer
  • LabelDefinition
  • TrackDisplayProperties

About the data

This sample uses a .json file containing observations of marine vessels in the Pacific North West hosted on ArcGIS Online.

Additional information

In this sample, we iterate through features in a GeoJSON file to mimic messages coming from a real-time feed. You can create a custom dynamic entity data source to process any data that contains observations which can be translated into Geometry objects with associated Map<String, Object> attributes.

Tags

data, dynamic, entity, label, labeling, live, real-time, stream, track

Sample Code

module-info.java module-info.java AddCustomDynamicEntityDataSourceSample.java SimulatedDataSource.java
/*
* Copyright 2023 Esri.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module com.esri.samples.add_custom_dynamic_entity_data_source {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
// require JavaFX modules that the application uses
requires javafx.graphics;
requires javafx.controls;
// require Gson for parsing json data
requires com.google.gson;
exports com.esri.samples.add_custom_dynamic_entity_data_source;
}