AnsweredAssumed Answered

How to view.goTo feature result and display full extent of feature?

Question asked by kafros on Aug 14, 2017
Latest reply on Aug 18, 2017 by TSolow-esristaff

I have some JavaScript that queries for a parcel in a feature layer, successfully, and then zooms to the parcel using view.goTo(). It works great, except it zooms a little TOO close into the parcel. I'd like to have it fully display the parcel on the map, not go too far in.  Any ideas?

Using ESRI's JavaScript 4.4 API

view.then(function() {
    var url = urlUtils.urlToObject(document.URL);
    //make sure we have parameters
    if (url.query) {
     var parcelNumber = url.query.PID;
     return parcelLayer.then(function() {
      var query = parcelLayer.createQuery();
      query.where = "PID_NUM = '" + parcelNumber + "'";
      query.outSpatialReference = view.spatialReference;
      return parcelLayer.queryFeatures(query);
   function zoomTo(response) {
    var parcel = response.features[0];
    //var parcelExtent = response.features[0].geometry.getExtent().expand(0.5);
    return (parcel);

Here is my zoomed map with the code above -- as you can see, it's not showing the full extent of the polygon I need to have zoomed into: 

Here is a more preferable view one click zoomed out (though I'd rather have the polygon fill the space, but be completely visible in the map): 




Thanks for any ideas.