Unable to view .mpkx file downloaded from Arcgis Pro 2.8

387
7
Jump to solution
07-12-2021 08:49 AM
SalmanSaleh
New Contributor II

Hi, I have learned from tutorials to load sample "PointsofInterest.mpkx" in arcgis runtime 100.10. Now I have created my own sample map in arcgis pro which uses satellite imagery. I exported that map named "newdha2map.mpkx" after enabling support for arcgis runtime.

However, I encounter this exception each time after running the application.

Please help.

 

 

Exception:
{"Failed to create service newdha2map MapServer. Service failed to initialize: Error unpacking map package hr=0x80004005 (No ErrorInfo)"}

 

 

Source Code:

Map = new Map(BasemapStyle.ArcGISTopographic);

// Create a local map service from a map package on disk.
LocalMapService pointsOfInterestMapService = new LocalMapService(@"..\Data\newDHA2Map.mpkx");

try
{
// Start the local service.
await pointsOfInterestMapService.StartAsync();
}
catch (InvalidOperationException invalidOpEx)
{
// Thrown if LocalService is already in Started state.
// TODO
}
catch (LocalServerException localServerEx)
{
// Thrown if deployment license level does not meet minimum required.
// TODO
}
catch (Exception ex)
{
// Thrown if error encountered starting service.
// TODO
}

// If the service did not start handle error and return.
if (pointsOfInterestMapService.Error != null || pointsOfInterestMapService.Status != LocalServerStatus.Started)
{
// TODO
return;
}

// Create a new ArcGISMapImageLayer.
ArcGISMapImageLayer pointsOfInterestmapImageLayer = new ArcGISMapImageLayer(pointsOfInterestMapService.Url);

// Add the layer to the map.
Map.OperationalLayers.Add(pointsOfInterestmapImageLayer);

 

 

Map download Link (gdrive):

https://drive.google.com/file/d/1Gyik5MDD4SIXf6Ic2y5z2kztx9u1wG9D/view?usp=sharing

0 Kudos
1 Solution

Accepted Solutions
MichaelBranscomb
Esri Frequent Contributor

You need to create an ArcGISMapImageLayer from the LocalMapService then add that layer to the Map.OperationalLayers collection.

Also, you should either await the layer's .LoadAsync method, or handle the LoadStatusChanged event to check for any errors. 

The following resources will help:

https://developers.arcgis.com/net/wpf/api-reference/html/T_Esri_ArcGISRuntime_Mapping_ArcGISMapImage... 

https://developers.arcgis.com/net/wpf/sample-code/local-server-map-image-layer/

https://developers.arcgis.com/net/local-server/using-local-server-services/

 

View solution in original post

7 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi,

I've downloaded the map package you shared and have reproduced the issue. Investigating...

Thanks

MichaelBranscomb
Esri Frequent Contributor

Hi,

The problem with the map package (.mpkx) in this case is the online basemap layers. ArcGIS Runtime Local Server doesn't support online services through packages. Online services should be added to the application directly via the API . You can use the basemap constructor and basemapstyle enum, or work with specific layer types vector tile layer or image tiled layer.

Alternatively, ArcGIS Runtime actually supports raster data directly without needing to use the Local Server component. We recommend using Mobile Map Packages (.mmpk) and using those within ArcGIS Runtime. This workflow will also support referencing those online basemap layers. See the Open mobile map package  sample and ArcGIS Pro topic Share a mobile map package for more information.

Thanks

SalmanSaleh
New Contributor II

Hi, Thankyou for your response.

I figured it out that error was related to path of my map file.

I have managed to load my local mpkx layers in online basemap using local server.
As per my requirement, I need to view local basemap stored in my computer (using local server only) however I m unable to do so.  Can you please tell me how can I resolve this issue.  I have tried to follow some tutorials but to no avail.

Code:

private Esri.ArcGISRuntime.LocalServices.LocalServer _localServer = Esri.ArcGISRuntime.LocalServices.LocalServer.Instance;
await _localServer.StartAsync();
LocalMapService mapService = new LocalMapService(@"C:\Users\...\worldmap1.mpkx");
Uri mapServiceUrl = mapService.Url;
MainMapView.Map = new Map(mapServiceUrl);

//If I change this line to "new Map (Basemap.CreateDarkGrayCanvasVector) I m able to view local layers added later on.

Lastly, I have exported my offline map from arcgis pro 2.8 after enabling support for arcgis runtime. I have tested them in arcgis pro as well.

Thank you.

0 Kudos
SalmanSaleh
New Contributor II
0 Kudos
MichaelBranscomb
Esri Frequent Contributor

You need to create an ArcGISMapImageLayer from the LocalMapService then add that layer to the Map.OperationalLayers collection.

Also, you should either await the layer's .LoadAsync method, or handle the LoadStatusChanged event to check for any errors. 

The following resources will help:

https://developers.arcgis.com/net/wpf/api-reference/html/T_Esri_ArcGISRuntime_Mapping_ArcGISMapImage... 

https://developers.arcgis.com/net/wpf/sample-code/local-server-map-image-layer/

https://developers.arcgis.com/net/local-server/using-local-server-services/

 

View solution in original post

SalmanSaleh
New Contributor II

Thanks a lot 🙂
I have now managed to achieve this functionality in arcgis runtime.

One thing more, if someone is adding multiple operational layers then make sure they have same spatial reference and are in the same extent range.

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

In ArcGIS Runtime most layer types that you add to the operational layers collection will re-project on-the-fly, either ArcGIS Runtime performs the reprojection or the reprojection may be done server-side in the case of map image layers (including from Local Server). But it is good practice to avoid having layers with different spatial references since reprojection inevitably incurs an overhead somewhere.

Information about the ability of specific layer types to be re-projected is included in the API reference: https://developers.arcgis.com/net/wpf/api-reference/html/T_Esri_ArcGISRuntime_Mapping_Layer.htm