Can I limit the results of the Search widget to my local area?

5501
20
Jump to solution
11-19-2015 02:25 PM
AlexisGreen
New Contributor II

When a user types an address into the Search widget in WAB which is using the Esri World Geocoder, they get results from other states in the U.S.  We want to constrain the addresses that are returned to be limited to our local area, either our city, county, zip codes, or an extent rectangle.  Do we need the WAB Developer Edition to do this?  If so, is there a custom widget out there already that handles this?  If not, any advice on how to do it is appreciated.

1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Alexis,

  It can be done with some coding changes and manually adding the searchExtent to the search widgets config_Search.json

Here is the config_Search.json (lines 10-18):

{
  "sources": [
    {
      "url": "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer",
      "name": "Esri World Geocoder",
      "singleLineFieldName": "SingleLine",
      "placeholder": "Esri World Geocoder",
      "maxResults": 6,
      "type": "locator",
      "searchExtent": {
        "xmin": -9589858.361942431,
        "ymin": 3964964.109405532,
        "xmax": -9522593.777051566,
        "ymax": 4031693.635098401,
        "spatialReference": {
          "wkid": 102100
        }
      }
    },

Then in the [install Dir]\server\apps\[app #]\widgets\Search\Widget.js (Lines 4-16):

_convertConfig: function(config) {
        var searchSouces = array.map(config.sources, lang.hitch(this, function(source) {
          if (source && source.url && source.type === 'locator') {
            var locSource = {
              locator: new Locator(source.url || ""),
              outFields: ["*"],
              singleLineFieldName: source.singleLineFieldName || "",
              name: source.name || "",
              placeholder: source.placeholder || "",
              countryCode: source.countryCode || "",
              maxResults: source.maxResults || 6
            };
            if(source.searchExtent){
              locSource.searchExtent =  new Extent(source.searchExtent);
            }
            return locSource;
          } else if (source && source.url && source.type === 'query') {

And you have to add the Extent require to the requires list in the Widget.js (lines 2, 7)

'dojo/i18n!esri/nls/jsapi',
    'esri/geometry/Extent',
    'dojo/NodeList-dom'
  ],
  function(declare, lang, array, html, when, on, query, keys,
    BaseWidget, LayerInfos, jimuUtils, Search, Locator,
    FeatureLayer, InfoTemplate, esriLang, utils, esriBundle, Extent) {

View solution in original post

20 Replies
BrianO_keefe
Regular Contributor II

I'll tell you, we have a street file for our city that we've built an address locator off of and published that to our ArcGIS Server as a REST Service utility. Then I just remove the ESRI World Geocoder when I want to restrict to our City. However, then we lose those addresses that (for whatever reason) are not covered by our street file.

I believe there is a method (I think config.js under the hood) that allows you for force the ESRI World Geocoder to restrict searches to specific geographic areas (cities, counties, states, etc.). But I can't remember it off hand.

0 Kudos
AlexisGreen
New Contributor II

Yes we thought about using our own address locator, but prefer not to because of the reason you mentioned.  We are looking for something that forces the ESRI World Geocoder to restrict searches as you describe.  Perhaps the below documentation in the ArcGIS REST API: World Geocoding Service gives a clue.  Anyone know if I'm on the right track or how to do this in WAB?

Search within an extent

The findAddressCandidates operation allows spatial filtering of search results by using the searchExtent parameter. If you want to confine a search to a localized area, something that is especially useful in a mobile application, you can define a bounding rectangle to search within. No candidates outside of the rectangle are returned. Bounding rectangle coordinates can be entered as a simple comma-separated string in the format <lower left corner>,<upper right corner>. If the simple format is used, the coordinates must be in  the default spatial reference of the geocode service, which is WGS84. The searchExtent parameter can be used with all supported search types (street address, POI, admin place, postal code).

0 Kudos
MattiasEkström
Regular Contributor

The ability to search within current map extent is a new feature in the latest November release. When configure your search source there is a checkbox for "Only search in current map extent".

AlexisGreen
New Contributor II

Thank you, but we had looked into this new feature and it is not quite what we are looking for.  While it does indeed limit the results to the current map extent, when you pan and zoom around the map, the tool limits the results to whatever map extent you happen to be at when you type in your search in the Search widget.  This has the effect of restricting the results too much when the user is zoomed into a small detailed area.

In contrast, the behavior that we are seeking is for the extent that is used to limit the search results to be a fixed, unchanging extent, for example, an extent rectangle covering our county, that doesn't depend on how far zoomed in the user is in the map at any given moment that they are navigating around the map. 

Anyone know if this is possible to do?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Alexis,

  It can be done with some coding changes and manually adding the searchExtent to the search widgets config_Search.json

Here is the config_Search.json (lines 10-18):

{
  "sources": [
    {
      "url": "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer",
      "name": "Esri World Geocoder",
      "singleLineFieldName": "SingleLine",
      "placeholder": "Esri World Geocoder",
      "maxResults": 6,
      "type": "locator",
      "searchExtent": {
        "xmin": -9589858.361942431,
        "ymin": 3964964.109405532,
        "xmax": -9522593.777051566,
        "ymax": 4031693.635098401,
        "spatialReference": {
          "wkid": 102100
        }
      }
    },

Then in the [install Dir]\server\apps\[app #]\widgets\Search\Widget.js (Lines 4-16):

_convertConfig: function(config) {
        var searchSouces = array.map(config.sources, lang.hitch(this, function(source) {
          if (source && source.url && source.type === 'locator') {
            var locSource = {
              locator: new Locator(source.url || ""),
              outFields: ["*"],
              singleLineFieldName: source.singleLineFieldName || "",
              name: source.name || "",
              placeholder: source.placeholder || "",
              countryCode: source.countryCode || "",
              maxResults: source.maxResults || 6
            };
            if(source.searchExtent){
              locSource.searchExtent =  new Extent(source.searchExtent);
            }
            return locSource;
          } else if (source && source.url && source.type === 'query') {

And you have to add the Extent require to the requires list in the Widget.js (lines 2, 7)

'dojo/i18n!esri/nls/jsapi',
    'esri/geometry/Extent',
    'dojo/NodeList-dom'
  ],
  function(declare, lang, array, html, when, on, query, keys,
    BaseWidget, LayerInfos, jimuUtils, Search, Locator,
    FeatureLayer, InfoTemplate, esriLang, utils, esriBundle, Extent) {
AlexisGreen
New Contributor II

Thank you for the detailed directions.  I'm trying to implement this in the WAB Developer Edition, but cannot find a config_Search.json file in the folder of the particular web app I'm working on.  Is the file located somewhere else, or am I supposed to create it from scratch?  Thanks!

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Alexis,

   It is located in the [install dir]\server\[app#]\configs folder

0 Kudos
AlexisGreen
New Contributor II

Looks like the folder shows up there only after you go in to configure the Search widget in the particular app you're working on in WAB.  It doesn't show up if the Search widget is just enabled but not configured.  Anyway I see it now.  Thanks!!

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Alexis,

   Gald to help, don't forget to mark this thread as answered. To do this you have to open the thread (you can not see the correct answer link from inside your inbox) and then you will see the green star with correct answer link. Just click that link on the thread that answered your question.

0 Kudos