Map Mobile package basemap in uwp app

504
5
05-15-2020 09:15 AM
urveshshaikh
New Contributor

Hi, I am new to ArcGIS development. I am trying to open map mobile package mmpk in uwp .net application. I have loaded the package in the map and I can see all the layers. Basemap is not part of mmpk package. I am unable to figure out how to display basemap with mmpk in UWP app. Can you help?

Tags (1)
0 Kudos
5 Replies
Nicholas-Furness
Esri Regular Contributor

To add to Mike's documentation links…

Once you have the Map from the Mobile Map Package, it will have a Basemap property (it sounds like that will be unset). Look at the Basemap class and the factory methods on it (e.g. CreateNavigationVector or CreateImageryWithLabels) which will give you a Basemap object you can set on your Map's Basemap property.

To be safe, since I don't know what the content of your MMPK is, I would recommend setting the Basemap on the Map before you display the Map in the MapView*.

Hope this helps,

Nick.

* Technically, before the Map is "loaded". See here if you need to learn more about what this means in Runtime, but chances are you won't have to. When the map is "loaded" (not the same as reading it from the MMPK), its contents determine the Map's Spatial Reference and this is done by first inspecting the basemap.

0 Kudos
urveshshaikh
New Contributor

Thanks for the response. As you mentioned I tried codes below. I am still unable to view basemap.

1. StorageFolder folder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Pole");

StorageFile f = await folder.GetFileAsync("mmm.mmpk");

MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync(f.Path);

Basemap b = Basemap.CreateImageryWithLabels();

myMapPackage.Maps.First().Basemap = b;

MyMapView.Map = myMapPackage.Maps.First();

2. StorageFolder folder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Pole");

StorageFile f = await folder.GetFileAsync("mmm.mmpk");

MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync(f.Path);

Basemap b = Basemap.CreateStreetsVector();

MyMapView.Map = myMapPackage.Maps.First();

MyMapView.Map.Basemap = b;

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Thanks for sharing your MMPK. That helped. Your map has a spatial reference of WGS 84.

Your solution is to do this:

  1. Go to this page and pick a WGS84 basemap.
  2. On the Basemap's item page, pick out the GUID from the URL (e.g. 02b1f120c3674bfe896ac81731be1739 for https://www.arcgis.com/home/item.html?id=02b1f120c3674bfe896ac81731be1739 )
  3. Create a Basemap from a Portal Item using that ID with code like this, setting it on the map from the MMPK, then setting the map on the map view:
    try
    {
        MobileMapPackage myMapPackage = await MobileMapPackage.OpenAsync("");
        if (myMapPackage.LoadStatus != LoadStatus.Loaded && myMapPackage.LoadError != null)
        {
            //TODO
        }
        ArcGISPortal arcGISPortal = await ArcGISPortal.CreateAsync();
        PortalItem portalItem = await PortalItem.CreateAsync(arcGISPortal, "02b1f120c3674bfe896ac81731be1739");
        Basemap basemap = new Basemap(portalItem);
        Map map = myMapPackage.Maps.First();
        map.LoadStatusChanged += Map_LoadStatusChanged;
        map.Basemap = basemap;
        MyMapView.Map = map;
    }
    catch (Exception) { throw; }

Our default basemaps that you create from our Basemap factory methods are spatial reference Web Mercator. The map that is obtained from the MMPK already has its spatial reference set (which I did not expect, but it turns out that's the case with maps from an MMPK).

Hope this helps (thanks Michael Branscomb‌ for the .NET code!)

0 Kudos
urveshshaikh
New Contributor

I tried the code. It's working perfectly. Thank you so much.

0 Kudos