Select to view content in your preferred language

Can MediaLayer be displayed beneath a GraphicLayer?

478
3
Jump to solution
03-05-2024 05:48 PM
JackyCai
Occasional Contributor

Hi,

As far as I know, MediaLayer and GraphicLayer do not have "index" attribute, so their display order are determined by their sequences in the layer array of the map.

This does work for among same layers, so if a GraphicLayer (MediaLayer) is added to map after another layer of its same kind, their graphics (elements) would be displayed on top of the ones from the other layer. However, even if a GraphicLayer is added to map after a MediaLayer, the graphic stills display beneath media elements.

Is there a way to control display orders of GraphicLayer and MediaLayer?

BTW, I am using verison 4.28.

Thank you!

0 Kudos
1 Solution

Accepted Solutions
Sage_Wall
Esri Contributor

Hi @JackyCai ,

MediaLayer and GraphicLayer behave like any other layer and can be placed in any position in the layer's collection.  The last layer in the map.layers collection in the top layer in the map.  You can use the collection add() method with an optional parameter for the index to place a layer anywhere in that collection.

I created a codepen that shows a graphics layer added after a media layer and the graphics appear on top.

https://codepen.io/sagewall/pen/GRLpmMZ

If you comment out line 262 and uncomment line 264 (where I used the index) you can change the order of the MediaLayer and GraphicsLayer in the collection and the order they appear in the map.

I hope this helps

View solution in original post

3 Replies
Sage_Wall
Esri Contributor

Hi @JackyCai ,

MediaLayer and GraphicLayer behave like any other layer and can be placed in any position in the layer's collection.  The last layer in the map.layers collection in the top layer in the map.  You can use the collection add() method with an optional parameter for the index to place a layer anywhere in that collection.

I created a codepen that shows a graphics layer added after a media layer and the graphics appear on top.

https://codepen.io/sagewall/pen/GRLpmMZ

If you comment out line 262 and uncomment line 264 (where I used the index) you can change the order of the MediaLayer and GraphicsLayer in the collection and the order they appear in the map.

I hope this helps

JackyCai
Occasional Contributor

Thank you for your reply, I am going to check if there is anything wrong in my code and update here.

0 Kudos
JackyCai
Occasional Contributor

Yes, it is working perfectly in your demo and mine, there must be something wrong with the layer management in my project. Thanks for the help!

0 Kudos