简体   繁体   English

多个javascript(不同版本)冲突

[英]Multiple javascript(different version) conflict

I've some problem using 2 APIs together, OneMap API and ESRI(Arcgis) API. 使用2个API(OneMap API和ESRI(Arcgis)API)时遇到一些问题。

My problem here is that I want to use OneMap API, which is based on ESRI(Arcgis) API but there are a few missing functionality in OneMap's API that I needed to complete my task, for eg featureLayer . 我的问题是我想使用基于ESRI(Arcgis)API的OneMap API,但是OneMap API中缺少一些我需要完成的功能,例如featureLayer This featureLayer which is found in ESRI(Arcgis) API is what I needed and I've tried to include both API, to call the featureLayer , but there will be errors and the map will not show. 我需要在ESRI(Arcgis)API中找到的featureLayer ,并且我尝试包括这两个API来调用featureLayer ,但是会出现错误,并且地图不会显示。 I guess that could be a conflict as I could use the APIs seperately. 我猜想可能会发生冲突,因为我可以单独使用API​​。

The reason why I chose to use OneMap is because its focused on Singapore and more detailed/updated information on the map as compared to ESRI's map. 我之所以选择使用OneMap是因为它专注于新加坡,并且与ESRI的地图相比,该地图上的信息更加详细/更新。

So is there a way to prevent this conflict when using the 2 API I've mentioned above? 那么在使用上面提到的2个API时,有没有一种方法可以防止这种冲突? or is there anyway to specify when to use which either API when needed by the function? 还是无论如何指定何时在函数需要时使用哪个API?

EDIT: Here are the error message, 编辑:这是错误消息,

Uncaught TypeError: Cannot read property 'dojo' of undefined 
Uncaught TypeError: Object #<Object> has no method '_loadPath' 

Based on the error messages, one of your libraries appears to require the Dojo library. 根据错误消息,您的一个库似乎需要Dojo库。 You should try including it, before including the other two libraries. 在包括其他两个库之前,您应该尝试包括它。

Once it is included ahead of the other libraries you should see those error messages disappear. 一旦将其包含在其他库之前,您应该会看到这些错误消息消失了。

Your code itself, which will create the map, needs to be included in the Dojo domReady plugin: 您的代码本身(将创建地图)需要包含在Dojo domReady插件中:

  <script>
    require(["esri/map", "dojo/domReady!"], function(Map) { 
      // code to create the map and add a basemap will go here 
    });
  </script>

I don't know anything specific about any of these libraries but it seems like this should at least get you past those errors (and possibly onto some new ones but we can deal with those when they occur). 我对这些库中的任何一个都一无所知,但是看来这至少可以使您克服这些错误(并且可能会遇到一些新的错误,但是当它们发生时我们可以进行处理)。

Based on an example from the ArcGIS site it seems like Dojo, or some portion of it, may be included already. 根据ArcGIS网站的示例,Dojo或其中的某些部分似乎已经包含在内。 Check out this where they include the library and then load up the map on dom ready (you would also need to include map styles and create an HTML element to hold the map (in this case a div with the ID of "mapDiv": 在包含库的地方检查一下,然后准备好在dom上加载地图(您还需要包括地图样式并创建HTML元素来保存地图(在本例中为ID为“ mapDiv”的div:

 <script src="http://js.arcgis.com/3.7/"></script>
  <script>
    var map;
    require(["esri/map", "dojo/domReady!"], function(Map) {
      map = new Map("mapDiv", {
        center: [-56.049, 38.485],
        zoom: 3,
        basemap: "streets"
      });
    });
  </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM