Select to view content in your preferred language

Adding Mapservice Programatically

1653
11
11-18-2013 12:18 AM
praveennarayandas
Deactivated User
Hi,

I am trying to add mapservice programatically.but it is not displaying map.
kindly letme know where i am doing wrong?

i have taken simple map application

My xaml code:
<esri:Map x:Name="MyMap" Background="White"  WrapAround="True" >
            <esri:ArcGISTiledMapServiceLayer x:Name="BaseMap" ID="BaseMap" Opacity="50"
                Initialized="MapServiceLayer_Initialized" InitializationFailed="Layer_InitializationFailed" />                    
        </esri:Map>

cs code:

            ArcGISTiledMapServiceLayer baseMap = new ArcGISTiledMapServiceLayer();
            String BaseMapResturl = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
            baseMap.Url = App._compentDict["BaseMapRestUrl"];
            baseMap.ID = "BaseMap";
            baseMap.Opacity = 50;
            baseMap.Initialized +=MapServiceLayer_Initialized;
            baseMap.InitializationFailed += MapServiceLayer_InitializationFailed;
            MyMap.Layers.Add(baseMap);

kindly let me where i am doing wrong.

thanks in advance.

praveen
0 Kudos
11 Replies
JohanCarlsson
Regular Contributor
What does the error message say?
0 Kudos
praveennarayandas
Deactivated User
The Error msg is

"The Best Overloaded method match for 'string.this[int]' has some invalid arguments"

thanks for support.
0 Kudos
DenisT
by
Deactivated User

            String BaseMapResturl = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
            baseMap.Url = App._compentDict["BaseMapRestUrl"];


What is _compentDict?
0 Kudos
praveennarayandas
Deactivated User
it is a static variable using to store url
0 Kudos
DenisT
by
Deactivated User
it is a static variable using to store url


Then why do you need this line?
String BaseMapResturl = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";


Maybe it's better to post the entire code and point the line that throws an exception.
0 Kudos
praveennarayandas
Deactivated User
Sorry For confusion in the source code.

Here I am attaching complete source code.

XAML:

<UserControl
    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:esri="http://schemas.esri.com/arcgis/client/2009" x:Class="silverlightmap.MainPage"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">

        <esri:Map x:Name="MyMap" Background="White"  WrapAround="True" >
            <esri:ArcGISTiledMapServiceLayer x:Name="BaseMap" ID="BaseMap" Opacity="50"
                Initialized="MapServiceLayer_Initialized" InitializationFailed="Layer_InitializationFailed" />                    
        </esri:Map>

    </Grid>
</UserControl>

.cs source code:


using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
namespace silverlightmap
{
    public partial class MainPage : UserControl
    {
       
        public MainPage()
        {
            InitializeComponent();
            ArcGISTiledMapServiceLayer baseMap = new ArcGISTiledMapServiceLayer();
            String BaseMapResturl = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
            baseMap.Url = App._compentDict["BaseMapRestUrl"];
            baseMap.ID = "BaseMap";
            baseMap.Opacity = 50;
            baseMap.Initialized += MapServiceLayer_Initialized;
            baseMap.InitializationFailed += MapServiceLayer_InitializationFailed;
            MyMap.Layers.Add(baseMap);
           
        }

       
        private void MapServiceLayer_InitializationFailed(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
        private void MapServiceLayer_Initialized(object sender, EventArgs e)
        {
           
            throw new NotImplementedException();
        }
      
    }
}


kindly let me know where i am doing wrong.

thanks a lot for support.
0 Kudos
praveennarayandas
Deactivated User
at line number 23 i am getting the error

Error 1 The best overloaded method match for 'string.this[int]' has some invalid arguments C:\inetpub\wwwroot\silverlightmap\silverlightmap\MainPage.xaml.cs 23 27 silverlightmap
0 Kudos
DenisT
by
Deactivated User
Here I am attaching complete source code.

Missing App.xaml.cs content.
0 Kudos
praveennarayandas
Deactivated User
App.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace silverlightmap
{
    public partial class App : Application
    {
        public static string _compentDict;

        public App()
        {
            this.Startup += this.Application_Startup;
            this.Exit += this.Application_Exit;
            this.UnhandledException += this.Application_UnhandledException;

            InitializeComponent();
        }

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.RootVisual = new MainPage();
        }

        private void Application_Exit(object sender, EventArgs e)
        {

        }

        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            // If the app is running outside of the debugger then report the exception using
            // the browser's exception mechanism. On IE this will display it a yellow alert
            // icon in the status bar and Firefox will display a script error.
            if (!System.Diagnostics.Debugger.IsAttached)
            {

                // NOTE: This will allow the application to continue running after an exception has been thrown
                // but not handled.
                // For production applications this error handling should be replaced with something that will
                // report the error to the website and stop the application.
                e.Handled = true;
                Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
            }
        }

        private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
        {
            try
            {
                string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
                errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");

                System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
            }
            catch (Exception)
            {
            }
        }

        public static string _ { get; set; }
    }
}
0 Kudos