featureLayerView: table-not-supported , table feature layer can't be displayed

1214
19
Jump to solution
10-16-2023 02:43 PM
Rohit_Venkat_GandhiMendadhala3
New Contributor III

I am trying to create a featureLayer from an XML response where lat,lon are stored in a featureArray. Instead of creating this as point graphic, I would like to create them as a pointFeatureLayer. However, when I do that I get an error saying table feature layer cant be displayed. I am creating the featureLayer from featuresArray by loading it as FeatureLayerCollection containing lat,lon and id.
Here is the snapshot of the code, I have used.  

 

   fetch(url,{
      method: 'GET',
      mode:'cors',
    }).then((response) => response.text())
    .then(str => new window.DOMParser().parseFromString(str, 'text/xml'))
    .then(async data => {
      const nodes = data.getElementsByTagName('tower');
      const featuresArray = [];
      for (const node of nodes){
          featuresArray.push({
            longitude: node.getAttribute('lng'),
            latitude: node.getAttribute('lat'),
            id:node.getAttribute('id')
          });
        }
      console.log(featuresArray);
      const featureLayer = await this.esri.FeatureLayer({
        source:featuresArray,
        objectIdField:'id',
        title:'TestLayer'
      });
      this.mvs.addToMap(featureLayer);

 

 

0 Kudos
19 Replies
ReneRubalcava
Frequent Contributor

Try to wrap your coords in Number(node.getAttribute('lng')), see if that helps. Although I think you would get a different error if the coords as string was an issue. What if you assign the y/x instead of lat/lon? 

If you had a small sample in codepen or similar to debug, would help.

0 Kudos
Rohit_Venkat_GandhiMendadhala3
New Contributor III

Well I  tried that, but it didnt work as well.

Here is sample of the featuresArray. 

Rohit_Venkat_GandhiMendadhala3_0-1697575841852.png

 

0 Kudos
Rohit_Venkat_GandhiMendadhala3
New Contributor III

No errors, code runs fine but layer doesnt display (points dont show up). The title displays in the map options, but points do not show up. Unfortunately, this is part of a big code base, cant upload the codebase

Rohit_Venkat_GandhiMendadhala3_0-1697576123380.png

 

Rohit_Venkat_GandhiMendadhala3_1-1697576181504.png

 

 

0 Kudos
JoelBennett
MVP Regular Contributor

It was good to convert the lat and long to numbers as Rene suggested, but I see in your screenshot the "id" values are still strings.  I've seen features not render in cases of duplicate or invalid objectid values, so you should probably convert those to integers as well, whether via Number or parseInt.  

0 Kudos
Rohit_Venkat_GandhiMendadhala3
New Contributor III

Well, I did that too

0 Kudos
Rohit_Venkat_GandhiMendadhala3
New Contributor III

Ok, I have just changed the id to a diff field and it loads just one point, that too with a mismatch of spatial reference. Any recommendations on this?

Rohit_Venkat_GandhiMendadhala3_0-1697577391888.png

 

0 Kudos
JoelBennett
MVP Regular Contributor

Is it really just one point, or a load of points stacked on one another?  If it is just one point, I would recommend autogenerating the objectID values as in a previous response.

As for the wrong location, it looks like it's treating your long/lat values as Web Mercator x/y values.  You may have to project the coordinates into Web Mercator, which is easily done with webMercatorUtils.lngLatToXY and then use "x" and "y" properties instead of "latitude" and "longitude".

0 Kudos
ReneRubalcava
Frequent Contributor

There could be some invalid data. If I add NaN values to coords, no points will display. The one valid point will display if you change to NaN to null though.

https://codepen.io/odoe/pen/ZEVdNBJ?editors=1000

You might need to filter the data to validate it before you create the layer.

0 Kudos
Rohit_Venkat_GandhiMendadhala3
New Contributor III

Yes, I expected that. So here is NaN value I found. 

Rohit_Venkat_GandhiMendadhala3_0-1697578025244.png

Is there a way to filter this down.. I did something like this.

featuresArray = featuresArray.filter((obj)=> !isNaN(obj.geometry.latitude || obj.geometry.longitude))

 

0 Kudos
ReneRubalcava
Frequent Contributor

Do the check on both values like !isNaN(obj.geometry.latitude) && !isNaN(obj.geometry.longitude)

0 Kudos