tjrourke

Navigation toolbar buttons work once only

Discussion created by tjrourke on Oct 22, 2010
Latest reply on Nov 2, 2010 by tjrourke
My current customer uses jQuery as their standard for web scripting, so we try to use Dojo only when it's absolutely necessary for ArcGIS JavaScript API functions to work. I've implemented a toolbar with buttons for functions including pan, zoom in, zoom out, etc. The buttons' click events call functions in a map script; these functions look like this:

pan: function ()
{
    navToolbar.deactivate();
    activeToolButton = "pan";
    navToolbar.activate(esri.toolbars.Navigation.PAN);
},

zoomIn: function ()
{
    navToolbar.deactivate();
    activeToolButton = "zoomin";
    navToolbar.activate(esri.toolbars.Navigation.ZOOM_IN);
},

zoomOut: function ()
{
    navToolbar.deactivate();
    activeToolButton = "zoomout";
    navToolbar.activate(esri.toolbars.Navigation.ZOOM_OUT);
}
This works OK - the first time anyone uses the zoom in or zoom out. The second time they try to click, the map pans while they are drawing the zoom box; the map moves with the cursor and the box expands. When the mouse button is released, the maps zooms, but to the area centered on the first point that was clicked.

The map script does include lines to require the esri toolbar, dojo form Button and Toolbar.
I added the navToolbar.deactivate to try to force the API to act as it is supposed to act, but it hasn't much effect.
I also added a line in the map initialization function to disable the automatic pan but it has no effect at all - with or without the navToolbar.

Is the dojo toolbar required to make this work? Has anyone else seen this kind of behavior and found a workaround?

EDIT:
The workaround I'm using is shown below, but it would be nice to know why our map and toolbar don't behave like the one in the sample. In this workaround I added redundant activation calls to the map extent handler:

function mapExtentChangeHandler()
{
    mapExtentIsFirst = navToolbar.isFirstExtent();
    jQuery('#zoomPrevious').attr('disabled', mapExtentIsFirst);
    mapExtentIsLast = navToolbar.isLastExtent();
    jQuery('#zoomNext').attr('disabled', mapExtentIsLast);
    switch (activeToolButton)
    {
        case "zoomin":
            //navToolbar.activate(esri.toolbars.Navigation.ZOOM_IN);
            zoomInMap(_common.Map);
            break;
 
        case "zoomout":
            navToolbar.activate(esri.toolbars.Navigation.ZOOM_OUT);
            zoomOutMap(_common.Map);
            break;
 
        default:
            navToolbar.activate(esri.toolbars.Navigation.PAN);
            panMap(_common.Map);
            break;
    }
}

Outcomes