WAB Geocode Widget Composite Locator

5857
11
Jump to solution
02-04-2015 01:54 PM
StanMcShinsky
Occasional Contributor III

I have a composite locator in the Geocode widget in WAB. I would like to know if there is a way to display what locator was used in the search. Either in the auto populate search bar

search.jpg

or in the popup from the result.

popup.jpg

One of the reasons I think this would be helpful is because on one of my composite locators I am searching based of attributes from features. I have unique IDs that I want to search for but the IDs are only unique for that feature class. So I could and do have IDs that match from different feature classes. As An additional thought I might be nice to have the geocode score as well in the popup.

Here is an esri example of what I was thinking

Geocode an address | ArcGIS API for JavaScript

results.jpg

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Stan,

  Sure this is possible with a couple of changes in the code.

Change the code in the client\stemapp\widgets\Geocoder\widget.js line 230 to:

content = response.result.name + "<br> Source locator: " + response.result.feature.attributes.Loc_name;

Assuming that your composite locator has an out field named "Loc_name". If not the substitute "Loc_name" fro your locators filed name.

Open your apps folder (i.e. server\apps\71\configs\Geocoder\config_Geocoder.json). Add the outfields property and add the same field name as in the previous step.

Example

{

  "geocoder": {

    "autoComplete": true,

    "minCharacters": 3,

    "arcgisGeocoder": false,

    "geocoders": [

      {

        "url": "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer",

        "name": "Esri World Geocoder",

        "singleLineFieldName": "SingleLine",

        "placeholder": "Esri World Geocoder"

      },

      {

        "url": "http://your server /arcgis/rest/services/your Locator/GeocodeServer",

        "name": "Calhoun Geocoder",

        "singleLineFieldName": "SingleLine",

        "placeholder": "Calhoun Geocoder",

        "outFields": "Loc_name,User_fld"

      }

    ]

  }

}

Let me know if anything is unclear.

View solution in original post

11 Replies
RobertScheitlin__GISP
MVP Emeritus

Stan,

  Sure this is possible with a couple of changes in the code.

Change the code in the client\stemapp\widgets\Geocoder\widget.js line 230 to:

content = response.result.name + "<br> Source locator: " + response.result.feature.attributes.Loc_name;

Assuming that your composite locator has an out field named "Loc_name". If not the substitute "Loc_name" fro your locators filed name.

Open your apps folder (i.e. server\apps\71\configs\Geocoder\config_Geocoder.json). Add the outfields property and add the same field name as in the previous step.

Example

{

  "geocoder": {

    "autoComplete": true,

    "minCharacters": 3,

    "arcgisGeocoder": false,

    "geocoders": [

      {

        "url": "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer",

        "name": "Esri World Geocoder",

        "singleLineFieldName": "SingleLine",

        "placeholder": "Esri World Geocoder"

      },

      {

        "url": "http://your server /arcgis/rest/services/your Locator/GeocodeServer",

        "name": "Calhoun Geocoder",

        "singleLineFieldName": "SingleLine",

        "placeholder": "Calhoun Geocoder",

        "outFields": "Loc_name,User_fld"

      }

    ]

  }

}

Let me know if anything is unclear.

StanMcShinsky
Occasional Contributor III

Thanks Robert

That works great. I was missing the line in the Widget.js file.

To add the score I just added this to the Widget .js:

  content = response.result.name + "<br> Locator: " + response.result.feature.attributes.Loc_name + "<br> Score: " + response.result.feature.attributes.score;

and to the config_Geocoder.json:

"outFields": "Loc_name, score"

Do you know of a way to show the locator in the auto suggest box at the top?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Stan,

   No that would require extending the Geocode API component. It could be done but would involve a lot of code.

0 Kudos
StanMcShinsky
Occasional Contributor III

Thanks what I thought but I figured I might ask anyway.

0 Kudos
BrandonKeinath1
Occasional Contributor III

Hi Stan,

Thanks for the link to this discussion.  It's not a fancy method but I do something similar with my geocoders.  I work for an electric utility and we use the object id to find multiple types of features (poles, transformers, etc).  I created single field locators that use a new field called "SearchField" that I calculate with the objected and the name of the geocoder.  For example, "1234 Pole" or "1234 Transformer".  Then when I combine them into a composite locator my users are able to see which geocoder is being used.

Brandon

0 Kudos
LarryStout
Occasional Contributor III

Stan,

It's on my to do list for JavaScript, but I wrote my own auto complete for the Flex Viewer.  I'm using a composite geocoder with over 20 feature classes.  I think my auto complete is way better than Esri's.

For my address, (9850 Highland Springs Dr N), my auto complete offers it after I type in 5 characters (the minimum).  Esri's auto complete using the same geocoder requires 20 characters before my address is offered.

Here's a link: Hamilton County Flex Viewer

I'm writing this up for the JS API team.

Larry

StanMcShinsky
Occasional Contributor III

As far as the auto compete goes I believe that as you type it is scoring your text against the geocoder and as soon as you reach the minimum match score then it will start showing up on your results drop down.

-Stan

LarryStout
Occasional Contributor III

Stan,

I understand, but I wish they would let us change the scoring.  My users would kill me if I replaced an app that suggests the address in 5 keystrokes with one that takes 20 keystrokes.  In my Flex auto complete, the query is simple.  When you type 12345, it builds a SQL query select * from table where id like '12345*'.  I have a Python script that updates the table every morning in the wee hours.  It has about a million records, but is indexed.

Larry

BrandonKeinath1
Occasional Contributor III

Hi Larry,

Maybe I'm not understanding the scoring you're referring to but it is possible to change the address locator properties programatically after creation.  I have a script that runs daily to create a number of single field and composite locators.  After each of the locators is created it loops through the xml files and replaces the properties I choose.  For example, MinimumMatchScore and SpellingSensitivity.  It would be better to set it first but after the fact works fine.

Brandon