How do I use outFields with a custom geocoder?

5000
9
05-08-2015 10:00 AM
BrandonKeinath1
Occasional Contributor III

While reading through geocoder documentation I found reference to an outFields parameter.  Assuming I understand what this does I'd like to add the functionality into some custom geocoders I use in web app builder applications.  I tried adding it into my geocoding config_Geocoder.json file but nothing seems to happen.  The geocoder still functions properly but no additional fields are shown.  Can someone help me figure out what is wrong with the code?

{
  "geocoder": {
    "autoComplete": true,
    "minCharacters": 3,
    "arcgisGeocoder": false,
    "geocoders": [
      {
        "url": "https://recpgis01.mnpower.com/mpgis/rest/services/OnelineLocator/GeocodeServer",
        "name": "One2line",
        "singleLineFieldName": "SingleLine",
        "placeholder": "",
  "outFields": "*"
      }
    ]
  }
}
0 Kudos
9 Replies
TimWitt2
MVP Alum

Brandon,

Maybe this thread can help: How can I access the "additional fields" in a locator?

Tim

BrandonKeinath1
Occasional Contributor III

Thanks Tim,

There does seem to be some good stuff there, but I'm not sure where to made the additional code changes necessary to see the additional fields.  Can you help me with that part since it sounds like I'm calling the outFields portion right.

Brandon

0 Kudos
TimWitt2
MVP Alum

Maybe Kelly Hutchins​ can point you in the right direction, since I am still learning the WebApp builder structure.

0 Kudos
PaulCrickard
New Contributor III

You are doing it right. You should be able to get the fields using

geocoder.results[0].feature.attributes.NAMEOFATTRIBUTEYOUWANT

results is an array so you can loop through it.

BrandonKeinath1
Occasional Contributor III

Hi Paul,

Do you have an example of how I would do this in the locator pop-up?  I'm new to all of this and I'm not sure how to get started.

Thanks,

Brandon

0 Kudos
PaulCrickard
New Contributor III

In the ESRI example they use an infoWindow. You can just add it like this:

geocoder.on("select", showLocation);

      

function showLocation(evt) {

          map.graphics.clear();

          var point = evt.result.feature.geometry;

          var symbol = new SimpleMarkerSymbol().setStyle(

            SimpleMarkerSymbol.STYLE_SQUARE).setColor(

            new Color([255,0,0,0.5])

          );

          var graphic = new Graphic(point, symbol);

          map.graphics.add(graphic);

          map.infoWindow.setTitle("Search Result");

          map.infoWindow.setContent(geocoder.results[0].feature.attributes.score+",<br><h3>Some other Fields</h3>");

          map.infoWindow.show(evt.result.feature.geometry);

        

        }

Here is the full code of an exmaple modified from esri

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Brandon,

   The Geocoder widget in WAB does not use all the out fields specified in the geocode service.   If you look in the Geocoder widgets widget.js and find the _processInfoWindowContent and the subsequent _generateInfoContent function you will see that the only attribute field it attempts to use is the Match_addr or StAddr. So you would have to modify the _generateInfoContent function to use more of your fields.

BrandonKeinath1
Occasional Contributor III

Hi Robert,


Sorry for the delayed response.  I find the functions you mention and I was able to modify the code but I'm missing something.  My code changes only seem to affect the default World geocoder.  I only noticed it by accident when I forgot to switch to my custom geocoder.  Is there additional code I need to modify to have my custom geocoder use the _processInfoWindowContent and _generateInfoContent functions?  If I'm understanding the process the reason it is undefined is that the attribute "SearchField" doesn't exist in the default World geocoder.

geocoder_popup_additionalfields_undefined.JPG

content += attr.SearchField + " HAHA";

0 Kudos
StanMcShinsky
Occasional Contributor III

Brandon,

I did something like what you are asking and here is the help I got WAB Geocode Widget Composite Locator​.

-Stan