问题描述
我正在使用ArcGIS JSAPI 4.12,希望使用空间幻觉在地图上绘制军事符号
I'm using ArcGIS JSAPI 4.12 and wish to use Spatial Illusions to draw military symbols on a map.
当我在脚本中添加milsymbol.js
时,控制台返回错误
When I add milsymbol.js
to the script, the console returns error
所以我将type="module"
添加到脚本中,然后它返回
so I add type="module"
to the script, and then it returns
这是我的代码:
<link rel="stylesheet" href="https://js.arcgis.com/4.12/esri/css/main.css">
<script src="https://js.arcgis.com/4.12/"></script>
<script type="module" src="milsymbol-2.0.0/src/milsymbol.js"></script>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/MapImageLayer",
"esri/layers/FeatureLayer"
], function (Map, MapView, MapImageLayer, FeatureLayer) {
var symbol = new ms.Symbol("SFG-UCI----D", { size: 30 }).asCanvas(3);
var map = new Map({
basemap: "topo-vector"
});
var view = new MapView({
container: "viewDiv",
map: map,
center: [121, 23],
zoom: 7
});
});
</script>
因此,无论我是否添加type="module"
,总是存在错误.但是,在空间幻象的正式文档中,脚本中没有任何type="module"
.我现在真的很困惑.他们如何设法在不添加类型的情况下正常工作?
So, whether I add type="module"
or not, there are always errors. However, in the official document of Spatial Illusions, there isn't any type="module"
in the script. I'm now really confused. How do they manage to get it work without adding the type?
import { ms } from "./ms.js";
import Symbol from "./ms/symbol.js";
ms.Symbol = Symbol;
export { ms };
推荐答案
我收到此错误是因为我忘记了脚本标记中的type ="module":
I got this error because I forgot the type="module" inside the script tag:
<script type="module" src="milsymbol-2.0.0/src/milsymbol.js"></script>
这篇关于“未捕获的SyntaxError:无法在模块外部使用import语句"导入ECMAScript 6时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!