Hello,
With Javascript, is there an advantage to adding layers in the constructor of a map using an array vs using map.add()?
var map = new Map({
layers: [housingLyr]
});
VS
map.add(housingLyr);
Thanks,
Nick
It's a matter of preference. I feel adding the layers in the constructor is more convenient if you want them added to the map when the view is ready.
However, there is an advantage to loading a WebMap with predefined layers, versus doing everything programmatically with the Map class. All you have to do is pass the item id of the webmap to the WebMap constructor. This loads all the layers, their renderers, and popups as defined and configured in the WebMap in ArcGIS Online, Portal for ArcGIS, or ArcGIS Desktop. You can save yourself time from writing many extra lines of code doing this.
That is useful to know Kristian. Thank you very much!