GeoJSON attributes are undefined

120
3
12-03-2022 01:36 PM
GeospatialEnterprise
New Contributor

I have a geojson url that I am able to see features on the map. I can use a definition query towards it, but I cannot access the values. The data comes in as undefined, though I can see the count of the features. The data comes in as: (36) [u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u] in the console. I'm not sure how to extract the values from a geojson link.

 

 

const query = geoJSONLayer.createQuery().set({
                        outFields: ["Category"],
                        returnGeometry: true
                    });

                    console.log(query)
                    const { features, fields } = await geoJSONLayer.queryFeatures(query);
                    console.log(features.attributes)
                    let sel = document.getElementById("sel").innerHTML = "";

                    // Populate dropdown with list of provinces
                    let dropdown = document.getElementById('locality-dropdown');
                    dropdown.length = 0;

                    let defaultOption = document.createElement('option');
                    defaultOption.text = 'Choose State/Province';

                    dropdown.add(defaultOption);
                    dropdown.selectedIndex = 0;

                    const url = mygeojsonurl;
                    fetch(url)
                        .then(
                            function (response) {
                                if (response.status !== 200) {
                                    console.warn('Looks like there was a problem. Status Code: ' +
                                        response.status);
                                    return;
                                }

                                // Examine the text in the response  
                                response.json().then(function (data) {
                                    let option;

let jsonobj = url;
jsonobj.length; i++) {
                                        dropdown.innerHTML = dropdown.innerHTML + '<option value="' + jsonobj[i]['id'] + '">' + jsonobj[i]['Category'] + '</option>'
                                    }

 

0 Kudos
3 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

Could you please share your geojson url so that I can take a look at what might be going on? If you cannot share then would you mind sharing json for one feature from your geojson file? 

0 Kudos
GeospatialEnterprise
New Contributor
0 Kudos
UndralBatsukh
Esri Regular Contributor

Hi there, 

Perhaps I misunderstood your question. GeoJSONLayer.queryFeatures runs successfully and returns attributes of the features as expected as you can see here in this codepen: https://codepen.io/U_B_U/pen/ExRMoGB?editors=1000

 

0 Kudos