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

7396
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.

20 Replies
AlexisGreen
New Contributor II

Sorry I was busy implementing it.  It works perfectly!  I have marked your answer as correct.  Thanks so much for your help!!

0 Kudos
LeoLadefian4
Occasional Contributor

Thanks for the help Robert, I'm trying to implement this on an app and now receiving a create widget error/Search, when trying to edit the app.  Any ideas? This is with WAB 1.3

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Leo,

   What is the browsers web console telling you. Sounds like a syntax error or you mixed up the order of the require and their subsequent vars.

0 Kudos
LeoLadefian4
Occasional Contributor

I started over and tried again, now I'm not getting the widget to appear on screen during loading.  Editing the widget just causes it to spin:

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Leo,


  I would have to see your search widget code with the changes you made.

0 Kudos
LeoLadefian4
Occasional Contributor

This is what I have so far:

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Leo,

    You are missing a comma after the

"type": "Locator",

"searchExtent": {

0 Kudos
LeoLadefian4
Occasional Contributor

Thanks for the help, I'm getting this error now in the console when I try to type in a search:

0 Kudos
LeoLadefian4
Occasional Contributor

my Widget.js code looks a bit different than the example:

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Leo,

  This thread was for WAB 1.2. It looks like you are using 1.3 so the code has changed.

Widget.js Require section (line 3 and 8):

    'esri/lang',
    './utils',
    'esri/geometry/Extent',
    'dojo/NodeList-dom'
  ],
  function(declare, lang, array, html, when, on, aspect, query, keys, Deferred, all,
    BaseWidget, LayerInfos, jimuUtils, Search, Locator,
    FeatureLayer, InfoTemplate, esriLang, utils, Extent) {
    //To create a widget, you need to derive from BaseWidget.

_convertConfig function(line 14)

      _convertConfig: function(config) {
        var sourceDefs = array.map(config.sources, lang.hitch(this, function(source) {
          var def = new Deferred();
          if (source && source.url && source.type === 'locator') {
            def.resolve({
              locator: new Locator(source.url || ""),
              outFields: ["*"],
              singleLineFieldName: source.singleLineFieldName || "",
              name: jimuUtils.stripHTML(source.name || ""),
              placeholder: jimuUtils.stripHTML(source.placeholder || ""),
              countryCode: source.countryCode || "",
              maxResults: source.maxResults || 6,
              useMapExtent: !!source.searchInCurrentMapExtent,
              searchExtent: (source.searchExtent) ? new Extent(source.searchExtent) : null
            });
          } else if (source && source.url && source.type === 'query') {

config_Search.json (the same as before).