LocalMapService what do I have to wait for?

2780
2
04-23-2013 07:28 PM
Labels (1)
RonaldNatalie
New Contributor II
I'm loading a local map package as follows:

            map_pkg = new ArcGISLocalDynamicMapServiceLayer("C:\Users\Me\foo.mpk");
            map_pkg.EnableDynamicLayers = true;
            map.Layers.Add(map_pkg);


If I immediately check the Layers in in map_pkg there's nothing there, the property is null.
If I let the application run for a bit and process some events and check back, it is populated with the layers in the file.

Is there anyway either prior to adding the pkg to the map or shortly there after to inspect the layers (I'd like to adjust the visibility early one).
0 Kudos
2 Replies
RonaldNatalie
New Contributor II
Never mind, I hooked the initialized event...
       map_pkg.Initialized += (s, e) =>
            {
                CheckLayers();
            };
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

That's correct. You might also want to listen for the InitializationFailed event.

You might also consider working with the underlying LocalMapService directly - where you can set the MaxRecords property (with respect to queries). Example below - I've used both an inline handler and explicit named events - obviously which pattern you choose is up to you.


        public MainWindow()
        {
            InitializeComponent();

            LocalMapService localMapService = new LocalMapService(@"..\Maps_and_Data\Map.mpk")
            {
                MaxRecords=1000000
            };
            localMapService.StartAsync(localServiceCallback =>
            {
                if (localServiceCallback.Error != null)
                {
                    // Do something with Error
                    return;
                }
                ArcGISDynamicMapServiceLayer localDynamicLayer =
                    new ArcGISLocalDynamicMapServiceLayer(localMapService);

                localDynamicLayer.Initialized += localDynamicLayer_Initialized;
                localDynamicLayer.InitializationFailed += localDynamicLayer_InitializationFailed;

                MyMap.Layers.Add(localDynamicLayer);
            });
        }

        void localDynamicLayer_InitializationFailed(object sender, System.EventArgs e)
        {

        }

        void localDynamicLayer_Initialized(object sender, System.EventArgs e)
        {
           
        }


Cheers

Mike