Edit Widget - Auto-populate address field reverse geocode

2384
1
01-11-2016 01:24 PM
LizDaRos
Occasional Contributor

I would love to be able to auto-populate a field in the edit widget with the nearest address. Robert thankfully showed me how to populate a field when creating a new feature and now I would like to perform a reverse geocode in the edit widget and have it auto-populate an editable field. So far I've been able to get the reverse geocode to work in the widget but I can't seem to get the value from the geocode function to populate in the _worksAfterCreate function in the editor Widget.js. What am I doing wrong and how can I get the value from my reverse geocode function to show in another function like the _worksAfterCreate?

     _initGeocoder: function() {

        this.editor.locator = new Locator("my/GeocodeServer");

        this.editor.locator.on("location-to-address-complete", lang.hitch(this, function (evt) {

            var address = evt.address.address;

            var AddrPt = address.Street;

            var AddrPt2 = AddrPt;

        })); 

    },

    _registerMapEvents: function() {

        this.mapClickEvent = this.map.on("click", lang.hitch(this, function (evt) {

            this.editor.locator.locationToAddress(esri.geometry.Point(evt.mapPoint), 100, null, lang.hitch(this, function () {

            }));    

        }));

    },

     _worksAfterCreate: function(AddrPt2) { 

        // add close button to atiInspector

        this._addButtonToInspector();

        // resize editPopup

        this.editPopup.resize(500, 251);

        // update templatePicker for responsive.

        this.editor.templatePicker.update();       

        //Add the autopopulate field value from Robert

        this.editor.templatePicker.on("selection-change", lang.hitch(this, function() {

          var selected = this.editor.templatePicker.getSelected(); 

          if (selected) { 

            var featureLayer = selected.featureLayer; 

            on.once(featureLayer, "before-apply-edits", lang.hitch(this, function(evt){

            alert(AddrPt2);

              if(evt.adds && evt.adds.length > 0){ 

                if(evt.adds[0].attributes.hasOwnProperty('ADDRESS')){ 

                evt.adds[0].attributes.ADDRESS = AddrPt2; 

                } 

                this.editor.attributeInspector.refresh();

              } 

            })); 

          }

        })); 

  //End add

        //just for BoxTheme

        setTimeout(lang.hitch(this, this._update), 900);

        // // reset default selectionSymbol that change by Editor dijit.

        // array.forEach(this.editor.settings.layerInfos, function(layerInfo) {

        //   layerInfo.featureLayer.setSelectionSymbol();

        // }, this);

      },

0 Kudos
1 Reply
AlistairFox
Occasional Contributor

Hi, you mention above "Robert thankfully showed me how to populate a field when creating a new feature" Can you share this? I need to populate a value into a field through code, not through the user editing it, but need to know where this happens in the code.

0 Kudos