mhadi11

How stop Map while zooming in or out when a user press escape key?

Discussion created by mhadi11 on Feb 5, 2012
Hi,
I am trying to stop Map while zooming in or out when a user press escape key but unable to do so.
I am using Javascript API v2.6 as well as all layers are either Dynamic or Feature Layers.
Please note that I am not using any tiled layer neither Navigation Toolbar.

  I slowed the zoom animation of a map, attached functions to onZoom, onZoomStart and onZoomEnd events. Checked the onkeydown event for escape key.

                //Modify zoom animation to ridiculous duration and rate For demonstration purpose only
                 esriConfig.defaults.map.zoomDuration = 5000; 
                esriConfig.defaults.map.zoomRate = 100; 

                //Attach Function to onZoom, onZoomEnd and onZoomStart
                dojo.connect(map, "onZoom", DuringZoomProcess);
                dojo.connect(map, "onZoomEnd", ZoomProcessEnd);
                dojo.connect(map, "onZoomStart", ZoomProcessStart);

                // Attach Escape Key
                var key_event_handle = dojo.isIE ? dojo.query('body')[0] : window;
                dojo.connect(key_event_handle, "onkeydown", function(evt) {
                  if (evt.keyCode == dojo.keys.ESCAPE) {
                    map.infoWindow.hide();
                    // If Escape key is pressed and extentDuringZoom is not undefined or null
                    if(extentDuringZoom){
                        //Zoom to extentDuringZoom
                        map.setExtent(extentDuringZoom);
                    }
                  }
                });

    ZoomProcessStart: function(extent, zoomFactor, anchor, level) {
        //Clear extentDuringZoom
        mapControl.extentDuringZoom = null;
  },
    ZoomProcessEnd: function(extent, zoomFactor, anchor, level) {
        //When Zoom Ends we no longer need extentDuringZoom 
        mapControl.extentDuringZoom = null;
  },
    DuringZoomProcess: function(extent, zoomFactor, anchor) {
        //Get Current Zoom Extent
        mapControl.extentDuringZoom = extent;
  },


Using console messages I found out that
1. When user zooms in a Zoom Animation is started from Zoom Extent A to Zoom Extent B.
2. If a user presses escape key at Zoom Extent C the map stops there but does not load the map correctly.
3. If user re sizes the map or browser map is loaded at Zoom Extent B i.e. the initial target zoom rather than the latter one.

Is there any way to stop first zoom animation and then start the other zoom animation?

see the following log messages for the scenario


ExtentsExtent AExtent BExtent C
X min
21.54438904543688342.6335798220000623.2053167616934
Y Min
14.615148099999992 18.22364023339286 14.899674256848485
X Max
68.44102035456311 42.67392896300004 66.41124464448994
Y Max
32.492102318.25772929000004331.36973558892859



Running TaskRunner Run Function, Setting Map Extent, Extent Information : xmin = 42.63357982200006 ymin = 18.22364023339286 xmax = 42.67392896300004 ymax = 18.257729290000043
Event onZoomStart Fired Running ZoomProcessStart Extent Information : xmin = 21.544389045436883 ymin = 14.615148099999992 xmax = 68.44102035456311 ymax = 32.4921023
Event onZoom Fired Running DuringZoomProcess Extent Information : xmin = 21.544389045436883 ymin = 14.615148099999992 xmax = 68.44102035456311 ymax = 32.4921023
Running TaskRunner Run Function, Map Extent Set Hiding InfoWindow, Extent Information : xmin = 42.63357982200006 ymin = 18.22364023339286 xmax = 42.67392896300004 ymax = 18.257729290000043
Running TaskRunner Run Function, Info Window Hidden, Extent Information : xmin = 42.63357982200006 ymin = 18.22364023339286 xmax = 42.67392896300004 ymax = 18.257729290000043
Event onZoom Fired Running DuringZoomProcess Extent Information : xmin = 21.570924619179515 ymin = 14.61969379138852 xmax = 68.40859193368212 ymax = 32.47417096901165
Event onZoom Fired Running DuringZoomProcess Extent Information : xmin = 21.63768944906377 ymin = 14.63113097813282 xmax = 68.32700040585112 ymax = 32.4290548439696
Event onZoom Fired Running DuringZoomProcess Extent Information : xmin = 21.738459149533917 ymin = 14.648393388363516 xmax = 68.20385242757146 ymax = 32.36096003395148
Event onZoom Fired Running DuringZoomProcess Extent Information : xmin = 21.88857621331561 ymin = 14.674109276428439 xmax = 68.02039834540446 ymax = 32.25951889746897
Event onZoom Fired Running DuringZoomProcess Extent Information : xmin = 22.078442552690333 ymin = 14.706634436511226 xmax = 67.78836772778556 ymax = 32.131217312287724
Event onZoom Fired Running DuringZoomProcess Extent Information : xmin = 22.311037019885493 ymin = 14.746479162568555 xmax = 67.50412019841431 ymax = 31.97404232832899
Event onZoom Fired Running DuringZoomProcess Extent Information : xmin = 22.61258061950624 ymin = 14.798135258545884 xmax = 67.13561176300948 ymax = 31.770275183715516
Event onZoom Fired Running DuringZoomProcess Extent Information : xmin = 22.898642248396484 ymin = 14.847139206817278 xmax = 66.78602343341373 ymax = 31.576969932416013
Event onZoom Fired Running DuringZoomProcess Extent Information : xmin = 23.2053167616934 ymin = 14.899674256848485 xmax = 66.41124464448994 ymax = 31.36973558892859
Event onkeydown Fired & extentDuringZoom is not undefined Extent Information : xmin = 23.2053167616934 ymin = 14.899674256848485 xmax = 66.41124464448994 ymax = 31.36973558892859
Running Function ZoomToExtent, initializing TaskRunner, Extent Information : xmin = 23.2053167616934 ymin = 14.899674256848485 xmax = 66.41124464448994 ymax = 31.36973558892859
Running Function ZoomToExtent, Starting TaskRunner, Extent Information : xmin = 23.2053167616934 ymin = 14.899674256848485 xmax = 66.41124464448994 ymax = 31.36973558892859
Running Function ZoomToExtent, TaskRunner Started, Extent Information : xmin = 23.2053167616934 ymin = 14.899674256848485 xmax = 66.41124464448994 ymax = 31.36973558892859
Running TaskRunner Run Function, Stopping Task, Extent Information : xmin = 23.2053167616934 ymin = 14.899674256848485 xmax = 66.41124464448994 ymax = 31.36973558892859
Running TaskRunner Run Function, Task Stopped, Extent Information : xmin = 23.2053167616934 ymin = 14.899674256848485 xmax = 66.41124464448994 ymax = 31.36973558892859
Running TaskRunner Run Function, Setting Map Extent, Extent Information : xmin = 23.2053167616934 ymin = 14.899674256848485 xmax = 66.41124464448994 ymax = 31.36973558892859
Running TaskRunner Run Function, Map Extent Set Hiding InfoWindow, Extent Information : xmin = 23.2053167616934 ymin = 14.899674256848485 xmax = 66.41124464448994 ymax = 31.36973558892859
Running TaskRunner Run Function, Info Window Hidden, Extent Information : xmin = 23.2053167616934 ymin = 14.899674256848485 xmax = 66.41124464448994 ymax = 31.36973558892859
Event onZoomFinish Fired Running ZoomProcessEnd Extent Information : xmin = 42.60904146485315 ymin = 18.22364023339286 xmax = 42.698467320146946 ymax = 18.257729290000043

Outcomes