将dojo代码升级到2.x后,我收到一个非常奇怪的错误。该函数定义为:
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));
});
但是,当我在控制台中执行map.toMap()函数时,它工作正常。有谁知道我哪里出错了?它变得如此令人困惑......
答案 0 :(得分:2)
您是否尝试过domReady!?它将导致函数等待,直到加载DOM。
require([
"esri/map",
"esri/geometry/Point",
"dojo/domReady!"
], function(){
// will not run until DOM is finished loading
});
否则可能是您的包含尚未注册,您可以通过将代码包装在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
});
});