Offline basemap not loading if internet connection is not available

2580
7
12-28-2016 03:42 AM
NiladriBanerjee
New Contributor

Hi All,

We are having an issue regarding the offline basemap. We are able to download the arcgis online base map in our device. using the code given in this forum,

.NET Xamarin gist to download ArcGIS basemap tiles for offline use. · GitHub 

However after downloading when we are trying to load the  offline map( using the sample code given in this link Offline mapping ideas — Xamarin Forums)  from our local storage and it  is not loading in the background if we switch off the device internet connection. But surprisingly if we switch on the internet the offline map was loading in the background from the local storage. we are using xamarin forms for android to develop the application. Any help concerning this issue will be highly appreciated.

Thanks,

Niladri Banerjee

GIS Developer

0 Kudos
7 Replies
EricBader
Occasional Contributor III

Hi Niladri,

I bet the guys here who work more closely with Xamarin could shed some light on the issue:

https://community.esri.com/community/developers/native-app-developers/arcgis-runtime-sdk-for-net 

ttilton‌ 

0 Kudos
NiladriBanerjee
New Contributor

Thanks Eric.

0 Kudos
ChadYoder1
Occasional Contributor II

Could it be that offline basemap is loading, but you can't see it because of the zoom extent and the LOD's downloaded are not included?

You might want to try creating a new Map, and then loading the offline map. This should reset the extent to the area where the offline map is located.

Post some code that shows your workflow when switching to offline mode and we'll be able to give you some more help.

0 Kudos
NiladriBanerjee
New Contributor

Hi Chad,

Thanks for your reply. Here is the sample code.

try

{

                if (message.SelectedLayers.Count != 0)

                {

 

                    var offlayer = message.SelectedLayers;

 

 

 

 

                    Acr.UserDialogs.UserDialogs.Instance.ShowLoading("Loading Offline Map", Acr.UserDialogs.MaskType.Black);

                    ArcGISTiledLayer layer = await ShowBaseMapsMenuEditMessage.OffLineMap.LoadTileCache("/storage/emulated/0/SmartMaps/" + “FileNameIS.tpk");

 

 

 

 

                    // Create basemap

                    Basemap basemap = new Basemap();

 

                    // Get layers from file

 

 

 

 

                    basemap.BaseLayers.Add(layer);

                    Map = new Map(basemap);

 

                   

 

 

                    if (layer.LoadStatus != Esri.ArcGISRuntime.LoadStatus.Loaded)

                    {

                        Acr.UserDialogs.UserDialogs.Instance.ShowSuccess("Could not load tile cache", 1000);

                    }

 

                    else

                    {

                        Acr.UserDialogs.UserDialogs.Instance.ShowSuccess("Tile cache loaded successfully.", 1000);

 

 

                    }

 

 

 

                }

 

 

 

           

 

            }

            catch (Exception rr)

            {

                Acr.UserDialogs.UserDialogs.Instance.ShowSuccess("Incourrect format", 1000);

 

            }

Thanks,

Niladri

0 Kudos
ChadYoder1
Occasional Contributor II

Looks similar to what I have and I'm able to load an offline basemap.

This code works for me, maybe has to do with creating a new Basemap?  Or, checking the load status to make sure the layer is loaded?

//Create a new map
EsriMapView.Map = new Map();

//Add the basemap
string basemapPath = Path.Combine (model.FullPathSettingsManager.BasemapName);
basemapPath = PathHelpers.CleanPath (basemapPath);
if (System.IO.File.Exists(basemapPath)) {
   var basemapLayer = new ArcGISTiledLayer(new Uri(basemapPath));
   if (basemapLayer.LoadStatus == Esri.ArcGISRuntime.LoadStatus.NotLoaded)
      await basemapLayer.LoadAsync ();
   EsriMapView.Map.Basemap.BaseLayers.Add(basemapLayer);
}

You might also want to reload the map, this occurs at the end of my offline map loading:

//Load the map
await EsriMapView.Map.RetryLoadAsync ();

0 Kudos
ChadYoder1
Occasional Contributor II

Also, have you confirmed the TPK file is valid and has data?  You could open in ArcMap to make sure you can see the tiles.

0 Kudos
AnttiKajanus1
Occasional Contributor III

You could try to use TileCache and see if that makes any difference to you. Btw, I cannot see the code how you are using the TPK

 // Add basemaps to the scene
var tileCacheSmallScale = new TileCache(pathToTheTPKFile);
var tileLayerSmallScale = new ArcGISTiledLayer(tileCacheSmallScale);
var basemap = new Basemap();
basemap.BaseLayers.Add(tileLayer);

Make sure that the TPK file is where you are looking it from. I usually use android device manager to check if it is there and the size is what I'm expecting.

Does the basemap and the tile layer inside it loaded correctly?

0 Kudos