2

I have defined a simple tiled map service layer:

<esri:ArcGISTiledMapServiceLayer x:Name="BaseMap"
ID="BaseMap" Opacity="50" Initialized="MapServiceLayer_Initialized"
InitializationFailed="Layer_InitializationFailed" />

Then I assign its Url property programmatically:

BaseMap.Url = App._componentDict["BaseMapRestUrl"];

The app bombs with this message, and the entire Silverlight app goes blank:

Layer 'BaseMap' is currently unavailable. Error" Value cannot be null. Parameter name: Url

error

Is there a particular way to go about this that I'm missing? I suspect I'm setting the Url too late in the lifecycle.

3
  • 3
    Since you're relying on code-behind anyway, why not just add the layer there instead of in xaml? Commented May 3, 2011 at 21:56
  • @Kirk - that worked. Seems like defining the Url property at runtime is not supported.
    – nw1
    Commented May 4, 2011 at 15:21
  • You can using event triggers. For an example of that create a new project using the Esri Standard Map Application project template, then look at the Base Map Switcher section of MainPage.xaml. Commented May 4, 2011 at 15:33

2 Answers 2

2

Following Kirk's suggestion in the comments, I just did this:

// add base map layer
ArcGISTiledMapServiceLayer baseMap = new ArcGISTiledMapServiceLayer();
baseMap.Url = App._componentDict["BaseMapRestUrl"];
baseMap.ID = "BaseMap";
baseMap.Opacity = 50;
baseMap.Initialized += MapServiceLayer_Initialized;
baseMap.InitializationFailed += MapServiceLayer_InitializationFailed;
MyMap.Layers.Add(baseMap);

It worked great.

1
  • Great to see you post your working solution. Thanks for showing what worked.
    – D.E.Wright
    Commented May 9, 2011 at 17:07
1

To set the url at runtime you might consider using a trigger action, as illustrated in Esri's Standard Map Application project template (under the Silverlight folder when you create a new project in visual studio).

This is from the Base Map Switcher section of MainPage.xaml:

<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://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</RadioButton>
<RadioButton Content="Topo"
    GroupName="BaseLayer"
    ToolTipService.ToolTip="United States Topographic Map"
    Margin="5,0,0,0" Foreground="White" FontSize="11" >
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Checked">
            <actions:SetLayerUrlAction TargetName="Map" LayerID="BaseLayer" 
                  Url="http://services.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</RadioButton>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.