I'm confused about how to use applyEdits to update my latitude and longitude columns once my graphic has been moved. It seems like I need to have a complete Graphic element created to use as input for applyEdits.
This isn't giving my any errors, but when I tried this, it doesn't change my attributes.
app.myEditor.editToolbar.on('graphic-move-stop', function(evt){ var currentGraphic = evt.graphic; var latLongCoord = webMercatorUtils.xyToLngLat(evt.graphic.geometry.x, evt.graphic.geometry.y); // console.log("Latitude: " + latLongCoord[1] + ", Longitude: " + latLongCoord[0]); var latCoor = latLongCoord[1].toFixed(6); var longCoor = latLongCoord[0].toFixed(6); var att = { "OBJECTID":currentGraphic.attributes.OBJECTID, "Name": currentGraphic.attributes.Name, "Address": currentGraphic.attributes.Address, "City": currentGraphic.attributes.City, "State": currentGraphic.attributes.State, "ZIP": currentGraphic.attributes.ZIP, "Phone": currentGraphic.attributes.Phone, "Cell": currentGraphic.attributes.Cell, "Latitude": latCoor, "Longitude":longCoor } var updateGraphic = new Graphic(currentGraphic,mySymbols.redPinSymbol_edit(),att); app.eusLayer.applyEdits(null,[updateGraphic], null ); });
What do you get when you add the error function to the applyEdits?
app.eusLayer.applyEdits(null,[updateGraphic], null, function () { console.log("Features updated!"); }, function (error) { console.log("Features not updated! ", error); });
An error like that isn't the right syntax .... Uncaught TypeError: Cannot read property '_getInfo' of undefined.
I've been looking at attr(name,value), which is something in the FeatureLayer documentation. That seems more straight forward, since I'm just trying to modify a couple of attributes. That doesn't work either, or I don't have the syntax right.
I think maybe my lat and long coordinates are coming through typed as string. I'm going to get them changed to a number and see if that's the problem.
I modified the latitude/longitude to numbers. That didn't fix anything. I also didn't have the graphic constructor correct. It should have been curentGraphic.geometry.
var updateGraphic = new Graphic(currentGraphic.geometry, mySymbols.redPinSymbol_edit() ,att);
Still isn't updating the attributes.
Have you verified that the updateGraphic has the new attributes when it is being passed to the applyEdits method?
Yes, it does.
I just now realized something. As long as the feature is still selected, it has the original attributes. But if I click away from it, so it's un-selected, and then select it again, I see that it has the updated coordinates.
It was working, but it didn't look like it was ....
Have you ever used graphic.attr(name, value)? Reading the documentation, it sure sounded like it was what I needed, as opposed to going through the applyEdits process.
One of my apps has the capability of update attributes for a feature. The user could select many features to update (selecting attributes from comboboxes), so I had a array of features (featureSet). This is how I updated the attributes
array.forEach(featureSet, function (feature) { feature.attributes.Priority = registry.byId('cboPriority').get("value"); feature.attributes.Management = registry.byId('cboManagement').get("value"); feature.attributes.Criteria1 = registry.byId('cboCriteria1').get("value"); feature.attributes.Criteria2 = registry.byId('cboCriteria2').get("value"); feature.attributes.Criteria3 = registry.byId('cboCriteria3').get("value"); }); layerFeatureLayer.applyEdits(null, featureSet, null, function () { console.log("Features updated!"); }, function (error) { console.log("Features not updated! ", error); });