Zoom to After Search Widget

2572
1
04-07-2016 02:31 AM
NatashaManzuiga
Occasional Contributor

how can I modify the Search Widget to stop zooming after a search and to pan if the searched item is outside the current extent?

I did the same in Flex...but with Web AppBuilder I don't understand where I have to modify...

Thanks,

Naty

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus

Naty,

  Sure it will require some code changes though:

  In the [install dir]\server\apps\[app#]\widgets\Search\Widgets.js, find the _convertConfig function and add line 10 and the comma on 9:

            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,
              autoNavigate: false
            });

If you want to do the same for feature layers as well then make these changes as well Line 12 and comma on 11:

              var convertedSource = {
                featureLayer: flayer,
                outFields: ["*"],
                searchFields: fNames,
                displayField: source.displayField || "",
                exactMatch: !!source.exactMatch,
                name: jimuUtils.stripHTML(source.name || ""),
                placeholder: jimuUtils.stripHTML(source.placeholder || ""),
                maxResults: source.maxResults || 6,
                infoTemplate: template,
                useMapExtent: !!source.searchInCurrentMapExtent,  
                autoNavigate: false  
              };

Then in the _onSelectResult function add these line to the end of that function:

        if(result.feature.geometry.type === 'point'){
          this.map.centerAt(result.feature.geometry);
        }else{
          this.map.centerAt(result.feature.geometry.getExtent().getCenter());
        }