Attachment Support

The offline-edit-advanced-min.js has support for attachments in offline mode. See attachments-editor.html sample.

What you can do:

While your application is in OFFLINE mode, you can:

How you do use it:

You can either use the ArcGIS FeatureLayer API (esri.layers.FeatureLayer) directly or use the AttachmentEditor widget that supports feature attachment editing. Both approaches work well, and the code you write works the same either if you are on ONLINE or OFFLINE modes.

The only differences in your code are:

You can also modified the database’s name and object store name. This functionality is typically used for advanced users that have a requirement to run multiple databases:

        var offlineEdit = new O.esri.Edit.OfflineEditAdvanced();
        offlineEdit.ATTACHMENTS_DB_NAME = "attachment-store-two";
        offlineEdit.ATTACHMENTS_DB_OBJECTSTORE_NAME = "attachments-two";
        
        offlineEdit.initAttachments(function(success, error){ . . . });

Using the FeatureLayer API

The FeatureLayer API for handling attachments consists primarily of four methods. In general you should let OfflineEditAdvanced handle interactions with attachments and it’s not recommended to interact with the attachments database directly.

They work the same both in ONLINE and OFFLINE mode. In OFFLINE mode, attachments will be kept in the local database (indexeddb) and sent back to the server when you call offlineEdit.goOnline()

Getting database usage

Once a feature layer is extended you can find out how big the database and how many attachments are stored by using the following pattern:

		layer.getAttachmentsUsage(function(usage, error) {
			console.log("Size: " + usage.sizeBytes + ", attachmentCount: " + usage.attachmentCount);
		});

Resetting the database

Under certain circumstances you may want to force the database to delete everything.

		layer.resetAttachmentsDatabase(function(result, error) { 
			console.log("Reset succes: " + result); // result is a boolean
		});

Using the AttachmentEditor widget

The AttachmentEditor is not very fancy, but it’s easy to work with:

            map.infoWindow.setContent("<div id='content' style='width:100%'></div>");
            map.infoWindow.resize(350,200);
            var attachmentEditor = new AttachmentEditor({}, dom.byId("content"));
            attachmentEditor.startup();

            featureLayer.on("click", function(evt) 
            {
                var event = evt;
                var objectId = evt.graphic.attributes[featureLayer.objectIdField];
                map.infoWindow.setTitle(objectId);
                attachmentEditor.showAttachments(event.graphic,featureLayer);
                map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));
            });

The widget internally uses the FeatureLayer API, and it works well in OFFLINE mode.

Limitations

Attachment support in OFFLINE mode has some limitations: