Dojo AMD and creating instance of esri classes

700
4
Jump to solution
12-15-2012 09:01 PM
RahulMetangale1
Occasional Contributor II
Hi All,

I wanted to know in following code why we have to instantiate map as new esri.Map() and not as new myMap()

define(["dojo/_base/declare", "core_library/_Widget", "esri/map"], function (declare, WidgetBase, myMap) {      return declare([WidgetBase], {         _map: null,          postCreate: function () {             this._map = new esri.Map(this.domNode, { extent:initExtent,slider: true });                      }     }); });
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor
As of right now there are still parts of the API that are not fully AMD, as in they don't all return an object. The map is still one of these. It provides "esri/map" in it's define method and has a dojo.provide("esri.map"). A lot of the API has been updated since 3.0 to return objects via AMD, but not completely yet. I'm sure it's a big task on their end.

View solution in original post

0 Kudos
4 Replies
JohnnyPenet
New Contributor
As you showed here, myMap will be created but with empty parameters by AMD, which is not usefull and will fail because a node is mandatory, you need a node as you showed in the postCreate.
If you want to create a new class you must replace "esri/map" by [esri/map] and remove myMap from the list of arguments)
It is not clear the purpose of "core_library/_Widget"

Hi All,

I wanted to know in following code why we have to instantiate map as new esri.Map() and not as new myMap()

define(["dojo/_base/declare", "core_library/_Widget", "esri/map"],
function (declare, WidgetBase, myMap) {

    return declare([WidgetBase], {
        _map: null,

        postCreate: function () {
            this._map = new esri.Map(this.domNode, { extent:initExtent,slider: true });
            
        }
    });
});
0 Kudos
RahulMetangale1
Occasional Contributor II
Thank you the replay.

core_library/_widget is superclass from which following class is derived. it has some additional functions which i am using it for some other purpose.

I am still not clear on why it is not possible to use local variable to instantiate map.  Let me rephrase my questions again,

define(["dojo/_base/declare", "core_library/_Widget", "esri/map","dijit/form/Button"],
function (declare, WidgetBase, myMap,Button) {

    return declare([WidgetBase], {
        _map: null,

        postCreate: function () {
  /*
                 where Button is a local varibale.Now we can use new Button() to instantiate button 
                 instead of new dijit.form.Button()
               */
  var myButton = new Button({
                                      label: "Click me!",
                                      onClick: function(){}
                                      }, "someNode");
 /* 
 but for map although we have local variable named myMap,following does not work
        */
            this._map = new myMap(this.domNode, { extent:initExtent,slider: true });
        //following works
     this._map=new esri.Map(this.domNode, { extent: initExtent, slider: true });
        }
    });
});
0 Kudos
ReneRubalcava
Frequent Contributor
As of right now there are still parts of the API that are not fully AMD, as in they don't all return an object. The map is still one of these. It provides "esri/map" in it's define method and has a dojo.provide("esri.map"). A lot of the API has been updated since 3.0 to return objects via AMD, but not completely yet. I'm sure it's a big task on their end.
0 Kudos
RahulMetangale1
Occasional Contributor II
Thank you!
0 Kudos