Select to view content in your preferred language

Typescript error adding sublayers to MapImageLayer

534
3
Jump to solution
02-22-2023 06:48 PM
LefterisKoumis
Regular Contributor II

I declare a mapimagelayer 

 

 const MPl = new MapImageLayer({
----
----

 

Then I created an array of sublayers that need to be visilbe.

 I added the sublayers index in an array

 

thearr.push({
            id: 1,
            visible: true},
           {
            id: 3,
            visible: true}
          );

 

Then, I used:

MPl.sublayers = thearr;

 but I got an  error

LefterisKoumis_0-1677120416696.png

When I used this script without using typescript i have no errors and it runs fine.

0 Kudos
1 Solution

Accepted Solutions
Noah-Sager
Esri Regular Contributor

I'm not 100% positive, but I think that if you don't declare the sublayers in the MapImageLayer constructor, you need to use one of the Collection methods to define/add/modify the sublayers.

Collection methods:

https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Collection.html#methods-summ...

sublayers property:

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-MapImageLayer.html#sublaye...

View solution in original post

0 Kudos
3 Replies
Noah-Sager
Esri Regular Contributor

I'm not 100% positive, but I think that if you don't declare the sublayers in the MapImageLayer constructor, you need to use one of the Collection methods to define/add/modify the sublayers.

Collection methods:

https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Collection.html#methods-summ...

sublayers property:

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-MapImageLayer.html#sublaye...

0 Kudos
LefterisKoumis
Regular Contributor II

Thank you. Looking at the documentation, it seems that in JS 4.x is more work  to define visible layers of a mapimagelayer. In JS 3.x  we could just write this. 

lyr.setVisibleLayers([1,2,3])

I assume there is  no similar way of doing so in JS 4.x 

In a collection like

MPl.sublayers.push(item)

where item or comma-separated list of items cannot be the sublayer id. 

0 Kudos
Noah-Sager
Esri Regular Contributor

Yes, there is an implementation difference between 3x and 4x. I would highly recommend looking at some 4x samples to get a feel for the difference. These two might be useful:

https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=layers-mapimagelayer-sub...

https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=layers-mapimagelayer-def...

 

0 Kudos