Offline TPK viewer in a Flex Mobile Application
In this post I will demonstrate how to write a Flex mobile application that displays a map with a tiled layer, where the tile source is the unpacked content of a tpk file. A tile package or tpk is generated using ArcMap and is a zip file that contains a couple of configuration files holding tile metadata and a set of ISAM files where the variable length files contain the tile images. The mobile application enables a user to download one or more tpk files from a web server to the local storage and disconnect from the “network” for offline viewing. When the user selects a local tpk, it will be unpacked and a map will render a tiled layer whose tile source is the local file unpacked images, enabling the user to zoom in and out and pan over the available levels as defined in the metadata file. This is possible due to the availability of the ByteArray class in AS3 and the capability to read and write binary files. The application is based on the Holistic Framework and is linked with the fast airzip library and the ArcGIS API for Flex. The TPKLayer in the map view is a subclass of the Esri TiledMapServiceLayer class where the getTileURL function is overridden to return a URLRequest instance with a custom ‘data’ scheme. This ‘data’ scheme informs the super class that the tile data is in a byte array referenced by the URLRequest instance ‘data’ property. In the TPKLayer, the getTileURL is invoked with a level, a row and a column value that are used to seek using the File API to a specific location to read the binary image at that location into a byte array. Using an iOS deployment, a user can drag and drop a tpk file onto the application's iTunes document folder for a later sync. This is possible due to the UIFileSharingEnabled declaration in the xml application manifest (CaheApp-app.xml). Like usual, all the source code is available, and you can download it from here. BTW, I was able to build the app using FlashBuilder 4.6 and the ArcGIS API 2.5 and upcoming 3.0 for Flex without issues. Have fun and keep me posted on your implementations.




Comments
Is that an ESRI Flex API 2.5 specific thing? In the 2.4 API I got some sort of security error about trying to script the browser.
Really great work here. Thanks so much for sharing.
And thanks for getting back into the blogging spirit, 3 posts this week is awesome!
And thanks for getting back into the blogging spirit, 3 posts this week is awesome!
Is there a size limit on the tpk. Hav e you run into any memory issues unpacking the tpk files?
Thanks,
Jeremy
Is there a size limit on the tpk. Hav e you run into any memory issues unpacking the tpk files?
Thanks,
Jeremy
Thanks:
Mobile Application Development
There appears to be a problem with how the code builds the path to the bundles. When I get to detail level 18, it stops working. When I trace it out, I see that the path it is building for the row and column is incorrect. The functions in question are buildCacheFilePath and toHexString. It appears to trim off a necessary character. The path it builds for me is, Inspection/v101/Layers/_alllayers/L18/R1758CB500. But the actual path is, Inspection/v101/Layers/_alllayers/L18/R17580Cb500. It is trimming the last 0 off the row.
Casey
return text.substr(0, 4);
and used
return text;
I have not had any problems so far, but I assume you were trimming it down to 4 characters for a reason. I just haven't found that reason yet.
http://www.webmapsolutions.com/offline-editing-mobile-arcgis
--Rory
1. Open up the TPKLayer.as file.
2. Find the function toHexString(value:int):Object
3. Change the bottom return line to:
return text.substr(0, text.length);
That will solve your woes. Let me know if that works for you.
Thanks,
Steve
but I got two errors while trying to build the project in Flash Builder 4.6:
- Could not resolve to a component implementation. in Registry.mxml
- Multiple markers at this line:
-1023: Incompatible override.
-public
overridescom.esri.ags.Map.staticLayer
in SnapMap.as : Line 26
Regards