<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: PrintTask LegendLayer Can not set the SubLayerIds in ArcGIS API for Silverlight Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/printtask-legendlayer-can-not-set-the-sublayerids/m-p/318701#M8222</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can't cast directly a List&amp;lt;int&amp;gt; to an IEnumerable&amp;lt;object&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Even if the Silverlight IEnumerable was supporting the covariance (which anyway is not the case unlike WPF version), that would not work since int is not an object.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should get it to work by casting each int to an object. Something like:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;
&lt;P&gt;myLegendLayer.SubLayerIds = pair.Value.Cast&amp;lt;object&amp;gt;();&lt;/P&gt;
&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 17 Nov 2014 07:34:23 GMT</pubDate>
    <dc:creator>DominiqueBroux</dc:creator>
    <dc:date>2014-11-17T07:34:23Z</dc:date>
    <item>
      <title>PrintTask LegendLayer Can not set the SubLayerIds</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/printtask-legendlayer-can-not-set-the-sublayerids/m-p/318700#M8221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a print service setup with custom layouts published with Export Web Map. The Layouts do not contain any layers, these are added in the PrintTask .&amp;nbsp; I have created a dictionary of all of the layers that are within my map extent named legendInfo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the legend I need to set the SublayerIds for the Legend Layer to be those that are within the map extent and are visible. This is done to minimize the size of the Legend on the pdf.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the dictionary key value pair, the key is the ID of the ArcGISDynamicMapServiceLayer and the values are a List&amp;lt;int&amp;gt; of the subids for the ArcGISDynamicMapServiceLayer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;. I have tried several casts such as pair.Value as IEnumerable&amp;lt;List&amp;lt;int&amp;gt;&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SublayerIds are null after the loop has finished.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scratching my head...any suggestions? Thanks in advance...&lt;/P&gt;&lt;P&gt;Margo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (var pair in legendInfo) &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ESRI.ArcGIS.Client.Printing.LegendLayer myLegendLayer = new ESRI.ArcGIS.Client.Printing.LegendLayer();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set the LegendLayer.LayerId to the Layer.ID to add it to the printed map's legend area.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myLegendLayer.LayerId = pair.Key.ToString();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myLegendLayer.SubLayerIds = pair.Value as IEnumerable&amp;lt;Object&amp;gt;;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myLegendLayers.Add(myLegendLayer);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000; font-size: 10pt; font-family: Consolas;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000; font-size: 10pt; font-family: Consolas;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 00:09:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/printtask-legendlayer-can-not-set-the-sublayerids/m-p/318700#M8221</guid>
      <dc:creator>MargoBlosser</dc:creator>
      <dc:date>2014-11-15T00:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: PrintTask LegendLayer Can not set the SubLayerIds</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/printtask-legendlayer-can-not-set-the-sublayerids/m-p/318701#M8222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can't cast directly a List&amp;lt;int&amp;gt; to an IEnumerable&amp;lt;object&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Even if the Silverlight IEnumerable was supporting the covariance (which anyway is not the case unlike WPF version), that would not work since int is not an object.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should get it to work by casting each int to an object. Something like:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;
&lt;P&gt;myLegendLayer.SubLayerIds = pair.Value.Cast&amp;lt;object&amp;gt;();&lt;/P&gt;
&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Nov 2014 07:34:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/printtask-legendlayer-can-not-set-the-sublayerids/m-p/318701#M8222</guid>
      <dc:creator>DominiqueBroux</dc:creator>
      <dc:date>2014-11-17T07:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: PrintTask LegendLayer Can not set the SubLayerIds</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/printtask-legendlayer-can-not-set-the-sublayerids/m-p/318702#M8223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Margo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PrintTask already does this for you if you had chosen a Format other than MapOnly, if LayoutOptions.LegendOptions was provided and if the layers for printing have their ID property set. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use Linq query to iterate through ArcGISSDynamicMapSerivceLayer .VisibleLayers. Since it is different type for ArcGISSDynamicMapSerivceLayer (int) and WmsLayer (string), we opted to use object.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if (l.ShowLegend)
&amp;nbsp; {
&amp;nbsp; var legendLayer = new LegendLayer() { LayerId = l.ID };
&amp;nbsp; if (l is ArcGISDynamicMapServiceLayer)
&amp;nbsp; {
&amp;nbsp; if ((l as ArcGISDynamicMapServiceLayer).VisibleLayers != null)
&amp;nbsp; {
&amp;nbsp; legendLayer.SubLayerIds = from s in (l as ArcGISDynamicMapServiceLayer).VisibleLayers
&amp;nbsp;&amp;nbsp; select s as object;
&amp;nbsp; }
&amp;nbsp; else if ((l as ArcGISDynamicMapServiceLayer).DynamicLayerInfos != null)
&amp;nbsp; {
&amp;nbsp; legendLayer.SubLayerIds = from s in (l as ArcGISDynamicMapServiceLayer).DynamicLayerInfos
&amp;nbsp;&amp;nbsp; select s.ID as object;
&amp;nbsp; }
&amp;nbsp; else if ((l as ArcGISDynamicMapServiceLayer).Layers != null)
&amp;nbsp; {
&amp;nbsp; legendLayer.SubLayerIds = from s in (l as ArcGISDynamicMapServiceLayer).Layers
&amp;nbsp;&amp;nbsp; select s.ID as object;
&amp;nbsp; }
&amp;nbsp; }
&amp;nbsp; else if (l is WmsLayer)
&amp;nbsp; {
&amp;nbsp; if ((l as WmsLayer).Layers != null)
&amp;nbsp; {
&amp;nbsp; legendLayer.SubLayerIds = from s in (l as WmsLayer).Layers
&amp;nbsp;&amp;nbsp; select s as object;
&amp;nbsp; }
&amp;nbsp; else if ((l as WmsLayer).LayerList != null)
&amp;nbsp; {
&amp;nbsp; legendLayer.SubLayerIds = from s in (l as WmsLayer).LayerList
&amp;nbsp;&amp;nbsp; select s.Name as object;
&amp;nbsp; }
&amp;nbsp; }
&amp;nbsp; legendLayers.Add(legendLayer);
&amp;nbsp; }&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:09:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/printtask-legendlayer-can-not-set-the-sublayerids/m-p/318702#M8223</guid>
      <dc:creator>JenniferNery</dc:creator>
      <dc:date>2021-12-11T15:09:14Z</dc:date>
    </item>
  </channel>
</rss>

