0

I am attempting to get an application working where editors can click on a point feature and edit a form. I need the form to have a save button that when clicked will apply the edits to the feature.

I am selecting the point/s using an envelope. Is there a way I can tell what feature I need to apply the edits to on my save click event? I would like to store the edits to a feature as fields are changed and then only save the edits to the feature class with the save button.

I am trying to use this example to understand the edit saving and then the feature save. Attribute Inspector

Here is what I am working with right now. I am grabbing the point features within an envelope:

function initEditor() {
          var featureLayer = layersFS[1].layer;            

      var selectQuery = new Query();
      map.on("click", function (evt) {

          var centerPoint = new esri.geometry.Point
           (evt.mapPoint.x, evt.mapPoint.y, evt.mapPoint.spatialReference);
          var mapWidth = map.extent.getWidth();

          //Divide width in map units by width in pixels
          var pixelWidth = mapWidth / map.width;

          //Calculate a 10 pixel envelope width (5 pixel tolerance on each side)
          var tolerance = 10 * pixelWidth;

          //build query filter
          query = new esri.tasks.Query();
          query.returnGeometry = true;
          query.outFields = ["*"];

          //Build tolerance envelope and set it as the query geometry
          var queryExtent = new esri.geometry.Extent
                  (1, 1, tolerance, tolerance, evt.mapPoint.spatialReference);
          query.geometry = queryExtent.centerAt(centerPoint);
          featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (features) {
              if (features.length > 0) {
                  //store the current feature
                  for (var i = 0; i < features.length; i++) {
                      updateFeatures.push(features[i]);                          
                  }
                  //map.infoWindow.setTitle(features[0].getLayer().name);
                  map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));
              } else {
                  map.infoWindow.hide();
              }
          });
      });

Then I am planning to update the specific feature with the save button:

saveButton.on("click", function () {
          //need to figure out how to get the current feature with the save click, 
          //the envelope may return 1 to many records and I need the current feature
          updateFeatures.forEach(function(entry) {
          updateFeature.getLayer().applyEdits(null, [updateFeature], null);            
          }
       )});

      ///////Need to apply similar logic as save button click but this will update the current feature in the updateFeatures[]
      attInspector.on("attribute-change", function (evt) {
          //store the updates to apply when the save button is clicked 
          updateFeature.attributes[evt.fieldName] = evt.fieldValue;
      });

What is the best way to determine what my current feature is in the info window that is being edited?

1

You can get the selected feature from the attributeInspector this way

attInspector._currentFeature

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.