map.disablePan() can not stop pan immediately. Who can?

1357
1
10-09-2013 11:58 PM
Imihiro
New Contributor II
Background:
     Out-of-mapDiv Pan may cause unstoppable Pan in some case.
     Inside mapDiv Pan   is in desperate need.
     Code below intended to disable pan The moment mouse move out mapDiv. It failed when mouse Left not released.

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>map.disablePan doesn't work immediately.</title>
    <link rel="stylesheet" href="http://js.arcgis.com/3.7/js/esri/css/esri.css"/>
    <style>
      html,body,#mapDiv{
        padding:0;
        margin:0;
        height:100%;
      }
 #dvBind{
  position:absolute;
  background:rgb(220,220,220);
  cursor:pointer;
  z-index:2;
  left:100px;
  top:100px;
 }
    </style>
    <script src="http://js.arcgis.com/3.7/"></script>
    <script>
      dojo.require("esri.map");
      var map; 
      var mouseOutHandler=null;
      
      dojo.ready(function(){
       //create map and add a dynamic layer
        map = new esri.Map("mapDiv");       
            var imageParameters = new esri.layers.ImageParameters();
            imageParameters.format = "jpeg";            
            var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer", {
              "opacity":0.5, 
              "imageParameters":imageParameters
            });            
            map.addLayer(dynamicMapServiceLayer);
           
            //bind UI events. 
            document.getElementById("dvBind").onclick=function(){             
             if(mouseOutHandler==null){
              console.log("map.mouseOut is binded");
              mouseOutHandler= dojo.connect(map,"onMouseOut",function(){
                     map.disablePan();
                     console.log("map.onMouseOut is triggered. map.disablePan() is executed. However, if the left button is not released, pan the map at your will!");
                     console.log("If you know any way to STOP PAN IMMEDIATELY, leave a message, Thank you!");
                    });
             }
            };           
      });
    </script>
  </head>
  <body>
   <div id="dvBind" title="Click me to bind map.onMouseOut">Bind map.onMouseOut</div>
    <div id="mapDiv"></div>
  </body>
</html>


Normal readers in this forum are really quiet,they read, never reply. They ask, never reply.
Senior Members are too busy to answer naive question like this.
Ok, No one expect a answer with detail here. One clue , one sentence is enough.
Could you guys make a noice like Gr......,En.....,Yeah.... to make this place like a forum rather than a Zoo?
1 Reply
SebastianFrey
New Contributor

Hey,

I don't know if you already have found a solution for your problem or not. So I would like to share my solution with you.

To stop map pan immediatly you can do this:

var map = new Map(args);

map.on("mouse-out", function(evt)
{
  map.navigationManger._panEnd(); // disconnects all pan handles.
});

The lower dash indeed indicates that the method is private..., anyway it works like a charm! 😃

0 Kudos