Add custom dynamic entity data source

View on GitHubSample viewer app

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

Image of add custom dynamic entity data source

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. Tap on a dynamic entity to view its attributes in LogCat.

How it works

Configure the custom data source:

  1. Create a custom data source using a CustomDynamicEntityDataSource.EntityFeedProvider.
  2. Override feed with a SharedFlow<CustomDynamicEntityDataSource.FeedEvent>.
  3. Override onLoad() to specify the DynamicEntityDataSourceInfo for a given unique entity ID field and a list of Field objects matching the fields in the data source.
  4. Override OnConnect() to begin asynchronously processing observations from the custom data source.
  5. Loop through the observations and deserialize each observation into a Point object and a Map<String, Any?> containing the attributes.
  6. Emit an observation in the custom data source feed with CustomDynamicEntityDataSource.FeedEvent.NewObservation(point, attributes).

Configure the MapView:

  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.
  4. Use MapView.identify(...) to display a dynamic entity's attributes in a Callout.

Relevant API

  • CustomDynamicEntityDataSource.EntityFeedProvider
  • 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 map points (com.arcgismaps.geometry.Point objects) with associated Map<String, Any?> attributes.

This sample uses the GeoViewCompose Toolkit module to implement a Composable MapView, which supports the use of Callouts.

Tags

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

Sample Code

DownloadActivity.ktDownloadActivity.ktMainActivity.ktCustomEntityFeedProvider.ktMapViewModel.ktMainScreen.kt
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* Copyright 2024 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.
 *
 */

package com.esri.arcgismaps.sample.addcustomdynamicentitydatasource

import android.content.Intent
import android.os.Bundle
import com.esri.arcgismaps.sample.sampleslib.DownloaderActivity

class DownloadActivity : DownloaderActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        downloadAndStartSample(
            Intent(this, MainActivity::class.java),
            // get the app name of the sample
            getString(R.string.add_custom_dynamic_entity_data_source_app_name),
            // ArcGIS Portal item containing the json file of observations of marine vessels in
            // the Pacific North West
            listOf(
                "https://www.arcgis.com/home/item.html?id=a8a942c228af4fac96baa78ad60f511f"
            )
        )
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.