udpate samples

This commit is contained in:
Andy Gup 2015-11-23 10:31:12 -07:00
parent 93b4b27d2d
commit 0b1df1d9fc
7 changed files with 90 additions and 90 deletions

View File

@ -194,7 +194,7 @@
var _listener;
// Variables for editing handling
var currentFeature, busStopFeatureLayer = null, offlineFeaturesManager = null;
var currentFeature, busStopFeatureLayer = null, offlineEdit = null;
var pendingEdits = document.getElementById("span-pending-edits");
var imgOfflineIndicator = document.getElementById("state-span");
var btnState = document.getElementById("btn-state");
@ -337,7 +337,7 @@
// Extend the feature layer with offline capabilities.
//
initOfflineFeaturesMgr();
initOfflineEdits();
// If app is online then we ONLY need to extend the feature layer.
if(_isOnline){
@ -357,7 +357,7 @@
}
});
}
// If the app is offline then we need to retrieve the dataStore from OfflineFeaturesManager
// If the app is offline then we need to retrieve the dataStore from OfflineEditAdvanced
// and then extend the feature layer using that information.
else {
loadFeatureLayerOffline(function(success) {
@ -403,7 +403,7 @@
* Load the feature while offline using information stored in database
*/
function loadFeatureLayerOffline(callback) {
offlineFeaturesManager.getFeatureLayerJSONDataStore(function(success,dataStore) {
offlineEdit.getFeatureLayerJSONDataStore(function(success,dataStore) {
if(success){
// Use the feature layer returns from getFeatureDefinition() to reconstitute the layer
@ -446,26 +446,26 @@
* **********************************************
*/
function initOfflineFeaturesMgr(callback) {
offlineFeaturesManager = new O.esri.Edit.OfflineFeaturesManagerAdvanced();
function initOfflineEdits() {
offlineEdit = new O.esri.Edit.OfflineEditAdvanced();
// IMPORTANT!!!
// This tells the database which graphic.attribute property to use as a unique identifier
// You can look this information up in your feature service directory under the "Fields" category.
// Example: http://services1.arcgis.com/M8KJPUwAXP8jhtnM/arcgis/rest/services/Denver_Bus_Stops/FeatureServer/0
offlineFeaturesManager.DB_UID = "FID";
offlineEdit.DB_UID = "FID";
// IMPORTANT!!!
// A proxy page may be required to upload attachments.
// If you are using a CORS enabled feature service you can ignore this.
// If your feature service is not CORS-enabled then you will need to configure this.
// Refer to "Using the Proxy Page" for more information: https://developers.arcgis.com/en/javascript/jshelp/ags_proxy.html
offlineFeaturesManager.proxyPath = null;
offlineEdit.proxyPath = null;
offlineFeaturesManager.on(offlineFeaturesManager.events.EDITS_ENQUEUED, updateStatus);
offlineFeaturesManager.on(offlineFeaturesManager.events.EDITS_SENT, updateStatus);
offlineFeaturesManager.on(offlineFeaturesManager.events.ALL_EDITS_SENT, updateStatus);
offlineFeaturesManager.on(offlineFeaturesManager.events.EDITS_SENT_ERROR, editsError);
offlineEdit.on(offlineEdit.events.EDITS_ENQUEUED, updateStatus);
offlineEdit.on(offlineEdit.events.EDITS_SENT, updateStatus);
offlineEdit.on(offlineEdit.events.ALL_EDITS_SENT, updateStatus);
offlineEdit.on(offlineEdit.events.EDITS_SENT_ERROR, editsError);
}
function extendFeatureLayer(online,callback){
@ -484,19 +484,19 @@
}
// NOTE: if app is offline then we want the dataStore object to be null
offlineFeaturesManager.extend(busStopFeatureLayer,function(result, error) {
offlineEdit.extend(busStopFeatureLayer,function(result, error) {
if(result) {
console.log("offlineFeaturesManager initialized.");
console.log("OfflineEditAdvanced initialized.");
// This sets listeners to detect if the app goes online or offline.
Offline.on('up', goOnline);
Offline.on('down', goOffline);
// If the app is online then force offlineFeaturesManager to its online state
// If the app is online then force OfflineEditAdvanced to its online state
// This will force the library to check for pending edits and attempt to
// resend them to the Feature Service.
if(_isOnline){
offlineFeaturesManager.goOnline(function(result){
offlineEdit.goOnline(function(result){
if(!result.success){
alert("There was a problem when attempting to go back online.");
}
@ -506,7 +506,7 @@
});
}
else {
offlineFeaturesManager.goOffline();
offlineEdit.goOffline();
updateStatus();
}
@ -672,7 +672,7 @@
*/
/**
* Forces offlineFeaturesManager to go online.
* Forces OfflineEditAdvanced to go online.
* When invoking featureLayer.goOnline() we force library to sync any edits that were
* stored while offline.
*/
@ -685,10 +685,10 @@
}
offlineFeaturesManager.goOnline(function(success,error) {
offlineEdit.goOnline(function(success,error) {
if(error === undefined) {
setUIOnline();
console.log("offlineFeatureManager is online.");
console.log("OfflineEditAdvanced is online.");
}
else {
alert("There was a problem syncing offline edits: " + JSON.stringify(error));
@ -702,20 +702,20 @@
}
/**
* Forces offlineFeaturesManager offline
* Forces OfflineEditAdvanced offline
*/
function goOffline() {
console.log("Going offline...");
setUIOffline();
offlineFeaturesManager.goOffline();
offlineEdit.goOffline();
if(typeof tileLayer != "undefined") tileLayer.goOffline();
}
/**
* Toggles offlineFeaturesManager online/offline
* Toggles offlineEdit online/offline
*/
function goOnlineOffline() {
if(offlineFeaturesManager.getOnlineStatus() == offlineFeaturesManager.ONLINE){
if(offlineEdit.getOnlineStatus() == offlineEdit.ONLINE){
goOffline();
}
else{

View File

@ -1,6 +1,6 @@
CACHE MANIFEST
# This manifest was generated by grunt-manifest HTML5 Cache Manifest Generator
# Time: Fri Nov 20 2015 18:10:55 GMT-0700 (MST)
# Time: Mon Nov 23 2015 09:22:04 GMT-0700 (MST)
CACHE:
#manifest-generator,version:3.0.0

View File

@ -182,7 +182,7 @@
"esri/graphic","esri/geometry/Extent", "esri/SpatialReference",
"//esri.github.io/bootstrap-map-js/src/js/bootstrapmap.js",
"../dist/offline-tiles-advanced-src.js",
"../dist/offline-edit-src.js",
"../dist/offline-edit-advanced-src.js",
"dojo/domReady!"],
function(Map,FeatureLayer,
SimpleRenderer,SimpleMarkerSymbol,Color,Query,
@ -193,7 +193,7 @@
var defaultSymbol, bStationSymbol;
// Variables for editing handling
var busStopFeatureLayer = null, offlineFeaturesManager = {};
var busStopFeatureLayer = null, offlineEdit = {};
var bicycleStationFeatureLayer = null;
var imgOfflineIndicator = document.getElementById("state-span");
var btnState = document.getElementById("btn-state");
@ -309,11 +309,11 @@
listener1 = busStopFeatureLayer.on("update-end",function(event){
listener1.remove();
if(!offlineFeaturesManager.hasOwnProperty("ONLINE")){
initOfflineFeaturesMgr();
if(!offlineEdit.hasOwnProperty("ONLINE")){
initOfflineEdits();
}
offlineFeaturesManager.extend(busStopFeatureLayer,function(result, error) {
offlineEdit.extend(busStopFeatureLayer,function(result, error) {
if(result){
deferred1.resolve(true);
map.addLayer(bicycleStationFeatureLayer);
@ -335,11 +335,11 @@
listener2 = bicycleStationFeatureLayer.on("update-end",function(event){
listener2.remove();
if(!offlineFeaturesManager.hasOwnProperty("ONLINE")){
initOfflineFeaturesMgr();
if(!offlineEdit.hasOwnProperty("ONLINE")){
initOfflineEdits();
}
offlineFeaturesManager.extend(bicycleStationFeatureLayer,function(result, error) {
offlineEdit.extend(bicycleStationFeatureLayer,function(result, error) {
if(result){
deferred2.resolve(true);
}
@ -366,7 +366,7 @@
// This is just an example of what you would do if you had stored edits!
console.log("Application is online...attempting to send any stored edits.");
offlineFeaturesManager.goOnline(function(result){
offlineEdit.goOnline(function(result){
if(!result.success){
alert("There was a problem when attempting to go back online.");
}
@ -376,7 +376,7 @@
});
}
else {
offlineFeaturesManager.goOffline();
offlineEdit.goOffline();
}
callback();
@ -424,11 +424,11 @@
*/
function loadFeatureLayerOffline(callback) {
initOfflineFeaturesMgr();
initOfflineEdits();
var promises = [];
offlineFeaturesManager.getFeatureCollections(function(success,dataStore) {
offlineEdit.getFeatureCollections(function(success,dataStore) {
if(success){
var deferred1 = new Deferred();
@ -459,7 +459,7 @@
_listener1 = busStopFeatureLayer.on("update",function(evt){
_listener1.remove();
offlineFeaturesManager.extend(busStopFeatureLayer,function(success, error){
offlineEdit.extend(busStopFeatureLayer,function(success, error){
if(success){
console.log("busStopFeatureLayer successfully extended offline");
deferred1.resolve(true);
@ -495,7 +495,7 @@
_listener2 = bicycleStationFeatureLayer.on("update",function(evt){
_listener2.remove();
offlineFeaturesManager.extend(bicycleStationFeatureLayer,function(success, error){
offlineEdit.extend(bicycleStationFeatureLayer,function(success, error){
if(success){
console.log("bicycleStationFeatureLayer successfully extended offline");
deferred2.resolve(true);
@ -533,25 +533,25 @@
* **********************************************
*/
function initOfflineFeaturesMgr() {
console.log("Initializing OfflineFeaturesManager");
offlineFeaturesManager = new O.esri.Edit.OfflineFeaturesManager();
function initOfflineEdits() {
console.log("Initializing OfflineEditAdvanced");
offlineEdit = new O.esri.Edit.OfflineEditAdvanced();
// IMPORTANT!!!
// This tells the database which graphic.attribute property to use as a unique identifier
// You can look this information up in your feature service directory under the "Fields" category.
// Example: http://services1.arcgis.com/M8KJPUwAXP8jhtnM/arcgis/rest/services/Denver_Bus_Stops/FeatureServer/0
offlineFeaturesManager.DB_UID = "FID";
offlineEdit.DB_UID = "FID";
// We want the library to automatically create the offline featureCollection for each layer
offlineFeaturesManager.ENABLE_FEATURECOLLECTION = true;
offlineEdit.ENABLE_FEATURECOLLECTION = true;
// IMPORTANT!!!
// A proxy page may be required to upload attachments.
// If you are using a CORS enabled feature service you can ignore this.
// If your feature service is not CORS-enabled then you will need to configure this.
// Refer to "Using the Proxy Page" for more information: https://developers.arcgis.com/en/javascript/jshelp/ags_proxy.html
offlineFeaturesManager.proxyPath = null;
offlineEdit.proxyPath = null;
}
/**
@ -650,7 +650,7 @@
* Toggles offlineFeaturesManager online/offline
*/
function goOnlineOffline() {
if(offlineFeaturesManager.getOnlineStatus() == offlineFeaturesManager.ONLINE){
if(offlineEdit.getOnlineStatus() == offlineEdit.ONLINE){
goOffline();
}
else{

View File

@ -100,15 +100,15 @@
// window.proxyPath = null; //can be set to null when using a CORS-enabled server
// esriConfig.defaults.io.proxyUrl = null; //can be set to null when using a CORS-enabled server
var offlineFeaturesManager = new O.esri.Edit.OfflineFeaturesManagerAdvanced();
var offlineEdit = new O.esri.Edit.OfflineEditAdvanced();
// IMPORTANT!!!
// A proxy page may be required to upload attachments.
// If you are using a CORS enabled server you may be ablew to set the proxyPath to null.
// Refer to "Using the Proxy Page" for more information: https://developers.arcgis.com/en/javascript/jshelp/ags_proxy.html
offlineFeaturesManager.proxyPath = null;
offlineEdit.proxyPath = null;
offlineFeaturesManager.initAttachments(function(success)
offlineEdit.initAttachments(function(success)
{
attachmentsInited = success;
updateStatus();
@ -127,8 +127,8 @@
map.on("delete-attachments-complete", updateStatus);
map.on("query-attachment-infos-complete", updateStatus);
offlineFeaturesManager.on(offlineFeaturesManager.events.ATTACHMENT_ENQUEUED, updateStatus);
offlineFeaturesManager.on(offlineFeaturesManager.events.ATTACHMENTS_SENT, updateStatus);
offlineEdit.on(offlineEdit.events.ATTACHMENT_ENQUEUED, updateStatus);
offlineEdit.on(offlineEdit.events.ATTACHMENTS_SENT, updateStatus);
function mapLoaded()
{
@ -178,7 +178,7 @@
{
var layer = evt.layer;
offlineFeaturesManager.extend(featureLayer,function(success, error){
offlineEdit.extend(featureLayer,function(success, error){
if(success == false) alert("There was a problem initiating the database. " + error);
});
}
@ -191,7 +191,7 @@
function goOnline()
{
offlineFeaturesManager.goOnline(function()
offlineEdit.goOnline(function()
{
updateConnectivityIndicator();
updateStatus();
@ -201,13 +201,13 @@
function goOffline()
{
offlineFeaturesManager.goOffline();
offlineEdit.goOffline();
updateConnectivityIndicator();
}
function clearLocalAttachments()
{
offlineFeaturesManager.attachmentsStore.deleteAll(function(success)
offlineEdit.attachmentsStore.deleteAll(function(success)
{
updateStatus();
});
@ -230,7 +230,7 @@
return;
domConstruct.empty('local-attachments-list');
offlineFeaturesManager.attachmentsStore.getAllAttachments(function(attachments)
offlineEdit.attachmentsStore.getAllAttachments(function(attachments)
{
var li;
if( attachments.length )
@ -257,17 +257,17 @@
{
var node = dom.byId('connectivity-indicator');
domClass.remove(node, "online offline reconnecting");
switch( offlineFeaturesManager.getOnlineStatus() )
switch( offlineEdit.getOnlineStatus() )
{
case offlineFeaturesManager.OFFLINE:
case offlineEdit.OFFLINE:
node.innerHTML = "<i class='fa fa-chain-broken'></i> offline";
domClass.add(node, "offline");
break;
case offlineFeaturesManager.ONLINE:
case offlineEdit.ONLINE:
node.innerHTML = "<i class='fa fa-link'></i> online";
domClass.add(node, "online");
break;
case offlineFeaturesManager.RECONNECTING:
case offlineEdit.RECONNECTING:
node.innerHTML = "<i class='fa fa-cog fa-spin'></i> reconnecting";
domClass.add(node, "reconnecting");
break;
@ -293,7 +293,7 @@
if(!attachmentsInited)
return;
offlineFeaturesManager.attachmentsStore.getUsage(function(usage)
offlineEdit.attachmentsStore.getUsage(function(usage)
{
var str = "attachment" + ((usage.attachmentCount === 1)? "" : "s");
var info = usage.attachmentCount + " " + str + " (" + formatSize( usage.sizeBytes) + ")";

View File

@ -80,15 +80,15 @@
// window.proxyPath = null; //can be set to null when using a CORS-enabled server
// esriConfig.defaults.io.proxyUrl = null; //can be set to null when using a CORS-enabled server
var offlineFeaturesManager = new O.esri.Edit.OfflineFeaturesManagerAdvanced();
var offlineEdit = new O.esri.Edit.OfflineEditAdvanced();
// IMPORTANT!!!
// A proxy page may be required to upload attachments.
// If you are using a CORS enabled server you may be ablew to set the proxyPath to null.
// Refer to "Using the Proxy Page" for more information: https://developers.arcgis.com/en/javascript/jshelp/ags_proxy.html
offlineFeaturesManager.proxyPath = null;
offlineEdit.proxyPath = null;
offlineFeaturesManager.initAttachments(function(success)
offlineEdit.initAttachments(function(success)
{
attachmentsInited = success;
updateStatus();
@ -107,8 +107,8 @@
map.on("delete-attachments-complete", updateStatus);
map.on("query-attachment-infos-complete", updateStatus);
offlineFeaturesManager.on(offlineFeaturesManager.events.ATTACHMENT_ENQUEUED, updateStatus);
offlineFeaturesManager.on(offlineFeaturesManager.events.ATTACHMENTS_SENT, updateStatus);
offlineEdit.on(offlineEdit.events.ATTACHMENT_ENQUEUED, updateStatus);
offlineEdit.on(offlineEdit.events.ATTACHMENTS_SENT, updateStatus);
function mapLoaded()
{
@ -158,7 +158,7 @@
{
var layer = evt.layer;
offlineFeaturesManager.extend(featureLayer,function(success, error){
offlineEdit.extend(featureLayer,function(success, error){
if(success == false) alert("There was a problem initiating the database. " + error);
});
}
@ -171,7 +171,7 @@
function goOnline()
{
offlineFeaturesManager.goOnline(function()
offlineEdit.goOnline(function()
{
updateConnectivityIndicator();
updateStatus();
@ -181,13 +181,13 @@
function goOffline()
{
offlineFeaturesManager.goOffline();
offlineEdit.goOffline();
updateConnectivityIndicator();
}
function clearLocalAttachments()
{
offlineFeaturesManager.attachmentsStore.deleteAll(function(success)
offlineEdit.attachmentsStore.deleteAll(function(success)
{
updateStatus();
});
@ -210,7 +210,7 @@
return;
domConstruct.empty('local-attachments-list');
offlineFeaturesManager.attachmentsStore.getAllAttachments(function(attachments)
offlineEdit.attachmentsStore.getAllAttachments(function(attachments)
{
var li;
if( attachments.length )
@ -237,17 +237,17 @@
{
var node = dom.byId('connectivity-indicator');
domClass.remove(node, "online offline reconnecting");
switch( offlineFeaturesManager.getOnlineStatus() )
switch( offlineEdit.getOnlineStatus() )
{
case offlineFeaturesManager.OFFLINE:
case offlineEdit.OFFLINE:
node.innerHTML = "<i class='fa fa-chain-broken'></i> offline";
domClass.add(node, "offline");
break;
case offlineFeaturesManager.ONLINE:
case offlineEdit.ONLINE:
node.innerHTML = "<i class='fa fa-link'></i> online";
domClass.add(node, "online");
break;
case offlineFeaturesManager.RECONNECTING:
case offlineEdit.RECONNECTING:
node.innerHTML = "<i class='fa fa-cog fa-spin'></i> reconnecting";
domClass.add(node, "reconnecting");
break;
@ -273,7 +273,7 @@
if(!attachmentsInited)
return;
offlineFeaturesManager.attachmentsStore.getUsage(function(usage)
offlineEdit.attachmentsStore.getUsage(function(usage)
{
var str = "attachment" + ((usage.attachmentCount === 1)? "" : "s");
var info = usage.attachmentCount + " " + str + " (" + formatSize( usage.sizeBytes) + ")";

View File

@ -148,13 +148,13 @@
on(dom.byId('go-offline-btn'),'click', goOffline);
on(dom.byId('go-online-btn'),'click', goOnline);
on(dom.byId('refresh-feature-layers-btn'),'click', refreshFeatureLayers);
var offlineFeaturesManager = new O.esri.Edit.OfflineFeaturesManagerBasic();
var offlineEdit = new O.esri.Edit.OfflineEditBasic();
// IMPORTANT!!!
// A proxy page may be required to upload attachments.
// If you are using a CORS enabled server you may be ablew to set the proxyPath to null.
// Refer to "Using the Proxy Page" for more information: https://developers.arcgis.com/en/javascript/jshelp/ags_proxy.html
offlineFeaturesManager.proxyPath = null;
offlineEdit.proxyPath = null;
map = new Map("map", {
basemap: "satellite",
@ -247,7 +247,7 @@
var layer = result.layer;
offlineInitializedLayers.push(layer);
offlineFeaturesManager.extend(layer,function(success,error){
offlineEdit.extend(layer,function(success,error){
if(success){
deferred.resolve(true);
}
@ -277,15 +277,15 @@
// Things to do when all the promises complete
function resolveOfflinePromises(){
offlineFeaturesManager.on(offlineFeaturesManager.events.EDITS_ENQUEUED, updateStatus);
offlineFeaturesManager.on(offlineFeaturesManager.events.EDITS_SENT, updateStatusAllEditsSent);
offlineEdit.on(offlineEdit.events.EDITS_ENQUEUED, updateStatus);
offlineEdit.on(offlineEdit.events.EDITS_SENT, updateStatusAllEditsSent);
offlineInitializedLayers[0].on("edits-complete", handleEditsComplete);
offlineInitializedLayers[1].on("edits-complete", handleEditsComplete);
offlineInitializedLayers[2].on("edits-complete", handleEditsComplete);
// handle errors that happen while storing offline edits
offlineFeaturesManager.on(offlineFeaturesManager.events.EDITS_ENQUEUED_ERROR, function(errors)
offlineEdit.on(offlineEdit.events.EDITS_ENQUEUED_ERROR, function(errors)
{
if( errors.length )
{
@ -428,7 +428,7 @@
function goOnline()
{
domUtils.show(editor.progressBar.domNode);
offlineFeaturesManager.goOnline(function()
offlineEdit.goOnline(function()
{
domUtils.hide(editor.progressBar.domNode);
updateConnectivityIndicator();
@ -438,7 +438,7 @@
function goOffline()
{
offlineFeaturesManager.goOffline();
offlineEdit.goOffline();
updateConnectivityIndicator();
}
@ -446,17 +446,17 @@
{
var node = dom.byId('connectivityIndicator');
domClass.remove(node, "online offline reconnecting");
switch( offlineFeaturesManager.getOnlineStatus() )
switch( offlineEdit.getOnlineStatus() )
{
case offlineFeaturesManager.OFFLINE:
case offlineEdit.OFFLINE:
node.innerHTML = "<i class='fa fa-chain-broken'></i> offline";
domClass.add(node, "offline");
break;
case offlineFeaturesManager.ONLINE:
case offlineEdit.ONLINE:
node.innerHTML = "<i class='fa fa-link'></i> online";
domClass.add(node, "online");
break;
case offlineFeaturesManager.RECONNECTING:
case offlineEdit.RECONNECTING:
node.innerHTML = "<i class='fa fa-cog fa-spin'></i> reconnecting";
domClass.add(node, "reconnecting");
break;

View File

@ -59,7 +59,7 @@
// refer to "Using the Proxy Page" for more information: https://developers.arcgis.com/javascript/jshelp/ags_proxy.html
esriConfig.defaults.io.proxyUrl = "/proxy/";
var offlineFeatureLayer = new O.esri.Edit.OfflineFeaturesManagerBasic();
var offlineEdit = new O.esri.Edit.OfflineEditBasic();
map = new Map("map", {
@ -79,7 +79,7 @@
function initEditing(evt) {
offlineFeatureLayer.extend(firePerimeterFL,function(success,error){
offlineEdit.extend(firePerimeterFL,function(success,error){
if(success){
var editToolbar = new Edit(map);
editToolbar.on("deactivate", function(evt) {