new GraphicsLayer(null) fails in 3.9

1314
6
04-09-2014 11:54 PM
ThomasCoopman
New Contributor II
When running this code in 3.9:

var l = new GraphicsLayer(null)


In 3.9 you get this error:

TypeError {stack: "TypeError: Cannot read property 'plugins' of undef???esolve (http://js.arcgis.com/3.9/init.js:197:441)", message: "Cannot read property 'plugins' of undefined"}
 "TypeError: Cannot read property 'plugins' of undefined
    at http://js.arcgis.com/3.9/init.js:1005:336
    at Object.some (http://js.arcgis.com/3.9/init.js:224:133)
    at g._pluginsHandler (http://js.arcgis.com/3.9/init.js:1005:305)
    at h.(anonymous function).g (http://js.arcgis.com/3.9/init.js:239:390)
    at new <anonymous> (http://js.arcgis.com/3.9/init.js:105:288)


In 3.8 this worked just fine. Solving this is easy of course (don't pass null to the GraphicsLayer).
0 Kudos
6 Replies
JonathanUihlein
Esri Regular Contributor
Thanks for the feedback!

According to the documentation, GraphicsLayer accepts an object that contains optional parameters.
Although 'null' is an object according to typeof(), there are obviously no properties, but perhaps GraphicsLayer does not account for this particular use-case.

Is there any particular reason you were passing null to GraphicsLayer?
Otherwise, like you said, just don't pass null and follow the documentation.

// No optional params example
var graphicsLayer1 = new GraphicsLayer();

// Optional param example; opacity
var graphicsLayer2 = new GraphicsLayer({opacity:0.20});
0 Kudos
ThomasCoopman
New Contributor II
Is there any particular reason you were passing null to GraphicsLayer?
Otherwise, like you said, just don't pass null and follow the documentation.


No reason, I just validate it now. This was code that worked in 3.8 so this was something that I needed to fix to update.
0 Kudos
TomTyndall
New Contributor III
I'm encountering this issue also. In my code I'm extending esri/layers/GraphicsLayer as follows:

in a file my/GL.js

define(["dojo/_base/declare", "esri/layers/GraphicsLayer"], function (declare, esriGL) {
   return declare(esriGL, {
       constructor: function (options, graphics, symbol) {
           // graphics & symbol arguments optional
           // if present, do something interesting with them
       }
   });
});


then sometimes my GL gets called like this:

require(["my/GL"], function (myGL) {
    var gl = new myGL({id: "someId"}, null, null);
});




This code runs successfully in 3.8 but fails in 3.9.

I suspect that at @ 3.9 esri/layers/GraphicsLayer is looking for some newly introduced, undocumented 2nd parameter in its constructor (or some other dojo declare lifecycle function), is finding null and throwing a "plugins" error similar to what tcoopman describes.

However, even when I augment my custom layer with a dojo preamble function, which should result in the null arguments not getting passed along to the superclass's constructor, I still get the error. So I'm not really sure what's going on??


define(["dojo/_base/declare", "esri/layers/GraphicsLayer"], function (declare, esriGL) {
   return declare(esriGL, {

       preamble: function (options, graphics, symbol) { return [options]; },

       constructor: function (options, graphics, symbol) {
           // graphics & symbol arguments optional
           // if present, do something interesting with them
       }
   });
});


Tom
Az Dept. of Transportation
0 Kudos
JérômeDuckers
New Contributor III

Hi Tom,

Do you find something to solve your problem ?

With Arcgis 4.x  when I try to inherit of GraphicsLayer I receive : 

      Uncaught TypeError: Cannot read property 'properties' of undefined

Jérôme.

0 Kudos
TomTyndall1
New Contributor II

That's way back Jérôme but I did dig up some old code (see attached).  I don't think this is in use in any of our applications anymore so I'm not sure of its viability.

Also, since v4 was a complete rewrite from v3 I'm not sure how applicable it is to your problem - but here it is anyway, hope it helps.

Tom

0 Kudos
JérômeDuckers
New Contributor III

Thanks Tom, 

Finally, I rewrite my code in TypeScript.

The inheritance is easier to implement.

Best Regard,

Jérôme.

0 Kudos