I see what you mean. Here are some thoughts though I am sure there are numerous other solutions out there:
1) setExtent(extent, fit?) note that there is fit? option. If you are using Tiled layers then maybe this would help? Not sure, never really used this option. Here is the documentation: http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/map.html#Map/setExtent NOTE: read the documentation on this. I am not sure if I am correct on my assumption of the fit? param.
2) Generally, I like to expand the extent so that it gives the map a little room/margin around your selected feature. map.setExtent(extent.expand(expandFactor));
I see what you mean. Here are some thoughts though I am sure there are numerous other solutions out there:
1) setExtent(extent, fit?) note that there is fit? option. If you are using Tiled layers then maybe this would help? Not sure, never really used this option. Here is the documentation: http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/map.html#Map/setExtent NOTE: read the documentation on this. I am not sure if I am correct on my assumption of the fit? param.
2) Generally, I like to expand the extent so that it gives the map a little room/margin around your selected feature. map.setExtent(extent.expand(expandFactor));
In my applications where I have a tiled basemap and I perform a zoom to a feature, I check whether the extent of that feature is contained by the extent of the map. If not, then I move out one level.
Although this code is for Flex, you should be able to use the same logic in JavaScript
map.extent = feature.extent;
if (!map.extent.contains(feature.extent))
{
map.level--;
}