Select to view content in your preferred language

Has anyone used "findLayerByID" with success?

38
1
2 hours ago
Paco
by
Occasional Contributor

Hello again all.    I am still having problems accessing individual layers within my WebMap thru the js API.

if I have loaded an existing webmap visually in my app-

const webmap = new WebMap({
  portalItem: { // autocasts as new PortalItem()
    id: "xxportalIDxx"
  }
});
 
why can't I access the individual Layers within it by their IDs?   i've tried-
 
const newLayer = webmap.findLayerByID('xxlayerIDxx')
 
but keep getting- 
 
TypeError: webmap.findLayerByID is not a function
 
shouldn't this be a basic chore,  to access individual layers within a WebMap?
 
thx!
0 Kudos
1 Reply
ReneRubalcava
Frequent Contributor II

I think you have a typo. It's findLayerById.

You need to either wait for view.when() or call the webmap.loadAll(), both are promises so you can await them or use promise.then().

0 Kudos