Hi Olivier,
The reason the code works in MapImageLayer and not TileLayer is because you're creating a dynamic sublayer in the constructor of the MapImageLayer. This is technically a new sublayer and a powerful capability of MapImageLayer.
However, TileLayer has sublayers that are readonly. So when you use the same snippet, you're actually attempting to create new sublayers within the constructor of the TileLayer. Since sublayers is a readonly property, you will see an error. However, you can still modify properties like popupTemplate, popupEnabled, and legendEnabled on existing sublayers. You just need to modify the code a little bit to get the proper sublayer. This should work in your app:
<SPAN class="keyword token">var</SPAN> SA_Innondation <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">TileLayer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN> url<SPAN class="punctuation token">:</SPAN><SPAN class="string token">"https://sig.gironde.fr/arcgis/rest/services/APP/sa_inondation_v_1_0/MapServer/"</SPAN><SPAN class="punctuation token">,</SPAN> title<SPAN class="punctuation token">:</SPAN><SPAN class="string token">"Sensibilité Aléas Inondation"</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> sublayer <SPAN class="operator token">=</SPAN> SA_Innondation<SPAN class="punctuation token">.</SPAN><SPAN class="token function">findSublayerById</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> sublayer<SPAN class="punctuation token">.</SPAN>popupTemplate <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN> title<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"{ppr_label}"</SPAN><SPAN class="punctuation token">,</SPAN> content<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"{risq_2015}"</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.