Change Feature Layers to Snapshot Mode

2817
4
03-04-2017 01:04 PM
JonLynch2
New Contributor II

Hi, I have a number of feature layers that are refreshing. These are hosted on an ArcGIS Server 10.4.1 (not ArcGIS online or Portal hosting server). When added to a web map (and web app builder app) they are in 'On Demand Mode' with a tile size of 512 x 512. These layers do not contain many features and I believe that the performance of refreshing them would improve if a single 'snapshot' request was made rather than 4-8 requests for tiles (depending on the monitor resolution).

I have read the FeatureLayer documentation and can only find references to setting the mode and tile sizes in the constructor. Does anybody know if it is possible to change these after a layer has been constructed or where in the web app builder code I would start looking to change how these layers are constructed?

Many thanks

Jon

Tags (1)
0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Jon,

  I don't see any support in the JS API for changing the mode of a FeatureLayer. The mode that the FeatureLayer uses is controlled by the WebMap that the WAB app uses and there is no observable code to change the mode use for a FeatureLayer as this is all internally controlled by the JS API ArcgisUtils.createMap method:

https://developers.arcgis.com/javascript/3/jsapi/esri.arcgis.utils-amd.html#createmap 

deleted-user-s-u3lS1YfHfK
New Contributor

Robert,

Thank you for the response and confirming my suspicions that it was not possible to change the mode after construction. After some digging I have found out one method to do this which I will describe below in case anybody else would like to switch layers from on-demand to snapshot mode in a web app builder application.

Note this is for feature layers hosted on an ArcGIS server 10.4.1. I believe that AGO/Portal hosted layers are more intelligent in their mode when added to a web map.

1. Update the web map json

Using ago-assistant.esri.com set the mode parameter of the operational layers you would like to be snapshot to 0. See https://developers.arcgis.com/web-map-specification/objects/featureLayer/ for the full details.

This puts your layer(s) into snapshot mode inside the AGO / Portal web map viewer but not in a web app builder application due the the 'esri/arcgis/utils' createMap() function not checking for snapshot mode.

2. Download the javascript api and host it locally so it can be modified

3. Hack 'esri/arcgis/utils' createMap() to honour the mode of the layer. (If you are using the standard build it will be in init.js)

Depending on the version of the javascript api in use the code may appear a little different (the e and E in the snippet below may be different due to different minification)  the section looks a little something like this:

`mode:e.mode==E.MODE_SELECTION?E.MODE_SELECTION:E.MODE_AUTO` (just search for .MODE_SELECTION?)

and should be changed to

`mode:e.mode==E.MODE_SELECTION?E.MODE_SELECTION:e.mode==E.MODE_SNAPSHOT?E.MODE_SNAPSHOT:E.MODE_AUTO`

4. Update the jsapi variable in env.js to point to your edited version of the javascript api.

Was it worth it? Well the we map we have has 11 feature layers refreshing every 12 seconds. On a high resolution monitor each layer took between 12 and 15 http requests to refresh and the application ground to a halt even when round trip times for each request was <300ms. Now the application runs smoothly and never gets bogged down when refreshing. If you have read this far I would welcome a suggestion of the best route to getting ESRI to make a similar modification to the JSAPI itself.

 

 

BenSaunders1
New Contributor III

Thanks for the pointer, Jon.

I found with the latest version - WAB 2.5 and JS API 3.21 - the issue still exists. But in addition to editing esri/arcgis/utils, I had to edit the same line in init.js (at the root of the API) as well for it to work in WAB (looks like esri/arcgis/utils is compiled into there...).

But couldn't have figured it out without your post - thanks!

JackCibor
Occasional Contributor II

Thanks, Dude. Seems to work great. 

0 Kudos