Online-Offline Editing Sample

3563
9
Jump to solution
04-06-2013 01:16 AM
ShiminCai
Occasional Contributor III
Hi there,

When the sample app is taken offline all the line features disappear... Is this the normal behaviour of the app? However, Looking into the code, the offline feature layer is already initialised with the feature layer definition and feature set json "[self initWithLayerDefinitionJSON:featureLayerDefinition featureSetJSON:featureSetDictionary];". Based on the API documentation, this initializer should display/retain the features within the visible extent on offline mode... I need to cache and display all the features in the visible extent upon taking the app offline. How do I achieve this in the sample?

Thanks,

Shimin
0 Kudos
1 Solution

Accepted Solutions
NimeshJarecha
Esri Regular Contributor
Please change following code line in OnlineOfflineFeatureLayer.m and when you go offline, features from visible extent will be available/displayed.

Change
query.spatialRelationship = AGSSpatialRelationshipEnvelopeIntersects;
To
query.spatialRelationship = AGSSpatialRelationshipIntersects;

Hope this helps!

Regards,
Nimesh

View solution in original post

0 Kudos
9 Replies
ShiminCai
Occasional Contributor III
Hi,

Tried the codes below following the [self initWithLayerDefinitionJSON:featureLayerDefinition featureSetJSON:featureSetDictionary]...
//trying to display the features while offline...
NSLog(@"%i", self.graphicsCount);  //the 5 graphics are already there but not showing
AGSFeatureSet *featureSet = [[AGSFeatureSet alloc] initWithJSON:featureSetDictionary];
[self addGraphics:featureSet.features];
NSLog(@"%i", self.graphicsCount); //now the number of graphics are doubled (10), but still now showing...

So the graphics are already in the feature layer but just not drawing on the screen. There must be a setting somewhere that prevents them from drawing on the screen... Any idea?

Thanks,

Shimin
0 Kudos
ShiminCai
Occasional Contributor III
Hi All,

I'm rephrasing my question just for the final try to get any answers if possible...

Is it possible to display features offline in a feature layer that is created and initialised with the initWithLayerDefinitionJSON: featureSetJSON: method in order to edit those features offline? If it's not possible what would be the alternatives? I need to be able to collect new features and edit existing features while offline.

Based on the online-offline sample workflow I'm able to edit features (attributes, geometry & attachments) online. What I also need is to be able to save existing features in the visible extent to devices while online and edit them while offline. Is this possible within the sample workflow?   

Thanks a lot for your help in advance.

Regards,

Shimin
0 Kudos
NimeshJarecha
Esri Regular Contributor
Please change following code line in OnlineOfflineFeatureLayer.m and when you go offline, features from visible extent will be available/displayed.

Change
query.spatialRelationship = AGSSpatialRelationshipEnvelopeIntersects;
To
query.spatialRelationship = AGSSpatialRelationshipIntersects;

Hope this helps!

Regards,
Nimesh
0 Kudos
ShiminCai
Occasional Contributor III
Hi Nimesh,

That's it! The simple spatial query relationship change did the trick!

Many thanks for your help.

Cheers,

Shimin
0 Kudos
HumzaAkhtar
Occasional Contributor II
Hi Nimesh,

That's it! The simple spatial query relationship change did the trick!

Many thanks for your help.

Cheers,

Shimin


Hi,

However if we start the application for the first time when we are offline then the application doesnot load the trail types? right?

Regards
Humza
0 Kudos
ShiminCai
Occasional Contributor III
Hi Humza,

In this case you need to initialise the feature layer from a feature layer definition json file which is created for you when you are online and taking it offline in the tmp directory of the app in the iphone simulator. I copied the FeatureLayerDefinition json file to the Documents directory of my app and always initialize the feature layer with the json file regardless of online or offline...

Hope this helps.

Regards,

Shimin
0 Kudos
HumzaAkhtar
Occasional Contributor II
Hi Humza,

In this case you need to initialise the feature layer from a feature layer definition json file which is created for you when you are online and taking it offline in the tmp directory of the app in the iphone simulator. I copied the FeatureLayerDefinition json file to the Documents directory of my app and always initialize the feature layer with the json file regardless of online or offline...

Hope this helps.

Regards,

Shimin


Thankyou for your reply Shamin

Regards
Humza
0 Kudos
HumzaAkhtar
Occasional Contributor II
Dear Shamin,

Also one more thing, Isnt it better to use NSHomeDirectory() instead of TemporaryDirectory to store my json files because the files get deleted from NSTemporary directory? if the app is getting an offline start then NSHomeDirectory would be a better choice right?

Thanks
Humza
0 Kudos
ShiminCai
Occasional Contributor III
Hi Humza,

I include the feature layer definition files in my app's bundle. When my app launches I copy the files to the app's Documents directory and then read the definitions from there to initialize the feature layers. The reason putting the files in the app's Documents directory is that should any of the definition changes I could use iTunes file sharing to update the files without having to recompile the app...

Cheers,

Shimin

@implementation FCNSWGISAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    //an example of the definition file name: lineFeatureLayerDefinition.json
    [FCNSWUtils copyFileInBoundleToDocumentsFolder:lineFeatureLayerDefinitionJsonFile withExtension:lineFeatureLayerDefinitionJsonFileExtension];
    [FCNSWUtils copyFileInBoundleToDocumentsFolder:pointFeatureLayerDefinitionJsonFile withExtension:pointFeatureLayerDefinitionJsonFileExtension];
    [FCNSWUtils copyFileInBoundleToDocumentsFolder:polygonFeatureLayerDefinitionJsonFile withExtension:polygonFeatureLayerDefinitionJsonFileExtension];
   
    return YES;
}


@implementation FCNSWUtils

+(NSString *) documentsPath
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return documentsDirectory;
}

+(void) copyFileInBoundleToDocumentsFolder:(NSString *)fileName withExtension:(NSString *)extension
{
    NSString *documentDirectory = [self documentsPath];
    NSString *filePath = [documentDirectory stringByAppendingPathComponent:[NSString stringWithString:fileName]];
    filePath = [filePath stringByAppendingString:@"."];
    filePath = [filePath stringByAppendingString:extension];
   
    //check if file is already in Documents folder
    //if not, copy it from the bundle.
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if(![fileManager fileExistsAtPath:filePath])
    {
        //get the path of the file in the bundle
        NSString *pathToFileInBundle = [[NSBundle mainBundle] pathForResource:fileName ofType:extension];
       
        //copy the file in the bundle to the Documents folder
        NSError *error = nil;
        bool success = [fileManager copyItemAtPath:pathToFileInBundle toPath:filePath error:&error];
        if(success)
        {
            NSLog(@"File copied from bundle to Documents.");
        }
        else
        {
            NSLog(@"%@", [error localizedDescription]);
        }
    }
}
0 Kudos