mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
refactor _pushFeatureCollections
This commit is contained in:
parent
f6da0cb5e8
commit
0fda7b3412
@ -499,60 +499,7 @@ define([
|
||||
}
|
||||
}
|
||||
|
||||
self._editStore._getFeatureCollections(function(success, result) {
|
||||
|
||||
var featureCollection =
|
||||
{
|
||||
featureLayerUrl: layer.url,
|
||||
featureLayerCollection: layer.toJson()
|
||||
};
|
||||
|
||||
// An array of feature collections, of course :-)
|
||||
var featureCollectionsArray = [
|
||||
featureCollection
|
||||
];
|
||||
|
||||
// An object for storing multiple feature collections
|
||||
var featureCollectionsObject = {
|
||||
// The id is required because the editsStore keypath
|
||||
// uses it as a UID for all entries in the database
|
||||
id: self._editStore.FEATURE_COLLECTION_ID,
|
||||
featureCollections: featureCollectionsArray
|
||||
};
|
||||
|
||||
// If the featureCollections object already exists
|
||||
if(success){
|
||||
var count = 0;
|
||||
for(var i = 0; i < result.featureCollections.length; i++) {
|
||||
|
||||
// Update the current feature collection
|
||||
if(result.featureCollections[i].featureLayerUrl === layer.url) {
|
||||
count++;
|
||||
result.featureCollections[i] = featureCollection;
|
||||
}
|
||||
}
|
||||
|
||||
// If we have a new feature layer then add it to the featureCollections array
|
||||
if(count === 0) {
|
||||
result.featureCollections.push(featureCollectionsArray);
|
||||
}
|
||||
}
|
||||
// If empty then we need to add the new featureCollectionsObject
|
||||
else if(!success && result === null) {
|
||||
result = featureCollectionsObject;
|
||||
}
|
||||
else {
|
||||
console.error("There was a problem retrieving the featureCollections from editStore.");
|
||||
}
|
||||
|
||||
// Automatically update the featureCollection store in the database with every ADD, UPDATE
|
||||
// and DELETE. It can be retrieved via OfflineFeaturesManager.getFeatureCollections();
|
||||
self._editStore._pushFeatureCollections(result, function(success, error) {
|
||||
if(!success){
|
||||
console.error("There was a problem creating the featureCollectionObject: " + error);
|
||||
}
|
||||
});
|
||||
});
|
||||
layer._pushFeatureCollections();
|
||||
|
||||
// we already pushed the edits into the database, now we let the FeatureLayer to do the local updating of the layer graphics
|
||||
// EDITS_ENQUEUED = callback(true, edit), and EDITS_ENQUEUED_ERROR = callback(false, /*String */ error)
|
||||
@ -801,6 +748,74 @@ define([
|
||||
|
||||
/* internal methods */
|
||||
|
||||
/**
|
||||
* Automatically creates a set of featureLayerCollections. This is specifically for
|
||||
* use with offline browser restarts. You can retrieve the collections and use them
|
||||
* to reconstitute a featureLayer and then redisplay all the associated features.
|
||||
*
|
||||
* To retrieve use OfflineFeaturesManager.getFeatureCollections().
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
layer._pushFeatureCollections = function(){
|
||||
|
||||
// First let's see if any collections exists
|
||||
self._editStore._getFeatureCollections(function(success, result) {
|
||||
|
||||
var featureCollection =
|
||||
{
|
||||
featureLayerUrl: layer.url,
|
||||
featureLayerCollection: layer.toJson()
|
||||
};
|
||||
|
||||
// An array of feature collections, of course :-)
|
||||
var featureCollectionsArray = [
|
||||
featureCollection
|
||||
];
|
||||
|
||||
// An object for storing multiple feature collections
|
||||
var featureCollectionsObject = {
|
||||
// The id is required because the editsStore keypath
|
||||
// uses it as a UID for all entries in the database
|
||||
id: self._editStore.FEATURE_COLLECTION_ID,
|
||||
featureCollections: featureCollectionsArray
|
||||
};
|
||||
|
||||
// If the featureCollectionsObject already exists
|
||||
if(success){
|
||||
var count = 0;
|
||||
for(var i = 0; i < result.featureCollections.length; i++) {
|
||||
|
||||
// Update the current feature collection
|
||||
if(result.featureCollections[i].featureLayerUrl === layer.url) {
|
||||
count++;
|
||||
result.featureCollections[i] = featureCollection;
|
||||
}
|
||||
}
|
||||
|
||||
// If we have a new feature layer then add it to the featureCollections array
|
||||
if(count === 0) {
|
||||
result.featureCollections.push(featureCollectionsArray);
|
||||
}
|
||||
}
|
||||
// If it does not exist then we need to add a featureCollectionsObject
|
||||
else if(!success && result === null) {
|
||||
result = featureCollectionsObject;
|
||||
}
|
||||
else {
|
||||
console.error("There was a problem retrieving the featureCollections from editStore.");
|
||||
}
|
||||
|
||||
// Automatically update the featureCollectionsObject in the database with every ADD, UPDATE
|
||||
// and DELETE. It can be retrieved via OfflineFeaturesManager.getFeatureCollections();
|
||||
self._editStore._pushFeatureCollections(result, function(success, error) {
|
||||
if(!success){
|
||||
console.error("There was a problem creating the featureCollectionObject: " + error);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Pushes a DELETE request to the database after it's been validated
|
||||
* @param layer
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user