Select to view content in your preferred language

v4.7 - How to redraw/refresh FeatureLayer in MapView after applyEdits? (SceneView works fine)

1630
2
Jump to solution
05-16-2018 03:09 PM
DannyBritt1
Emerging Contributor

Link to github showcasing this particular issue with version 4.7.2 of the API: GitHub - danbritt/arcgis-api-refresh-issue 

This project uses this as a base: jsapi-resources/4.x/webpack/demo at master · Esri/jsapi-resources · GitHub  and I'm using the featurelayer from this example: ArcGIS API for JavaScript Sandbox 

When using applyEdits on a FeatureLayer that is in a SceneView, the new feature saves and shows up on the map. If you switch to a MapView, it saves the features correctly, but they do not show on the map unless you pan away and then back. (In my github, you can change the import at the top of webmapview.tsx to test this issue.)

The only way I can get the layer to refresh in a MapView is to do some weird asynchronous changing of the definitionExpression using window.setTimeout() (which hasn't been reliable), or removing and re-adding the layer to the map which causes all features to disappear for a second which isn't ideal.

I tried using the refresh() method of FeatureLayer but it didn't seem to do anything. I did not see any requests made in the network tab of chrome dev tools or any redrawing of the layer.

Is this a bug? Or is there some way to refresh the layer in a MapView that I am not seeing? Any help would be appreciated, and if I can show any more details let me know.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Honored Contributor

By default, the webpack-plugin has WebGL for FeatureLayers enabled.

arcgis-webpack-plugin/loaderConfig.js at master · Esri/arcgis-webpack-plugin · GitHub 

Currently, WebGL FeatureLayer doesn't support applyEdits.

For the webpack-plugin, you can provide your own loaderConfig(), just copy the one from the repo and update your webpack config to use it.

// in your own loaderConfig.js
// change this line
"esri-featurelayer-webgl": 0

// in your webpack.config.js
plugins: [
  new ArcGISPlugin({
    options: {
      loaderConfig: require("./myCustomloaderConfig")
    }
  })
];‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

0 Kudos
2 Replies
ReneRubalcava
Honored Contributor

By default, the webpack-plugin has WebGL for FeatureLayers enabled.

arcgis-webpack-plugin/loaderConfig.js at master · Esri/arcgis-webpack-plugin · GitHub 

Currently, WebGL FeatureLayer doesn't support applyEdits.

For the webpack-plugin, you can provide your own loaderConfig(), just copy the one from the repo and update your webpack config to use it.

// in your own loaderConfig.js
// change this line
"esri-featurelayer-webgl": 0

// in your webpack.config.js
plugins: [
  new ArcGISPlugin({
    options: {
      loaderConfig: require("./myCustomloaderConfig")
    }
  })
];‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
DannyBritt1
Emerging Contributor

Thanks for the answer, Rene.

That did the trick.

I did also notice that setting the "visible" property of a graphic to false in a FeatureLayer (webgl set to 0) does not hide the graphic in MapView, but it does in SceneView. I have a need to temporarily hide a graphic and as a workaround, I'm currently modifying the definitionExpression to exclude that OBJECTID, then set it back later, but that's kind of cumbersome with the network traffic depending on number of features. 

I'm looking forward to more of these features coming to the MapView and the WebGL FeatureLayers in the future!

Also, thanks for the work on the new webpack plugin. It's made the process of integrating the API into our build so much easier!

0 Kudos