Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
Bing Map displaying Shapefieles
posted
Hi everybody,

sorry for my bad English!


I have a question?
is there a simple way with Bing Map displaying Shapefieles so that the shapes are geocoded correctly?

I've loaded the example already in men's, but it can not emulate the Bing, the API has changed.


Many thanks



Olaf

this is my original bing:
<UserControl  
    x:Class="BingShp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
       
    </UserControl.Resources>
        <Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
     <m:Map  CredentialsProvider="x" x:Name="MyMap" Grid.Row="1" Mode="Road" Center="51.36236,7.47651" ZoomLevel="11" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
    </Grid>

</UserControl>
this is the attempt to unite it:
<UserControl  
    x:Class="BingShp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
     xmlns:ig="clr-namespace:Infragistics;assembly=InfragisticsSL4.DataVisualization.v10.2" 
   xmlns:igControls="clr-namespace:Infragistics.Controls;assembly=InfragisticsSL4.DataVisualization.v10.2" 
   xmlns:igMap="clr-namespace:Infragistics.Controls.Maps;assembly=InfragisticsSL4.Controls.Maps.XamMap.v10.2" 

    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
       
    </UserControl.Resources>
        <Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <m:Map  CredentialsProvider="x" x:Name="MyMap" Grid.Row="1" Mode="Road" Center="51.36236,7.47651" ZoomLevel="11" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
            <igMap:XamMap 
   x:Name="theMap"  
   Margin="30" 
   ViewportBackground="#FFDBEDFF"
                >
             <igMap:XamMap.Background>
             <SolidColorBrush Color="Transparent" Opacity="0"/>
             </igMap:XamMap.Background>
   <igMap:XamMap.Layers>
      <igMap:MapLayer 
         LayerName="PLZ" 
         FillMode="Choropleth" FontSize="2.5">
         <igMap:MapLayer.Reader>
            <igMap:ShapeFileReader DataMapping="Name=PLZ" Uri="shp/ZipCode" />
         </igMap:MapLayer.Reader>
      </igMap:MapLayer>
   </igMap:XamMap.Layers>
   <igMap:MapThumbnailPane 
      Width="200" 
      Height="100" 
      HorizontalAlignment="Center" 
      Margin="0,0,0,10" 
      Background="Transparent" 
      igControls:XamDock.Edge="InsideBottom" 
       />
   <igMap:MapNavigationPane Margin="10" igControls:XamDock.Edge="InsideRight" />
</igMap:XamMap>
        </m:Map>
    </Grid>

</UserControl>

 

 

Parents
  • 4666
    Verified Answer
    posted

    Hi Olaf,

    Probably you want to display data from BingMaps using data from BingMaps and shape files:

    I will give you a sample:

    1. You need to have a token from BingMaps:

    From Bing Maps Account Center : http://www.bingmapsportal.com/

    you need to generate a Bink Maps key (token) for your account to use with your application.

    2. Add a token in your Web.config file:

    <appSettings>
      <add key="token" value=[my application token]/>
    </appSettings>

    3. In the web project modify the default page :

    In Default.aspx.cs

           public string InitParams { get; set; }

     

           protected void Page_Load(object sender, EventArgs e)

            {

     

                if (System.Configuration.ConfigurationManager.AppSettings.Count > 0)

                {

                    string customSetting =

                        System.Configuration.ConfigurationManager.AppSettings["token"];

                    if (customSetting != null)

                    {

                        InitParams = "clientToken=" + customSetting;

                    }

                }

     

            }

    In Default.aspx:

        <div id="silverlightControlHost">

            <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">

              <param name="source" value="ClientBin/SlSQLSpatialApp.xap"/>

              <param name="onError" value="onSilverlightError" />

              <param name="background" value="white" />

              <param name="initParams" value="<%=InitParams%>" />

              <param name="minRuntimeVersion" value="4.0.50401.0" />

              <param name="autoUpgrade" value="true" />

              <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration:none">

                  <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>

              </a>

            </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>

           </div>

    In your client application:

    In App.xaml.cs:

           private void Application_Startup(object sender, StartupEventArgs e)

            {

                _token = e.InitParams["clientToken"];

                Application.Current.Resources.Add("token", _token);

                this.RootVisual = new MainPage();

            }

    You need this key to access the Bing Maps service

    Add a reference to BingMaps inagery service:

    http://dev.virtualearth.net/webservices/v1/imageryservice/imageryservice.svc/mex


    In the Silverlight application startup page you have no neet do add anything for this. In my sample I just added a combobox where to select witch maps style to load from Bing Maps service.

    MapControl has defined readers on for a vector data (shape files) there:

                <ig:XamMap.Layers>

                    <ig:MapLayer

                            Name="World" Brushes="#4C2C42C0 #4C218B93 #4CDC1C1C #4C3D7835 #4C701B51"

                            FillMode="Choropleth" WorldRect="{Binding ElementName=MainWindow, Path=WorldRect}"                       

                            >

                            <ig:MapLayer.Reader>

                                <ig:ShapeFileReader Uri="ShapeFiles\Cntry00\Cntry00"

                                       DataMapping="Name=CNTRY_NAME; Value=POP_CNTRY; Caption=CNTRY_NAME; ToolTip=CNTRY_NAME" />

                            </ig:MapLayer.Reader>

                            <ig:MapLayer.ValueScale>

                            <ig:LinearScale IsAutoRange="True"/>

                        </ig:MapLayer.ValueScale>

                    </ig:MapLayer>

                </ig:XamMap.Layers>

    in the cs file you need to add code to load a data from Bing Maps:

            private void SetImagerySource()

            {

                ComboBox combo = this.FindName("xMapStyle") as ComboBox;

     

                if (combo != null)

                {

                    if (combo.SelectedIndex == -1)

                    {

                        combo.SelectedIndex = 2;

                    }

                    MapStyle mapStyle = (MapStyle)combo.SelectedItem;

                    if (mapStyle == MapStyle.Birdseye || mapStyle == MapStyle.BirdseyeWithLabels)

                    {

                        MessageBox.Show("You can't use Birdseye and BirdseyeWithLabels Map Styles");

                        combo.SelectedIndex = -1;

                        return;

                    }

                    GetImagerySource(mapStyle);

                }

            }

            private void GetImagerySource(MapStyle mapStyle)

            {

                ImageryMetadataRequest metadataRequest = new ImageryMetadataRequest();

     

                // Set credentials using a valid Bing Maps Key

                metadataRequest.Credentials = new Credentials();

                metadataRequest.Credentials.ApplicationId = _key;

     

     

                metadataRequest.Style = mapStyle;

     

                // Make the imagery metadata request

                ImageryServiceClient imageryService = new ImageryServiceClient();

                imageryService.GetImageryMetadataAsync(metadataRequest);

                imageryService.GetImageryMetadataCompleted -= ImageryServiceGetImageryMetadataCompleted;

                imageryService.GetImageryMetadataCompleted += new EventHandler<BingMapsImageryService.GetImageryMetadataCompletedEventArgs>(ImageryServiceGetImageryMetadataCompleted);

            }

            void ImageryServiceGetImageryMetadataCompleted(object sender, GetImageryMetadataCompletedEventArgs e)

            {

                this.xamMap.MapTileSource = new BingMapsTileSource

                {

                    Token = _key,

                    TilePath = e.Result.Results[0].ImageUri,

                    SubDomains = e.Result.Results[0].ImageUriSubdomains

                };

     

            }

    Hope this can help :-)

     

    Cheers!

    Mihail

     

     

Reply Children
No Data