We're using ESRI's ArcGIS Javascript API with a tiled basemap and when the user zooms in using a rubberband selection via the navigation toolbar the map sometimes zooms in too far. This is apparently expected behaviour (not sure why!) when using the API with a tiled map service. However, we need to change this behaviour since this is a usability issue.

When calling map.setExtent() directly it's possible to change the default behaviour by specifying the fit option. Eg. map.setExtent(extent, true). Unfortunately, we can't find a way to specify this option when zooming using the Navigation toolbar. The only way to fix this that we could find was by overriding setExtent() in a custom sub-class of esri.Map. We ended up having to override the setLevel() method as well because just blindly setting the fit option to true inside our setExtent() method caused the setLevel() method to fail as the zoom level was sometimes overridden.

Functional workaround:

dojo.declare("MyMap", esri.Map, {
  levelling : false,

  setExtent : function(extent, fit) {
    var shouldfit = fit;
    if (fit === undefined && !this.levelling) { 
      shouldfit = true; 
    this.inherited(arguments, [extent, shouldfit]);

  setLevel : function(level) {
    this.levelling = true;
    try { 
    finally { 
      this.levelling = false; 

I'm not happy with the workaround above and feel we must be missing an obvious, simple way to change the zoom behaviour to use the fit option without resorting to the hack above. Does anyone know of a better way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.