Select to view content in your preferred language

Uncaught TypeError: Cannot read properties of null (reading '0')

2298
2
07-16-2023 04:48 AM
siefaqel
New Contributor
I am trying to query features from the feature layer view and add these features to a graphics layer to enable snapping on the features using the sketch view model I already have, but on a large scale, i start to see this error: " Uncaught TypeError: Cannot read properties of null (reading '0') ".
 
NOTE: when I comment : " gfxLayer.add(g) " or  " new FeatureSnappingLayerSource({ layer: gfxLayer as __esri.GraphicsLayer, 
enabled: true,
             }), "  or " visible: false," I don't see the error anymore, but snapping does not work.
any thoughts?
 
 

 

sketchVmRef.current = new SketchViewModel({
        view: mapView,
        layer: new GraphicsLayer({}),
        snappingOptions: {
          enabled: true,
          featureSources: [
             new FeatureSnappingLayerSource({
               layer: gfxLayer as __esri.GraphicsLayer,
               enabled: true,
             }),
          ],
        },
      })
    
const queriedFeatures = await featureLayerView.queryFeatures({
          where: `1=1`,
          outFields: ['*'],
          returnGeometry: true,
        })
       
        for (const feature of queriedFeatures.features) {
          
            const g = new Graphic({
              geometry: feature.geometry,
              attributes: feature.attributes,
              layer: gfxLayer,
              // visible: false,
            })
            gfxLayer.add(g)

        }

 

0 Kudos
2 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

I am not able to reproduce the behavior you describe. Would you mind creating a simple reproducible case? You can use this codepen as starting point: https://codepen.io/U_B_U/pen/BaGxBqK?editors=100

 

0 Kudos
JoelBennett
MVP Regular Contributor

The error appears to be driven by your implementation of "gfxLayer".  Can you provide more code as it relates to that object (i.e. its construction, setting of properties, etc)?

I encountered this same error message yesterday, although it's unlikely we had the same problem.  The error message occurs when an Array is expected, but a value of null is received.  In my case, I was trying to use a UniqueValueRenderer created from JSON with the uniqueValueGroups specified.  The JSON structure for uniqueValueGroups differs from the autocast structure, and is still undocumented, but I fumbled my way through it.

0 Kudos