// using the historyutil.js module I posted earlier var Service = declare([], { constructor: function(options) { this.options = options; this.map = this.options.map; // the options will have a URL to the // non-spatial table in my FeatureService // for recording the history of my edits this.editHistory = new HisotryUtil(this.options); // this is the actual layer with spatial features that // I will edit. this.editLayer = this.map.getLayer('defectsLayer'); }, save: function(name, adds, updates) { var deferred = new Deferred(); var self = this; // first edit my spatial layer // NOTE - Deletes not allowed in app, but you could track that if // needed. this.editLayer.applyEdits(adds, updates, null, function (results) { // when spatial table successfully edited, send same // edits to history table using the HistoryUtil // module in previous post. self.editHistory.save(adds, filterUpdate(updates)); self.editLayer.refresh(); // quick refresh // I don't to see if // history update finished because I don't care. // History is a backend thing, not app related. // In production I would check if this failed and // log it somewhere else. // Now I can resolve my results. deferred.resolve(results); }, function (error) { deferred.reject(error); }); return deferred.promise; }, }); // This function finds out if two field // values are identical function statsMatch(obj, field1, field2) { return obj[field1] === obj[field2]; } // If I'm doing an update of data, I just track status changes. // So I filter out any features where the status did NOT change. function filterUpdate(items) { return arrayUtil.filter(items, function(item) { // helper function to see if the status changed return !statsMatch(item.attributes, 'PreviousStatus', 'DefectStatus'); }); } return Service;
define([ 'dojo/_base/declare', 'esri/layers/FeatureLayer' ], function( declare, FeatureLayer ) { 'use strict'; return declare(null, { constructor: function(options) { this.historyLayer = new FeatureLayer(options.settings.defectHistory); }, save: function(adds, updates, deletes) { return this.historyLayer.applyEdits(adds, updates, deletes); } }); });
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.