FeatureLayer Source

1042
3
Jump to solution
03-29-2019 12:59 PM
by Anonymous User
Not applicable

Greetings, 

I'm trying to use featureLayer.source to create a feature layer with JSON. I create my featureLayer with an empty source and renderer and then try to add JSON data to it later. For some reason I'm getting the error:

            

            "Source modifications will not propagate after layer has been loaded. Please use .applyEdits() instead" 

I create the featureLayer like so:

  let fl = new FeatureLayer({
          popupTemplate: layer.popupTemplate,
          fields:layer.fields,
          objectIdField:"FACILITYID",
          id:layer.id,
          geometryType: "point",
          source:[]
        });
        fl.minScale = layer.minScale;
        console.log('fl.id: ' + fl.id)
        const arcade = ` IIf($feature.NUM >100, true, false)`
        var renderer = {
          type: "unique-value", // autocasts as new UniqueValueRenderer()
          valueExpression: arcade,
          valueExpressionTitle: "Adoption Status",
          uniqueValueInfos: [
            {
              value: true,
              symbol: self.createSymbol("#00c3ff"),
              label: "adopted"
            }, 
            {
              value: false,
              symbol: self.createSymbol("#ff002e"),
              label: "unadopted"
            }
          ]
        };
        
        mapView.map.add(fl)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Later on I try to add data to the feature layer using the source.add method like so:

let fl = self.state.mapView.map.findLayerById(layer.id)
      
fl.source.add({"attributes":{"FACILITYID":"DP76415003","INSTALLDATE":-2208970800000,"INLETTYPE":"Pipe","ACCESSDIAM":0,"adopted":"false"},"geometry":{"type":"point","x":-8769067.07037968,"y":4271765.250156212}})
      ‍‍‍‍‍‍

the fl.source.add method is what is giving me the error. 

Does anyone notice anythign that I'm doing wrong?

Thanks, Tyler 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor II

You can only add features via the source when you first create the client-side FeatureLayer. All subsequent updates need to happen via the applyEdits method just like you were editing the layer. There is a code snippet in the documentation. https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#applyEdi...

View solution in original post

3 Replies
ReneRubalcava
Frequent Contributor II

You can only add features via the source when you first create the client-side FeatureLayer. All subsequent updates need to happen via the applyEdits method just like you were editing the layer. There is a code snippet in the documentation. https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#applyEdi...

by Anonymous User
Not applicable

That was what I needed. Thank you for the info!

Tyler 

0 Kudos
UndralBatsukh
Esri Regular Contributor

Hi there, 

Rene answered already. Just adding this link for more information.