Select to view content in your preferred language

Adding Layers Using Javascript

2147
2
07-15-2016 12:35 PM
ISP_graynic
Frequent Contributor

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

0 Kudos
2 Replies
KristianEkenes
Esri Regular Contributor

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.

ISP_graynic
Frequent Contributor

That is useful to know Kristian.  Thank you very much!

0 Kudos