No Network, load from local geodatabase

1320
3
Jump to solution
05-20-2014 12:38 PM
VIKRANTKRISHNA
New Contributor III
I am struggling to build the logic for relaunching the application (or initializing) from local geodatabase layers, when app got crashed or closed for some reason with no network availability.

I will really appreciate any help with this?
0 Kudos
1 Solution

Accepted Solutions
ShiminCai
Occasional Contributor III
Hi, my app always starts up offline if a local geodatabase exists. My local geodatabase is in the app's Documents folder and it loads local data or live data in the viewDidLoad method. Hope it helps. Regards, Shimin.

@property (nonatomic, strong) AGSGDBGeodatabase *geodatabase;

//in the viewDidLoad
NSString *gdbFilePath = [[FCNSWUtils documentsPath] stringByAppendingPathComponent:@"MyLocalDB.geodatabase"];
    if([FCNSWUtils fileExist:gdbFilePath])
    {
        [self loadLocalData];
    }
    else
    {
        [self takeOnline];//load live data.
    }

-(void)loadLocalData
{
   
    NSString *gdbFilePath = [[FCNSWUtils documentsPath] stringByAppendingPathComponent:@"MyLocalDB.geodatabase"];
    AGSGDBGeodatabase *gdb = [[AGSGDBGeodatabase alloc]initWithPath:gdbFilePath error:nil];
    self.geodatabase = gdb;
   
    ////Remove all live feature layers if any
    for (AGSLayer* lyr in self.mapView.mapLayers)
    {
        if([lyr isKindOfClass:[AGSFeatureLayer class]])
        {
            [self.mapView removeMapLayer:lyr];
        }
    }
   
    //Add local feature/table layers
    for (AGSFeatureTable* fTable in self.geodatabase.featureTables)
    {
        if ([fTable hasGeometry])
        {
            AGSFeatureTableLayer *ftl = [[AGSFeatureTableLayer alloc]initWithFeatureTable:fTable];
            ftl.delegate = self;
           
            [self.mapView addMapLayer:ftl];
        }
    }
   
    [self showEditsInGeodatabaseAsBadge:self.geodatabase];
  
}

View solution in original post

0 Kudos
3 Replies
ShiminCai
Occasional Contributor III
Hi, my app always starts up offline if a local geodatabase exists. My local geodatabase is in the app's Documents folder and it loads local data or live data in the viewDidLoad method. Hope it helps. Regards, Shimin.

@property (nonatomic, strong) AGSGDBGeodatabase *geodatabase;

//in the viewDidLoad
NSString *gdbFilePath = [[FCNSWUtils documentsPath] stringByAppendingPathComponent:@"MyLocalDB.geodatabase"];
    if([FCNSWUtils fileExist:gdbFilePath])
    {
        [self loadLocalData];
    }
    else
    {
        [self takeOnline];//load live data.
    }

-(void)loadLocalData
{
   
    NSString *gdbFilePath = [[FCNSWUtils documentsPath] stringByAppendingPathComponent:@"MyLocalDB.geodatabase"];
    AGSGDBGeodatabase *gdb = [[AGSGDBGeodatabase alloc]initWithPath:gdbFilePath error:nil];
    self.geodatabase = gdb;
   
    ////Remove all live feature layers if any
    for (AGSLayer* lyr in self.mapView.mapLayers)
    {
        if([lyr isKindOfClass:[AGSFeatureLayer class]])
        {
            [self.mapView removeMapLayer:lyr];
        }
    }
   
    //Add local feature/table layers
    for (AGSFeatureTable* fTable in self.geodatabase.featureTables)
    {
        if ([fTable hasGeometry])
        {
            AGSFeatureTableLayer *ftl = [[AGSFeatureTableLayer alloc]initWithFeatureTable:fTable];
            ftl.delegate = self;
           
            [self.mapView addMapLayer:ftl];
        }
    }
   
    [self showEditsInGeodatabaseAsBadge:self.geodatabase];
  
}
0 Kudos
VIKRANTKRISHNA
New Contributor III
But How about localTileLayer?, Is it possible to store AGSLocalTiledLayer in the geodatabase as well?
0 Kudos
VIKRANTKRISHNA
New Contributor III
I found the solution Thanks, It generated tpk on device as well!!
0 Kudos