如果这很简单,请原谅我,但我无法找到解决问题的方法。
我正在尝试在引导模式中打开 ESRI map 。第一次它没有加载 map (在控制台中我看到错误“require is not defined”)但是第二次它工作正常。如果我在单独的窗口中打开 map ,那么它每次也能很好地工作。
我的部分 View 如下所示:
@{
<link rel="stylesheet" href="https://js.arcgis.com/3.21/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.21/esri/css/esri.css">
<script src="https://js.arcgis.com/3.21/"></script>
<script>
var map;
require([
"esri/map",
"dojo/parser",
"dojo/domReady!"
],
function (
Map,
parser
)
{
parser.parse();
map = new Map("map", {
basemap: "streets",
center: [5.79, 50.97], // lon, lat
zoom: 16,
slider: false
});
});
</script>
}
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4>DrawProjectLocation</h4>
</div>
<div class="modal-body">
<div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline', gutters:false" style="width:100%; height:100%;">
<div id="map" class="roundedCorners" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'">
</div>
<div id="footer" class="roundedCorners" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'bottom'">
<div id="editorDiv"></div>
</div>
</div>
</div>
<div class="modal-footer">
<span id="info" style="position:absolute; left:15px; bottom:15px; color:#000; z-index:100"></span>
<button type="submit" class="btn btn-success" id="submitButton">Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
我试图在我的部分 View 中包含 require.js 但它没有帮助。有人可以告诉我这里出了什么问题吗?谢谢!!
最佳答案
最后我通过在主视图而不是局部 View 上为 ArcGIS 添加 js 解决了这个问题。由于 RequireJS 是异步加载的,所以其他脚本/函数不会等到它完全加载。
另一种解决方法是通过为 RequireJS 设置配置来加载引导模式,以确保最初加载所有必需的脚本。可以找到示例 here
关于javascript - 未为 ArcGIS 服务器 map 定义 Bootstrap 模式要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45501806/