Unable to draw graphic (null): Deferred Cancelled

12919
8
08-03-2010 10:42 PM
SystemAdministrator
New Contributor
Hi

I am getting a JavaScript exception when selecting features from a FeatureLayer on the map. The selection *seems* to work (i.e the features are highlighted), however firebug reports this error:

dojo.io.script error Error: Deferred Cancelled

cancelResult: undefined
dojoType: "cancel"
fileName: http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0
lineNumber: 16
message: "Unable to draw graphic (null): Deferred Cancelled"
name: "Error"
stack: "Error("Deferred Cancelled")@:0 ()@http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0:16 ([object Object],0,[object Array])@http://serverapi.arcgisonline.com/jsapi/arcgis/2.0/js/esri/layers/FeatureLayer.xd.js:19 ([object Array],(function (dfd, id) {dfd = dfd || _4.io.script["jsonp_" + "dojoIoScript" + id];if (dfd) {try {dfd.cancel();_4.io.script._validCheck(dfd);} catch (e) {}}}))@http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0:16 (true)@http://serverapi.arcgisonline.com/jsapi/arcgis/2.0/js/esri/layers/FeatureLayer.xd.js:19 ([object Object],4,[object Object],6)@http://serverapi.arcgisonline.com/jsapi/arcgis/2.0/js/esri/layers/FeatureLayer.xd.js:19 ([object Object],4,[object Object],6)@http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0:16 ([object Object],4,[object Object],6)@http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0:16 ([object Object],4,[object Object],[object Object],true)@http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0:52 ([object HTMLDivElement])@http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0:52 ([object HTMLDivElement])@http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0:16 ("onEnd",[object Array])@http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0:16 (148)@http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0:16 (148)@http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0:16 (148)@http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0:16 (148)@http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0:16 "


Firebug also reports the following error:


dojo.io.script.jsonp_dojoIoScript_postcodes00_0_02197265625_1_3 is undefined



Here is the code I am using:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
  <meta http-equiv="X-UA-Compatible" content="IE=7" /> 
  <title>Layer in a map service - [ON-DEMAND]</title> 
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.0/js/dojo/dijit/themes/tundra/tundra.css"> 
 <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dojox/layout/resources/ResizeHandle.css"/> 
    <script type="text/javascript">djConfig = { parseOnLoad:true };</script> 
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0"></script> 
 
    <script type="text/javascript"> 
      dojo.require("esri.map");
      dojo.require("esri.layers.FeatureLayer");
   dojo.require("dijit.form.ComboBox")

      var selectionToolbar, featureLayer;
 
      function init() {
   
   
     var initialExtent = new esri.geometry.Extent(112.607,-43.825,154.882,-10.558, new esri.SpatialReference({wkid:4326}) );
        var map = new esri.Map("map", { extent: initialExtent, slider: true, nav: true });
        dojo.connect(map, "onLoad", initSelectToolbar);
        var baseMapLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");
        map.addLayer(baseMapLayer);
 
        var fieldsSelectionSymbol = new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255,255,0,0.5]));
        fieldsSelectionSymbol.setOutline(new esri.symbol.SimpleLineSymbol("dashdot", new dojo.Color([255,0,0]), 2));
  
        featureLayer = new esri.layers.FeatureLayer("http://arcgis:8399/arcgis/rest/services/maptest/MapServer/0",{
          mode: esri.layers.FeatureLayer.MODE_ONDEMAND
        });
 
        featureLayer.setSelectionSymbol(fieldsSelectionSymbol);
 
 
        map.addLayer(featureLayer);
      }
 
      function initSelectToolbar(map) {
        selectionToolbar = new esri.toolbars.Draw(map);
        var selectQuery = new esri.tasks.Query();
        dojo.connect(selectionToolbar, "onDrawEnd", function(geometry) {
          selectionToolbar.deactivate();
          selectQuery.geometry = geometry;
          featureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW);
        });
      }
   
   
  
 
    dojo.addOnLoad(init);
  </script> 
 
</head> 
 
<body class="tundra"> 
 <select dojoType="dijit.form.ComboBox" id="asgc" name="asgc">

  <option>
   ASGC Heirarchy 1
  </option>
  <option selected>
     ASGC Heirarchy 2
  </option>
  <option>
   ASGC Heirarchy 3
  </option>
 </select>

   
  <button dojoType="dijit.form.Button" onClick="selectionToolbar.activate(esri.toolbars.Draw.EXTENT);">Extent</button> 
  <button dojoType="dijit.form.Button" onClick="selectionToolbar.activate(esri.toolbars.Draw.LINE);map.hideZoomSlider();">Line</button> 
  <button dojoType="dijit.form.Button" onClick="selectionToolbar.activate(esri.toolbars.Draw.POLYLINE);map.hideZoomSlider();">Polyline</button> 
  <button dojoType="dijit.form.Button" onClick="selectionToolbar.activate(esri.toolbars.Draw.POLYGON);map.hideZoomSlider();">Polygon</button> 
  <button dojoType="dijit.form.Button" onClick="selectionToolbar.activate(esri.toolbars.Draw.FREEHAND_POLYLINE);map.hideZoomSlider();">Freehand Polyline</button> 
  <button dojoType="dijit.form.Button" onClick="selectionToolbar.activate(esri.toolbars.Draw.FREEHAND_POLYGON);map.hideZoomSlider();">Freehand Polygon</button> 
  <button dojoType="dijit.form.Button" onClick="featureLayer.clearSelection();">Clear Selection</button><br> 
  <div id="map" style="position: relative; width:1280px; height:768px; border:1px solid #000;">
  </div> 
  
  <span id="messages"></span> 

</body> 
</html>




I cannot afford to have JavaScript errors on the site I am working on, any help is greatly appreciated.
0 Kudos
8 Replies
Tara_StarrMarvin
New Contributor
Hello - Did you ever find a solution to this problem? I am getting the same problem when using FeatureLayer with "dojo.io.script error Error: Deferred Cancelled" and later "dojo.io.script.<name> is undefined". I have found no other information on this problem. Would appreciate it if you could share anything you have discovered.
0 Kudos
IhabEl_Attar
New Contributor
Hello,
I am getting a similar error in FireFox trying to zoom in\out on a feature layer.
http://forums.arcgis.com/threads/24176-dojo.io.script.jsonp_dojoIoScript-Error

Regards,
0 Kudos
MichelleVan_Broekhoven
New Contributor II
I had this same problem with a feature layer that drove me nuts. I believe in my case the jsonp callback string error (in dojo.io.script) was occurring because I tried to change both the featurelayer's visibility and layerdefinition, then change the map extent. My dev arcgis server is slow, so it takes a little time for the graphics in the featurelayer to redraw. If the layer isn't finished drawing before the map extent is changed, those errors were thrown.


I solved my problem by setting the layer definition before setting its visibility and creating a small time out function to give the layer time to draw. for example-

acuteLayer.setDefinitionExpression(defExp);
acuteLayer.setVisibility(true);
t=setTimeout(function(){updateZoomExtent(countyId, regionId)},500);

I also had luck by setting the visibility of the layer to false with the event onZoomStart and then making it visible again upon onZoomEnd.

//in the init function
dojo.connect(map, "onZoomStart", function(extent, zoomFactor, anchor, level){
     acuteLayer.setVisibility(false);
    });

dojo.connect(map, "onZoomStart", function(extent, zoomFactor, anchor, level){
     acuteLayer.setVisibility(true);
    });

I'll probably end up using the second method which so far works the best for my map.
ScottDavis
Occasional Contributor
onZoomStart and onZoomEnd fixed the problem for me. Thanks, mapstar!
0 Kudos
GeorgieCassar
Occasional Contributor
THANKYOU.
I have spent half a day wondering why I could not access the graphics of my featurelayer.
I added the event "onUpdateEnd" to my feature layer and voila I can access the graphics array !

ie:
dojo.connect(featureLayer, "onUpdateEnd", function() {
var zoomExtent = esri.graphicsExtent(featureLayer.graphics);  //this works now !
map.setExtent(zoomExtent); 
});
0 Kudos
RyanKoehnen
New Contributor III
I kept getting this error when a user rapidly zoomed in or out before the map finished drawing the feature layer. It was throwing an alert dialog. From what I can tell the error is meaningless because it's just indicating something went wrong when the xhr request for the current draw was canceled due to a new redraw.

I was able to suppress the annoying error dialog like by proxying the alert and throwing it away. In the below function, the alert is only returned back to the caller if the error is NOT the one in question. Otherwise, it's handled, no more error alert.

var proxied = window.alert;
window.alert = function(error) {
    if(error.message !== "Unable to draw graphic (null): Request canceled") {
 return proxied.apply(this, arguments);
    }
}
0 Kudos
LixianDai1
New Contributor
Hi, All,
I am also seeing this error. Any solution?
0 Kudos
YousefQuran
Occasional Contributor

I had face same problem, we cannot update tow feature layers at same time.

Re: Unable to draw graphic (null): Deferred Cancelled

Michelle Van BroekhovenLevel 1

Thank you sir.

We can solve it by timers depending onUpdateEnd and onZoomEnd. But I solved it in different way ..

if you have a small Feature Layer you can set the mood to the Snapshot mood, because the snapshot mood is dealing with a Feature layer just like a graphics. And it is works fine with me.