Only display the latest feature added

595
5
Jump to solution
02-28-2014 09:22 AM
HenryBoston
New Contributor
I'm trying to modify the following sample to only show the latest feature added to the map. 

The sample is located here: https://developers.arcgis.com/javascript/jssamples/ed_attributeInspectorValidate.html

I've tried to change

//Add the editable feature layer to the map         var pointsOfInterest = new esri.layers.FeatureLayer("http://sampleserver5.arcgisonline.com/ArcGIS/rest/services/Notes/FeatureServer/0",{           mode: esri.layers.FeatureLayer.MODE_ONDEMAND,            outFields: ['*']         });


from MODE_ONDEMAND to MODE_SELECTION

//Add the editable feature layer to the map         var pointsOfInterest = new esri.layers.FeatureLayer("http://sampleserver5.arcgisonline.com/ArcGIS/rest/services/Notes/FeatureServer/0",{           mode: esri.layers.FeatureLayer.MODE_SELECTION,            outFields: ['*']         });


Which works when adding a new feature but as soon as the user clicks anywhere else on the map the newly added feature disappears.  Is there anyway to modify the code so that the newly added feature remains displayed until another feature is added? Effectively making it so only the latest feature is shown on the map.

Thanks!
0 Kudos
1 Solution

Accepted Solutions
BenFousek
Occasional Contributor III
Try:
dojo.connect(pointsOfInterest, "onEditsComplete", function (a, u, d) {   var objectId = a[0].objectId;   pointsOfInterest.setDefinitionExpression("OBJECTID = " + objectId);   pointsOfInterest.refresh(); //for good measure });


Also, consider switching to AMD sooner than later.

View solution in original post

0 Kudos
5 Replies
BenFousek
Occasional Contributor III
Henry,

The 'edits-complete' event returns the object id of the new feature. Use this value to set the definition expression of the layer.

featureLayer.setDefinitionExpression("OBJECTID = " + THE_RETURNED_OBJECTID);


I've not tried this on layer while editing, but I think it should work fine.
0 Kudos
HenryBoston
New Contributor
Thanks for the response Ben. I think we are heading in the right direction. However whenever the edit is complete it hides all of the features including the recently added one.  Below is my code:

 dojo.connect(pointsOfInterest, "onEditsComplete", function(a, u, d) { 
            var objectId = a;
            console.log(objectId);
            pointsOfInterest.setDefinitionExpression("OBJECTID = " + objectId);

        });
0 Kudos
BenFousek
Occasional Contributor III
Try:
dojo.connect(pointsOfInterest, "onEditsComplete", function (a, u, d) {   var objectId = a[0].objectId;   pointsOfInterest.setDefinitionExpression("OBJECTID = " + objectId);   pointsOfInterest.refresh(); //for good measure });


Also, consider switching to AMD sooner than later.
0 Kudos
HenryBoston
New Contributor
Thanks! That appears to have resolved the issue.

Nevermind about the last comment... I've solved it by changing the visibility of the layer.

One minor problem still. When the map is loaded it is displaying all of the features.  When I add a feature to the layer all of the features disappear except the newly added feature.  Is there anyway to show no features when the map has loaded, and then once one is added display only the newly added feature?


Thanks again!
0 Kudos
BenFousek
Occasional Contributor III
You're welcome. Happy coding!
0 Kudos