Select to view content in your preferred language

onUpdateEnd, onUpdateStart events for esri.layers.Layer

2785
2
04-03-2010 03:29 PM
JohnCartwright
Deactivated User
Hello All,

it appears that the onUpdateEnd event only fires for visible layers - is this by design?

Looking at the sample (http://help.arcgis.com/en/webapi/javascript/arcgis/demos/map/map_showloading.html), this will only work if all layers are visible.

Also, the onUpdateStart event does not behave as I would expect.  It does not fire when a layer is added to a Map like the onUpdateEnd does.  It does fire with zoom/pan, but only fires once even through there are multiple layers.  In this example I have four Layers added to a Map - two visible, two non-visible.  On a zoom/pan onUpdateEnd fires twice, onUpdateStart fires only once.

Am I missing something here?

Thanks!

--john
0 Kudos
2 Replies
KellyHutchins
Esri Notable Contributor
Hi John,

I'm trying to reproduce the issue you are experiencing but in my test case (see below) OnUpdateStart and OnUpdateEnd fire for each layer that's listening for the event.  In my testing both events fire when layers load and update themselves.
You are correct, all the update events (onUpdate,onUpdateStart,onUpdateEnd) only fire for visible layers.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"

   "http://www.w3.org/TR/html4/strict.dtd"> 
<html lang="en"> 
  <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=7" /> 
    <title>Map loading image</title> 
 
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.0/js/dojo/dijit/themes/tundra/tundra.css"> 
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0"></script> 
 
    <script type="text/javascript"> 
      dojo.require("esri.map");

      var dynamicMapServiceLayer;
      function init() {       
        var map = new esri.Map("map");
   
        //Takes a URL to a map in a map service.
        var tiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer");
        map.addLayer(tiledMapServiceLayer);
        
        dojo.connect(tiledMapServiceLayer, "onUpdateEnd", UpdateEnd);
        dojo.connect(tiledMapServiceLayer,"onUpdateStart",UpdateStart);

        
        var statesLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer");
        map.addLayer(statesLayer);
        dojo.connect(statesLayer,"onUpdateEnd",UpdateEnd);
        dojo.connect(statesLayer,"onUpdateStart",UpdateStart);

        //Takes a URL to a non cached map service.
        dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer");
        dynamicMapServiceLayer.setOpacity(0.5);
        dynamicMapServiceLayer.setVisibility(false);
        map.addLayer(dynamicMapServiceLayer);
        
        dojo.connect(dynamicMapServiceLayer, "onUpdateEnd", UpdateEnd);
        dojo.connect(dynamicMapServiceLayer,"onUpdateStart", UpdateStart);
   
 
      }

      function UpdateStart(){
        console.log(this.url + " Update Start");
      }
      function UpdateEnd(){
        console.log(this.url + " Update End");
      }
      function setVisible(){
        dynamicMapServiceLayer.setVisibility(!dynamicMapServiceLayer.visible);
      }
      dojo.addOnLoad(init);
    </script> 
  
  </head> 
  <body class="tundra"> 
    <button onClick="setVisible();">Toggle Dynamic Layer Visibility</button>
    <div id="map" style="position:relative; width:1024px; height:512px; border:1px solid #000;"> 
      <img id="loadingImg" src="images/loading.gif" style="position:absolute; right:512px; top:256px; z-index:100;" /> 
    </div> 
  </body> 
 
</html> 
0 Kudos
JohnCartwright
Deactivated User
Hi John,

I'm trying to reproduce the issue you are experiencing but in my test case (see below) OnUpdateStart and OnUpdateEnd fire for each layer that's listening for the event.  In my testing both events fire when layers load and update themselves.
You are correct, all the update events (onUpdate,onUpdateStart,onUpdateEnd) only fire for visible layers.


Thanks for your reply Kelly, and sorry to be so long getting back to this.  I don't understand why my example (see attached) behaves differently.  I'm finding that the onUpdateEnd is firing for visible layers while the onUpdateStart is not.  I also don't understand why they're firing at all prior to any zoom, pan operation.  The callback is only attached once all layers have been loaded and added to the map.

Can you see what I'm doing wrong here?

Thanks again for your help!

--john
0 Kudos