Search widget won't zoom??

3048
13
Jump to solution
11-30-2018 08:36 AM
KarenEllett
Regular Contributor

When I create a search widget (using 4.9) when I search for a location using the esri geocoder, it zooms to the result just fine.  But I've also defined a feature layer source, and it WON'T zoom to that result; only pan.  I've tried setting the zoomScale to several different values, but it makes no difference. It will pan, but not zoom.  Any help?? I can't find any examples with zoom at all.

Here's a pared down version:

searchWidgetTest = new Search({
  view: view,
  sources:[{
    featureLayer: new FeatureLayer({
      url: "https://server/arcgis/rest/services/folder/layers/MapServer/0"
    }),
  searchFields: ["NAME", "NUMBER"],
  zoomScale:200
  }]
});

0 Kudos
13 Replies
Shane_
by
Emerging Contributor

Thanks Robert. Is there any event I can listen for/use to zoom to the selected feature? The popup is being displayed for the selected feature?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Shane,

  Sure use select result event:

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#event-select-... 

Use a setTimeout to make sure that the search widget is done with everything it does (some like 500 milliseconds should be good) then do you view.goTo.

0 Kudos
Shane_
by
Emerging Contributor

Thanks Robert, perfect...

// ZOOM TO FEATURE AFTER IT IS SELECTED
searchWidget.on("select-result", function (event) { view.goTo( { zoom: 12 } ); } );

0 Kudos
xlt208
by Esri Contributor
Esri Contributor

Hi all,

I was able to reproduce the issue so I went ahead and logged a defect.

  • BUG-000129390: The ZoomScale property fails to set zoom scale for the selected search result from LayerSearchSource.

  

Apologies for the inconvenience!

Lingtao

Esri Support Services

0 Kudos