错误屏幕截图在这里,我想在ArcGIS Api for JS中使用dojo,但是当我通过cdn链接导入dojo时,它给了我脚本错误。添加了代码的SS和错误。 我正在使用版本 4.29 的 ArcGIS Map SDK for Javascript。当我使用 CDN 链接包含 dojo 时,它会给我脚本错误,如此处附加的错误屏幕截图所示。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial: Hello Dojo!</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.29/esri/themes/light/main.css">
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"
data-dojo-config="async: true"></script>
</head>
<script src="https://js.arcgis.com/4.29/"></script>
<body>
<script>
require([
"dojo/dom",
"dojo/dom-construct",
"esri/config",
"esri/Map",
"esri/views/MapView",
], function (dom, domConstruct, esriConfig, Map, MapView) {
esriConfig.apiKey = "API KEY HERE ";
const map = new Map({
basemap: "arcgis/topographic"
});
const view = new MapView({
container: "viewDiv",
map: map,
center: [-118.243683, 34.052234],
zoom: 13
});
});
</script>
<h1 id="viewDiv"></h1>
</body>
</html>
您遇到的错误可能是由库导入的顺序引起的。 您还需要指定名称是什么
dojo
,如果没有,它将尝试在esri
库中搜索它。
那么,
dojoConfig
指定什么是 dojo
以及您需要的任何其他模块<script>
) 首先 arcgis
,第二dojo
例如,
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<title>Using Dojo from CDN with ArcGIS Maps SDK for JavaScript 4.30</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 500px;
width: 100%;
}
</style>
<link rel="stylesheet" href="https://js.arcgis.com/4.30/esri/themes/light/main.css" />
<!-- i) declares names -->
<script>
var dojoConfig = {
packages: [{
name: "dojo",
location: "//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"
}]
};
</script>
<!--ii) import libraries -->
<script src="https://js.arcgis.com/4.30/"></script> <!--FIRST-->
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script> <!--SECOND-->
<!--iii) main-->
<script>
require([
"esri/Map", "esri/views/MapView", "dojo/dom", "dojo/dom-construct"
], (Map, MapView, dom, domConstruct) => {
const map = new Map({
basemap: "topo-vector"
});
const view = new MapView({
container: "viewDiv",
map: map,
zoom: 4,
center: [15, 65] // longitude, latitude
});
const greetingNode = dom.byId('greeting');
domConstruct.place('<em> Dojo!</em>', greetingNode);
});
</script>
</head>
<body>
<h1 id="greeting">Hello</h1>
<div id="viewDiv"></div>
</body>
</html>