AnsweredAssumed Answered

How do I refresh the attributes of the map graphics and update the Attribute Inspector to show new attributes after an edit operation?

Question asked by timdine on Sep 2, 2015
Latest reply on Sep 3, 2015 by timdine

I'm continuing working on enhancements on the edit widget.  I've built an Object Class Extension to generate a uniqueID and populate a field based on some rules, I've deployed it and it works well.

 

When you make an edit to one of five fields the values of those fields are combined to populate a sixth field in the object class extension.  When I make an edit to one of those five fields the applyEdits function fires and sends the update (updating all fields?).  The class extension fires and fills in the sixth field.  The attribute inspector doesn't know this happens and doesn't reflect the result for the sixth field.

 

I'm working on how to update the attribute inspector on an event and feel close.  I've hooked onto some events that fire which I'd expect to update the features in the feature layer and then refresh the inspector, I'm not getting the result I want.  I see query requests being sent to the feature service, but the graphics layer isn't reflecting the change and therefore the attribute inspector isn't showing it either.  My hooks onto the query events aren't firing at this time.  I think the inspector is refreshing and just reshowing the same values it already had.  When I pan the map all the query events I've hooked onto fire appropriately, reopening the attribute inspector shows what I've been looking for.

 

Any thoughts would be appreciated...  It almost seems like the api is preventing the other events from firing during an edit process.

 

------------------------------------------------------------------

onOpen function from my Edit Widget, creates some hooks onto the feature layers if the specified event happens

onOpen: function() {
    if (typeof this.hasAlreadyHitchedLayerChanges === "undefined") {
        featureLayerCount = this.map.graphicsLayerIds.length;
        for(i = 0; i < featureLayerCount; i++){
            var layerID = this.map.graphicsLayerIds[i];
            var fLayer = this.map.getLayer(layerID);
            if(fLayer !== undefined)  {
                fLayer.on("edits-complete", OnEditsCompleteHandler);//OnEditsCompleteHandler
                fLayer.on("query-features-complete", OnQueryFeaturesComplete);
                fLayer.on("query-extent-complete", OnQueryFeaturesComplete);
                fLayer.on("query-ids-complete", OnQueryFeaturesComplete);
                fLayer.on("update", OnQueryFeaturesComplete);
            }
        }

       
        this.hasAlreadyHitchedLayerChanges = true;
      }
}

-----------------------------------------------------------------------

The two functions that fire when the events are detected.

 

function OnEditsCompleteHandler(evt){

    //alert("it worked!  Here's the data: " + evt);
    //console.log(this.editor);
   
    require(['jimu/WidgetManager'],function(WidgetManager){
    var wm = WidgetManager.getInstance();
    var editWidget = wm.getWidgetsByName('Edit')[0];
    console.log(evt);
    console.log(editWidget);
    var theLayerInfos = editWidget.editor.attributeInspector.layerInfos;
    for (var i=0; i<theLayerInfos.length; i++) {
        var theLayerID = theLayerInfos[i].layerId;
        console.log(this.map);
        var theLayerToRefresh = editWidget.map.getLayer(theLayerID);
        theLayerToRefresh.refresh(); //seems to cause requests to the feature service that aren't reflected in the map?
        theLayerToRefresh.redraw(); //probably unnecessary
        editWidget.attributeInspector.refresh(); //not showing my updated data
    }

    });
};

function OnQueryFeaturesComplete(evt) {
    alert("it worked!  Here's the data: " + evt);

Outcomes