gyetmanesri-ca-esridist

Connect to onExtentChange with deferred web map

Discussion created by gyetmanesri-ca-esridist Employee on Dec 17, 2012
Latest reply on Dec 18, 2012 by gyetmanesri-ca-esridist
Hi,

I am trying to connect to the onExtentChange event of web map (from ArcGIS Online). I have tried two different methods with limited success. The first way I tried (see code below) is only called after the map loads, not after each extent change. The second way is called after the map loads and after every update to the map extents. However, only the first call is successful. The calls after the map loads (triggered by panning the map) give this error:

TypeError: _508.advice is null

from the javascript api. I assume that this is because after the initial load the map object I am passing is null. Any advice on how should I make the connection?

cheers,

Greg


   
<script type="text/javascript">
      dojo.require("esri.map");
   dojo.require("esri.arcgis.utils");
   var map, maxExtent,iniExtent, tiledMapServiceLayer;  

      function init() {
     // configure the proxy URL -- required to access Data not on the local server
  esri.config.defaults.io.proxyUrl = "/proxy/proxy.ashx";
    var lods = [ {"level" : 6, "resolution" : 2445.98490512499, "scale" : 9244648.868618},
               {"level" : 7, "resolution" : 1222.99245256249, "scale" : 4622324.434309},
               {"level" : 8, "resolution" : 611.49622628138, "scale" : 2311162.217155},
               {"level" : 9, "resolution" : 305.748113140558, "scale" : 1155581.108577},];
 
  var webmap = "longwebmapstring"
    iniExtent = new esri.geometry.Extent({"xmin": -7315000, "ymin": 5829000, "xmax": -4967000, "ymax": 6836000, "spatialReference":{"wkid":102100}});
  mapDeferred = esri.arcgis.utils.createMap(webmap, "map", {
          mapOptions: {
      extent:iniExtent,
   lods: lods,
                        slider: true,
   sliderStyle: "small",
                        nav:false
          }});
  mapDeferred.addCallback(function (response) {
   var map = response.map;
   //this line is only called on init
                        //dojo.connect(dijit.byId("map"), "onExtentChange", map, checkExtents(map));
                        //this line is called onExtentChange but the map passed is null.
   dojo.connect(map, "onExtentChange", checkExtents(map));
  });
}

     function checkExtents(map) {
   console.log("checkExtents called");
   console.log(map.extent);
  };
 
dojo.ready(init);
    </script>

Outcomes