LocalMapService load .mpk map fail

3463
12
07-05-2015 08:39 PM
坤王
by
New Contributor

map don't load mpk map. debug it only execute  await localMapService.StartAsync();  why?

code:

public async void CreateLocalServiceAndDynamicLayer()

        {

            try

            {

                LocalMapService localMapService = new LocalMapService(@"maps\water-distribution-network.mpk");

                await localMapService.StartAsync();

                ArcGISDynamicMapServiceLayer arcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer()

                {

                    ID = "arcGISDynamicMapServiceLayer",

                    ServiceUri = localMapService.UrlMapService,

                };

                MyMapView.Map.Layers.Add(arcGISDynamicMapServiceLayer);

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

0 Kudos
12 Replies
SachinKanaujia
Occasional Contributor III

What is the exception message that you are getting?

Generally you will not have to start the service Async if you are already adding it to JMap.

Have you tried with the sample mpks that ESRI provides, to know if its a problem with only the mpk you are using? Is it possible for you to share the MPK?

0 Kudos
坤王
by
New Contributor

it don't have exception message. Through the breakpoint debuging,it only perform to  "await localMapService.StartAsync();  "

I give my friend use the project,he can show the map,But i don't.

what is JMap?

mpk download:

https://github.com/Esri/arcgis-runtime-samples-data/tree/master/maps

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

If the awaited call to LocalMapService.StartAsync returns then the service is starting successfully. This would suggest it could be an issue with the map extent not zoomed to the correct area (that water distribution mpk is a very small sample area)?

Cheers

Mike

0 Kudos
坤王
by
New Contributor

Yes,mpk is a very small sample area.How to solve this problem?

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

Do you see anything at all? An esri logo? A gray background grid?

Checking the sample, although it does not explicitly zoom to the extent of the ArcGISDynamicMapServiceLayer, that layer is the only one in the map and the MapView should automatically display. You could add the following lines of code which should force the MapView extent to that of the service. Or you may catch an exception if there is a problem initializing the layer:

await arcGISDynamicMapServiceLayer.InitializeAsync();
await MyMapView.SetViewAsync(new Viewpoint(arcGISDynamicMapServiceLayer.FullExtent));

Additionally, I note that sample does not handle the LayerLoaded event on the MapView. You do this by registering an event handler e.g.

MyMapView.LayerLoaded += MyMapView_LayerLoaded;

And then handling the event:

private void MyMapView_LayerLoaded(object sender, LayerLoadedEventArgs e)
{
  if (e.LoadError != null)
  {
    MessageBox.Show(e.LoadError.Message, "Layer Error");
    return;
  }
}

Or alternatively use the MapView.LayersLoadedAsync awaitable task and check the LayerLoadedResult objects.

Cheers

Mike

0 Kudos
坤王
by
New Contributor

I can see an esri logo,not see a gray background grid.

my code:

using Esri.ArcGISRuntime.Controls;
using Esri.ArcGISRuntime.Layers;
using Esri.ArcGISRuntime.LocalServices;
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;


namespace NavMapAPP
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            CreateLocalServiceAndDynamicLayer();
            MyMapView.LayerLoaded += MyMapView_LayerLoaded;  
        }
        private void MyMapView_LayerLoaded(object sender, LayerLoadedEventArgs e)
        {
            if (e.LoadError != null)
            {
                MessageBox.Show(e.LoadError.Message, "Layer Error");
                return;
            }
        }  
        public async void CreateLocalServiceAndDynamicLayer()
        {
            try
            {
                LocalMapService localMapService = new LocalMapService(@"maps\water-distribution-network.mpk");
                await localMapService.StartAsync();
                ArcGISDynamicMapServiceLayer arcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer()
                {
                    ID = "arcGISDynamicMapServiceLayer",
                    ServiceUri = localMapService.UrlMapService,
                };
                MyMapView.Map.Layers.Add(arcGISDynamicMapServiceLayer);
                await arcGISDynamicMapServiceLayer.InitializeAsync();
                await MyMapView.SetViewAsync(new Viewpoint(arcGISDynamicMapServiceLayer.FullExtent));  
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

run screenshot: program don't show "layer error".

map1.jpg

0 Kudos
NakulManocha
Esri Regular Contributor

If it breaks on the following line then please confirm if the mpk is supported for runtime.

await localMapService.StartAsync();

If it get passed the above line without throwing any exception then please follow the suggestions which Mike provided in his last reply.

If your mpk isn't too big would you mind attaching it here?

0 Kudos
坤王
by
New Contributor
0 Kudos
NakulManocha
Esri Regular Contributor

mpk_water_distribution_network.JPG

As you see above I had no issues loading your mpk. Sorry didn't get chance to reply sooner.

0 Kudos