AnsweredAssumed Answered

How can I "lazy load" a feature layer?

Question asked by c_sharp_dotnet on Oct 15, 2017
Latest reply on Oct 16, 2017 by TSolow-esristaff

What is the best way to lazy load a feature layer for a map?  In my application, I have a map and handful of layers, some are turned off by default on launch.  These feature service layers that are off by default I would like to delay loading until the user clicks that layer's on/off check box.  Is this possible within the ArcGIS Online JS API?  The solution I've brainstormed so far is to set the layer's url to an empty feature service when the layer is first instantiated.  Inside the checkBox.on("change") function I would change the url to the correct feature service url, refresh() the layer, then proceed with the rest of the code that handles the layer rendering and tables.  I don't want to reinvent the wheel when possible, so I'm looking for a documented or better way of handling this while I roll my own solution.

Outcomes