I get that I probable need to use MobileMapPackageUtility.unpack(), but the details of how you'd actually do that to display the package as the background layer within a Map escape me, and I don't see an example that does this. Thanks!
something along these lines should do the trick:
<SPAN class="keyword token">function</SPAN> <SPAN class="token function">unpackMmpk</SPAN><SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// once the unpack status is complete, add the mmpk</SPAN> MobileMapPackageUtility<SPAN class="punctuation token">.</SPAN>unpackStatusChanged<SPAN class="punctuation token">.</SPAN><SPAN class="token function">connect</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>MobileMapPackageUtility<SPAN class="punctuation token">.</SPAN>unpackStatus <SPAN class="operator token">===</SPAN> Enums<SPAN class="punctuation token">.</SPAN>TaskStatusCompleted<SPAN class="punctuation token">)</SPAN> <SPAN class="token function">addMmpk</SPAN><SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// unpackge the mmpk</SPAN> MobileMapPackageUtility<SPAN class="punctuation token">.</SPAN><SPAN class="token function">unpack</SPAN><SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="token function">addMmpk</SPAN><SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// create the mmpk and set the path</SPAN> <SPAN class="keyword token">var</SPAN> mobileMapPackage <SPAN class="operator token">=</SPAN> ArcGISRuntimeEnvironment<SPAN class="punctuation token">.</SPAN><SPAN class="token function">createObject</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MobileMapPackage"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> mobileMapPackage<SPAN class="punctuation token">.</SPAN>path <SPAN class="operator token">=</SPAN> path<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// wait for the package to load</SPAN> mobileMapPackage<SPAN class="punctuation token">.</SPAN>loadStatusChanged<SPAN class="punctuation token">.</SPAN><SPAN class="token function">connect</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>mobileMapPackage<SPAN class="punctuation token">.</SPAN>loadStatus <SPAN class="operator token">===</SPAN> Enums<SPAN class="punctuation token">.</SPAN>LoadStatusLoaded<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// set the mapview's map to the first map in the package</SPAN> mapView<SPAN class="punctuation token">.</SPAN>map <SPAN class="operator token">=</SPAN> mobileMapPackage<SPAN class="punctuation token">.</SPAN>maps<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// load the mmpk</SPAN> mobileMapPackage<SPAN class="punctuation token">.</SPAN><SPAN class="token function">load</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Lucas Danzinger Thanks! I will give this a try tomorrow and let you know if I have any issues. Appreciate the rapid reply.
Lucas Danzinger A few questions. I'm using this code:
MapView { id: mapView anchors.fill: parent focus: true Map { id: map BasemapTopographic{} } function unpackMmpk(path, outputDirectory) { // once the unpack status is complete, add the mmpk MobileMapPackageUtility.unpackStatusChanged.connect(function() { if (MobileMapPackageUtility.unpackStatus === Enums.TaskStatusCompleted) { console.log("unpacked mmpk"); addMmpk(path); } else if (MobileMapPackageUtility.unpackStatus === Enums.TaskStatusErrored) { console.log("unpacking TaskStatusErrored"); } }); console.log("unpacking mmpk"); // unpackage the mmpk MobileMapPackageUtility.unpack(path, outputDirectory); } function addMmpk(path) { console.log("adding mmpk"); // create the mmpk and set the path var mobileMapPackage = ArcGISRuntimeEnvironment.createObject("MobileMapPackage"); mobileMapPackage.path = path; // wait for the package to load mobileMapPackage.loadStatusChanged.connect(function() { if (mobileMapPackage.loadStatus === Enums.LoadStatusLoaded) { // set the mapview's map to the first map in the package mapView.map = mobileMapPackage.maps[0]; } }); // load the mmpk mobileMapPackage.load(); } Component.onCompleted: { unpackMmpk("/tmp/goldstream_valley.mmpk", "/tmp/unpacked") } } <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
MobileMapPackageUtility.unpack() requires the mmpk file as the first argument and the directory to unpack as the second, so I updated that. I also added a test to see if there's an error unpacking.
When I run this, I see "unpacking mmpk" in the logs, it never reaches "unpacked mmpk" or "adding mmpk", but it does hit the "unpacking TaskStatusError" section. But I don't know what might be going wrong. The "unpacked" directory exists and I can write to it, and the mmpk file unzips just fine with the Unix "unzip" utility.
Any suggestions as to what I might be doing wrong or how to have it show me the error? Once I get it unpacked, I'm wondering whether I need to pass the unpack directory to the addMmpk() function rather than the mmpk file itself.
Finally, all I'm really trying to do is get a TIF image as the background for my map. Is there a simpler way to accomplish this? It seems like a lot of work to create a mobile map package of a TIF, then have the application unpack it back into a TIF again for display.
Thanks!
I'm getting closer. I think the error in unpacking was because I wasn't using "file:/// ..." links in the unpack() function. Now that I am, the mmpk successfully unpacks into the directory I specify. But nothing loads. I'm passing the unpacked directory path to the addMmpk() function (which sets mobileMapPackage.path to the unpacked directory), but it doesn't load when I do that. When I check loadStatusChanged, it reports Enums.LoadStatusLoaded but the space where the imagery should be is grey. I've checked the TIF that's in the unpacked/commondata/raster_data/ subdirectory and it displays fine in GIS software. It's EPSG:26906. Does that matter? Should I transform the raster to EPSG:3857 first?
I also notice that after the first time I run the application I get a TaskStatusErrored status from unpack(), which I gather is because the mmpk is already unpacked. How do I handle that?
I'm out of ideas. For what it's worth, the mobile map packages I've tried are here: https://seafile.abrinc.com/d/bd9ed1edfc5a47e39d26/
The one without an SRID in the name is the one with the original TIF and original projection in it (EPSG:26906).
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.