user4103576
user4103576

Reputation:

Type error: Undefined is not a function (esri map)

I am getting a very strange error after upgrading dojo code to 2.x. The function is defined as:

var map; //Globally defined   
Require(["esri/map", "esri/geometry/Point"], function(Map, Point) {    

map = new Map("map", {infoWindow: popupWin, extent: initialExtent, sliderStyle: 'small', sliderPosition: "bottom-right", navigationMode: 'css-transforms'});  
var a = (map.toMap(new Point(0, 0));  
});

However, as I execute map.toMap() function in console, it works fine. Does anyone have any idea where I'm going wrong? It's been getting so confusing...

Upvotes: 1

Views: 619

Answers (1)

iH8
iH8

Reputation: 28638

Did you try including domReady!? It will cause the function to wait untill the DOM is loaded.

require([
    "esri/map",
    "esri/geometry/Point",
    "dojo/domReady!"
], function(){
    // will not run until DOM is finished loading
});

Otherwise it could be that your includes aren't registered yet which you could solve by wrapping your code in dojo/ready.

require([
    "esri/map",
    "esri/geometry/Point",
    "dojo/ready"
], function(map, Point, ready){
    ready(function(){
        // This function won't run until the DOM has loaded and other modules that register
    });
});

Upvotes: 2

Related Questions