Select to view content in your preferred language

using Bing Maps samples

1480
9
01-13-2011 12:22 PM
JoannaLaroussi
Emerging Contributor
I would like to use a sample from Bing Maps (ArcGIS Resource Center/ Silverlight). I found information in XAML code that I need to �??Replace Token value with your Bing Maps key.  Use http://www.bingmapsportal.com to generate a key�?�. I do have already a bing key in my server manager. Is it the same key or I need to generate something new? The key I have is a string of letters and numbers like �??123abc�?�. Where exactly in the example suppose I past it? An example line is: Token="{StaticResource BingKeyString}" /> I tried to change it for Token="{StaticResource 123abc}" /> but this does not work�?� Can somebody explain me what exactly to do in order to use ESRI Bing Maps examples? Thanks!
0 Kudos
9 Replies
DanielWalton
Frequent Contributor
The string from your server is all you need. Also, the replacement you tried is invalid (you need to assign the value of BingKeyString wherever it is defined, probably in App.xaml:

<Application ... xmlns:clr="clr-namespace:System;assembly=mscorlib">
<Application.Resources>
    <sys:String x:Key="BingKeyString">abc...123</sys:String>
</Application.Resources>
0 Kudos
JoannaLaroussi
Emerging Contributor
The string from your server is all you need. Also, the replacement you tried is invalid (you need to assign the value of BingKeyString wherever it is defined, probably in App.xaml:

<Application ... xmlns:clr="clr-namespace:System;assembly=mscorlib">
<Application.Resources>
    <sys:String x:Key="BingKeyString">abc...123</sys:String>
</Application.Resources>


Thank you for your advice. I tried to change my code to this:
<UserControl x:Class="bing.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    xmlns:bing="clr-namespace:ESRI.ArcGIS.Client.Bing;assembly=ESRI.ArcGIS.Client.Bing">
    xmlns:clr="clr-namespace:System;assembly=mscorlib">

    <Application.Resources>
        <sys:String x:Key="BingKeyString">abc123</sys:String>
    </Application.Resources>

    <Grid x:Name="LayoutRoot">

        <esri:Map x:Name="MyMap">
            <!-- Replace Token value with your Bing Maps key.  Use http://www.bingmapsportal.com to generate a key. -->
            <bing:TileLayer ID="BingLayer" LayerStyle="Road" Visible="True" ServerType="Production"
                   Token="{StaticResource BingMapsKey}" />
        </esri:Map>

        <Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10" >
            <Rectangle Fill="#77919191" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0" >
                <Rectangle.Effect>
                    <DropShadowEffect/>
                </Rectangle.Effect>
            </Rectangle>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="5" >
                <RadioButton x:Name="RoadRadioButton"
                         Tag="Road" IsChecked="true" Margin="5,0,0,0" Foreground="White"
                         GroupName="Layers" Content="Road" Click="RadioButton_Click"/>
                <RadioButton x:Name="AerialRadioButton"
                         Tag="Aerial" Margin="5,0,0,0" Foreground="White"
                         GroupName="Layers" Content="Aerial" Click="RadioButton_Click"/>
                <RadioButton x:Name="AerialWithLabelsRadioButton"
                         Tag="AerialWithLabels" Margin="5,0,0,0" Foreground="White"
                         GroupName="Layers" Content="Aerial - Labels" Click="RadioButton_Click"/>
            </StackPanel>
        </Grid>

    </Grid>
</UserControl>

And I received following errors:
Error 1 'sys' is an undeclared prefix. 
Error 4 A value of type 'String' cannot be added a child of type 'UIElement'.
Error 2 The attachable property 'Resources' was not found in type 'Application'.
Error 5 The property 'Content' is set more than once.
Error 3 The type 'sys:String' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
0 Kudos
DanielWalton
Frequent Contributor
My bad. Sorry. In the heading tag for App.xaml, change

xmlns:clr="clr-namespace:System;assembly=mscorlib">

to

xmlns:sys="clr-namespace:System;assembly=mscorlib">
0 Kudos
JoannaLaroussi
Emerging Contributor
Still not a full success�?� Once I added just the first line
xmlns:sys="crl-namespace:System;assembly=mscorlib">
I received two errors:
Error 1 A value of type 'String' cannot be added a child of type 'UIElement'.
Error 2 The property 'Content' is set more than once. (this one refers to line <Grid x:Name="LayoutRoot">)
Do you think that I am adding it in a right place?



Thank you for your advice. I tried to change my code to this:
<UserControl x:Class="bing.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    xmlns:bing="clr-namespace:ESRI.ArcGIS.Client.Bing;assembly=ESRI.ArcGIS.Client.Bing">
    xmlns:clr="clr-namespace:System;assembly=mscorlib">

    <Application.Resources>
        <sys:String x:Key="BingKeyString">abc123</sys:String>
    </Application.Resources>

    <Grid x:Name="LayoutRoot">

        <esri:Map x:Name="MyMap">
            <!-- Replace Token value with your Bing Maps key.  Use http://www.bingmapsportal.com to generate a key. -->
            <bing:TileLayer ID="BingLayer" LayerStyle="Road" Visible="True" ServerType="Production"
                   Token="{StaticResource BingMapsKey}" />
        </esri:Map>

        <Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10" >
            <Rectangle Fill="#77919191" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0" >
                <Rectangle.Effect>
                    <DropShadowEffect/>
                </Rectangle.Effect>
            </Rectangle>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="5" >
                <RadioButton x:Name="RoadRadioButton"
                         Tag="Road" IsChecked="true" Margin="5,0,0,0" Foreground="White"
                         GroupName="Layers" Content="Road" Click="RadioButton_Click"/>
                <RadioButton x:Name="AerialRadioButton"
                         Tag="Aerial" Margin="5,0,0,0" Foreground="White"
                         GroupName="Layers" Content="Aerial" Click="RadioButton_Click"/>
                <RadioButton x:Name="AerialWithLabelsRadioButton"
                         Tag="AerialWithLabels" Margin="5,0,0,0" Foreground="White"
                         GroupName="Layers" Content="Aerial - Labels" Click="RadioButton_Click"/>
            </StackPanel>
        </Grid>

    </Grid>
</UserControl>

And I received following errors:
Error 1 'sys' is an undeclared prefix. 
Error 4 A value of type 'String' cannot be added a child of type 'UIElement'.
Error 2 The attachable property 'Resources' was not found in type 'Application'.
Error 5 The property 'Content' is set more than once.
Error 3 The type 'sys:String' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
0 Kudos
DanielWalton
Frequent Contributor
Oh, I see. You should change:

<Application.Resources>
        <sys:String x:Key="BingKeyString">abc123</sys:String>
    </Application.Resources>

to

<UserControl.Resources>
        <sys:String x:Key="BingKeyString">abc123</sys:String>
    </UserControl.Resources>
0 Kudos
JoannaLaroussi
Emerging Contributor
Oh, I see. You should change:

<Application.Resources>
        <sys:String x:Key="BingKeyString">abc123</sys:String>
    </Application.Resources>

to

<UserControl.Resources>
        <sys:String x:Key="BingKeyString">abc123</sys:String>
    </UserControl.Resources>


I am really thankful for your time, but I am not there yet�?� Last change reduced my errors to four, but this is still four to much to make it work 😞
Error 1 'sys' is an undeclared prefix. Line 8, position 10.
And Error 2 The type 'sys:String' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
Refer to: <sys:String x:Key="BingKeyString">abc123</sys:String>
Error 3 A value of type 'String' cannot be added a child of type 'UIElement'.
Refers to: xmlns:sys="crl-namespace:System;assembly=mscorlib">
Error 4 The property 'Content' is set more than once.
Refers to: <Grid x:Name="LayoutRoot">
Here is everything again (bold lines means problems)
<UserControl x:Class="bing.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    xmlns:bing="clr-namespace:ESRI.ArcGIS.Client.Bing;assembly=ESRI.ArcGIS.Client.Bing">
    xmlns:sys="crl-namespace:System;assembly=mscorlib">    <UserControl.Resources>
        <sys:String x:Key="BingKeyString">abc123</sys:String>    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">

        <esri:Map x:Name="MyMap">
            <!-- Replace Token value with your Bing Maps key.  Use http://www.bingmapsportal.com to generate a key. -->
            <bing:TileLayer ID="BingLayer" LayerStyle="Road" Visible="True" ServerType="Production"
                   Token="{StaticResource BingMapsKey}" />
        </esri:Map>

        <Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10" >
            <Rectangle Fill="#77919191" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0" >
                <Rectangle.Effect>
                    <DropShadowEffect/>
                </Rectangle.Effect>
            </Rectangle>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="5" >
                <RadioButton x:Name="RoadRadioButton"
                         Tag="Road" IsChecked="true" Margin="5,0,0,0" Foreground="White"
                         GroupName="Layers" Content="Road" Click="RadioButton_Click"/>
                <RadioButton x:Name="AerialRadioButton"
                         Tag="Aerial" Margin="5,0,0,0" Foreground="White"
                         GroupName="Layers" Content="Aerial" Click="RadioButton_Click"/>
                <RadioButton x:Name="AerialWithLabelsRadioButton"
                         Tag="AerialWithLabels" Margin="5,0,0,0" Foreground="White"
                         GroupName="Layers" Content="Aerial - Labels" Click="RadioButton_Click"/>
            </StackPanel>
        </Grid>

    </Grid>
</UserControl>
0 Kudos
DanielWalton
Frequent Contributor
You need to add a reference to mscorlib in your Silverlight project.
0 Kudos
JoannaLaroussi
Emerging Contributor
Thanks a lot! This left me with only one error:
Error 1 'sys' is an undeclared prefix. Line 8, position 10.
0 Kudos
DanielWalton
Frequent Contributor
You have a spelling error in your heading tag:

xmlns:sys="crl-namespace:System;assembly=mscorlib"

should be:

xmlns:sys="clr-namespace:System;assembly=mscorlib"
0 Kudos