I am encountering a quirk or potential issue with the Search widget using the JS API 4.x My search widget includes a geocoding service and feature layer source.
I have set a zoomScale property for both sources. When searching against the geocoding service, the scale is being honored (I believe). But when searching against the feature layer, it is not.
I am aware that I could use the goToOverride method to resolve this. However, it is my opinion that the widget is not working properly. Any help is appreciated.
I have a demo at https://codepen.io/pmckinney/pen/MWYLggN.
Sample searches:
Hi Patrick,
I was able to reproduce the issue so I went ahead and logged a defect.
As you have probably already found, a possible workaround would be to set view.scale in a select-result event. For example:
Apologies for the inconvenience!
Lingtao
Esri Support Services
Thanks for the response. I ended up using the goTo() method for the map view object within the search-complete event of the Search widget.
// set map view during search complete event
searchWidget.on('search-complete', function(response) {
// latitude of result
const latitude = response.results[0].results[0].extent.center.latitude;
// longitude to result
const longitude = response.results[0].results[0].extent.center.longitude;
// set map view to result coordinates
mapView.goTo({
center: [longitude, latitude],
zoom: 17
});