Select to view content in your preferred language

Bing TileLayer Silverlight 4

1102
9
06-17-2010 10:05 AM
KadeSmith
Frequent Contributor
When I try adding a Bing TileLayer to a map in SL4, I get the following error message:

A value of type 'TileLayer' cannot be added to a collection or dictionary of type 'LayerCollection'.

Exact code in SL3 is working fine.  Here are portions of my code.

xmlns:bing="clr-namespace:ESRI.ArcGIS.Client.Bing;assembly=ESRI.ArcGIS.Client.Bing"

<esri:Map x:Name="Map" IsLogoVisible="False" Loaded="Map_Loaded" Grid.Row="1">
            <esri:Map.Extent>
                <esriGeometry:Envelope XMin="-9860192.874701" YMin="3536523.562187" XMax="-9454281.630124" YMax="4181859.017432">
                    <esriGeometry:Envelope.SpatialReference>
                        <esriGeometry:SpatialReference WKID="102100" />
                    </esriGeometry:Envelope.SpatialReference>
                </esriGeometry:Envelope>
            </esri:Map.Extent>
           
            <esri:Map.Layers>
                <bing:TileLayer ID="BingLayer" LayerStyle="Road" Visible="True" />
                <esri:ArcGISTiledMapServiceLayer ID="Street Map" Url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" Opacity=".5" />              
                <esri:GraphicsLayer ID="MarkupDrawingLayer" />
            </esri:Map.Layers>
           
        </esri:Map>
0 Kudos
9 Replies
TylerMunn
Emerging Contributor
I'm getting the same issue, however I haven't tried it in SL3. Unsure of where to go from there
0 Kudos
dotMorten_esri
Esri Notable Contributor
Microsoft fixed a few things in the XAML parser that is causing this. Either remove the <esri:Map.Layers> part (layer collection is implied), or add a <esri:LayerCollection> around the layers:

<esri:Map >
  <esri:Map.Layers>
    <esri:LayerCollection>
      <bing:TileLayer />
      <esri:ArcGISTiledMapServiceLayer /> 
      <esri:GraphicsLayer />
    </esri:LayerCollection>
  </esri:Map.Layers>
</esri:Map> 


or

<esri:Map >
  <bing:TileLayer />
  <esri:ArcGISTiledMapServiceLayer /> 
  <esri:GraphicsLayer />
</esri:Map> 


Difference is that the first one replaces the existing layer collection, the other one adds to it, but the result is the same.
0 Kudos
TylerMunn
Emerging Contributor
Morten,

I have modified my code and am still getting the same message as kadesmith. Even taking the code example from http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#BingImagery where

<bing: TileLayer / > falls only within <esri:map > </esri:map>, the error still appears.
0 Kudos
TylerMunn
Emerging Contributor
kadesmith - were you able to resolve your issue?

Morten, would you have any idea aside from your earlier suggestion? I have my ECP code for Bing Imagery from ESRI and am really hoping to have it up & running asap.

Thanks
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I already got this error when there is a mismatch in the ESRI.ArcGIS.Client and ESRI.ArcGIS.Client.bing references (not the same version number).

Verify the versions of these 2 packages and might worth the try to remove and to add again the references.
0 Kudos
TylerMunn
Emerging Contributor
It works now, great! Thanks a lot for the help.
0 Kudos
TylerMunn
Emerging Contributor
One more question, using the sample code found on the ESRI Silverlight Samples page, is it possible to remove the bing maps tile layer completely? Ive added a 4th button titled 'None', and to cut down on imagery costs when they are not necessary, I would like to not show any Bing Tiles when that option is checked. Thanks again.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I did that in one application, so I give you the code (XAML):
  
<!-- Base Map Switcher -->
<Border x:Name="BaseMapSwitcher" Style="{StaticResource CommonBorder}" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="5">
 <StackPanel Orientation="Horizontal" Margin="5">
   <RadioButton Content="No BaseMap" ToolTipService.ToolTip="No base map" GroupName="BaseLayer" Margin="5,0,0,0" Foreground="White" FontSize="11" >
     <i:Interaction.Triggers>
       <i:EventTrigger EventName="Checked">
         <actions:SetLayerVisibilityAction TargetName="Map" LayerID="BaseLayer" Visible="False"/>
       </i:EventTrigger>
     </i:Interaction.Triggers>
   </RadioButton>
   <RadioButton Content="Streets" IsChecked="True" ToolTipService.ToolTip="Worldwide Street Map" GroupName="BaseLayer" Margin="5,0,0,0" Foreground="White" FontSize="11" >
     <i:Interaction.Triggers>
       <i:EventTrigger EventName="Checked">
         <actions:SetLayerUrlAction TargetName="Map" LayerID="BaseLayer" Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
         <actions:SetLayerVisibilityAction TargetName="Map" LayerID="BaseLayer" Visible="True"/>
       </i:EventTrigger>
     </i:Interaction.Triggers>
   </RadioButton>
.......


As an ArcGISMapServiceLayer doesn't accept an empty Url, I switch the visibility On/Off.
0 Kudos
TylerMunn
Emerging Contributor
Thanks Dominique
private void RadioButtonOff_Click(object sender, RoutedEventArgs e)
        {
            ESRI.ArcGIS.Client.Bing.TileLayer tileLayer = MyMap.Layers["BingLayer"] as TileLayer;
            tileLayer.Visible = false;
        }

        private void RadioButton_Click(object sender, RoutedEventArgs e)
        {
            ESRI.ArcGIS.Client.Bing.TileLayer tileLayer = MyMap.Layers["BingLayer"] as TileLayer;
            string layerTypeTag = (string)((RadioButton)sender).Tag;
            TileLayer.LayerType newLayerType = (TileLayer.LayerType)System.Enum.Parse(typeof(TileLayer.LayerType), layerTypeTag, true);
            tileLayer.LayerStyle = newLayerType;

            if (tileLayer.Visible == false) 
            {
            tileLayer.Visible = true;
            }
 
        }


I tried that just after you posted and it works, rather than doing the code in xaml.

I assume I would have to contact microsoft or track the usage manually to find out if Bing Maps is still counting transactions because I am only changing the visibility of the tile layer, not removing the actual basemap.
0 Kudos