Select to view content in your preferred language

GeoJSON Labels when Field is an Object

475
2
01-23-2023 11:44 AM
JulianDurantini
New Contributor II

All, 

I am trying to make a GeoJSON Layer from a source I do not control. I have a property in the GeoJSON (example below) that is actually an Object, not a string/number, etc, and I am attempting to display labels on the map, but can only access the root objects.

The labelingInfo is the class I am trying to get working properly. As you can see in the linked code pen example, I am unable to get the core_details (or hopefully, core_details.device_type) to display. Any help would be greatly appreciated! 

https://codepen.io/AIM_Atlas/pen/QWBQdLa?editors=0010

Spoiler
{
            "id""2105CAA6-951D-437C-AA6B-51CF4FB5F8DC",
            "type""Feature",
            "geometry": {
                "type""Point",
                "coordinates": [
                    -93.6943733,
                    41.8766766
                ]
            },
            "properties": {
                "core_details": {
                    "device_type""arrow-board",
                    "data_source_id""67899A97-0F3E-4683-B169-75C09C3B8F67",
                    "device_status""ok",
                    "update_date""2023-01-18T17:11:50Z",
                    "has_automatic_location"true,
                    "name""464",
                    "description""Arrow Panel, Display Down",
                    "serial_number""0xd0016e"
                },
                "pattern""blank",
                "is_in_transport_position"false,
                "custom": {
                    "isPublic"false,
                    "start_date""2022-10-04T00:59:31",
                    "location_details": {
                        "first_date""2023-01-18T07:38:00",
                        "update_date""2023-01-18T17:11:00"
                    }
                }
            }
        },

 

0 Kudos
2 Replies
ScottSurber
New Contributor

Did you ever figure this out? Is it possible. I have seen some GEOJson examples that have an object but not how to access it.

0 Kudos
BjornSvensson
Esri Regular Contributor

It's not possible to use fields inside an object directly.  However, you can use RequestInterceptor to flatten the field structure so that you can use the field data from inside field objects.

See for example https://codepen.io/bsvensson/pen/YzjaKQg?editors=0010 -- which uses RequestInterceptor to create new fields like "core_details__device_type".

BjornSvensson_0-1676501625620.png

cc: @JulianDurantini , @ScottSurber 

[Update] Looks like @UndralBatsukh already answered this in the original issue post -- https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geojson-layer-property-is-an-obje...

 

0 Kudos