首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >触发multipleDefine错误的ArcGIS Api (Esri)

触发multipleDefine错误的ArcGIS Api (Esri)
EN

Stack Overflow用户
提问于 2017-10-30 12:56:12
回答 1查看 493关注 0票数 0

在我的代码中使用ArcGIS API for JavaScript v4.4时,我遇到了这个奇怪的问题。我正在尝试构建一个Excel Web外接程序,我想在其中加载一个ArcGIS地图,但当我加载ArcGIS时,我得到了一个multipleDefine错误。

ArcGIS与Dojo捆绑在一起,它被用作所有ArcGIS/esri包的加载器。由于ArcGIS构建其应用程序接口的方式,我没有其他选择来使用Dojo加载我自己的自定义JS包。因此,我不能决定不使用Dojo,因此不能得到multipleDefine错误。

我像这样加载我自己的JS文件:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>

<script>
    var dojoConfig = {
        parseOnLoad: false,
        async: false,
        // we make aliases for our js file
        aliases:  [
            ['index',  './Bundles/index.js'],
        ],
    };
</script>
<script src="https://js.arcgis.com/4.4/init.js"></script>
<script>
    require(['index'], function (index) {
        //...do something
    });
</script>

当我重新启动页面时,每2/3次试验中就会出现一次multipleDefine错误。经过大量调查,我知道错误出在Office.js应用程序接口上,但我很难找到一个好的解决方案。

EN

回答 1

Stack Overflow用户

发布于 2017-10-30 12:56:12

过了一段时间,我找到了问题的原因;我们不能一起启动multipleDefined -js和Dojo,因为它们都想在页面的head标签中添加脚本,但不知何故它们彼此冲突,因此我们得到了可怕的office-js Dojo错误,并且我们的一些文件无法加载。

一旦确定了原因,我决定通过确保在Office和依赖项完全加载后加载Dojo、Argis和我的自定义js文件来解决它。

我在我的js代码中是这样实现的:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
// This Dojo config variable has to be defined before Dojo is loaded in our scripts
var dojoConfig = {

    // we make aliases for our custom js file
    aliases: [
        ['index', './Bundles/index.js'],
    ],

    // We require our dependencies (our own code bundles) with Dojo. 
    // Notice that it is mandatory to bundle our js files
    // as AMD Modules for Dojo to be able to load them as dependencies.
    deps: ['index'],
};

// Once office has fully initialized we can add our arcgis file and let 
// him load our own required javascript files.
// We cannot start Office-js and Dojo/Arcgis together because they both 
// want to add scripts in the head tag of the HTML page and
// somehow they end up in conflict, thus we get the dreaded 
// multipleDefined Dojo error and some of our files
// do not get loaded.

Office.initialize = function (reason) {
    // we manually add the Arcgis script to the header of our page
    // once we are sure Office and dependencies has fully loaded.
    var tag = document.createElement('script');
    tag.src = 'https://js.arcgis.com/4.4/init.js';
    document.getElementsByTagName('head')[0].appendChild(tag);
};

一旦添加了这一点,代码就开始像护身符一样工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47015850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文