我收到此错误:
TypeError:“未定义”不是函数(评估“parser.parse()”)
这是我的代码。
<script>
require([
"esri/map",
"esri/layers/FeatureLayer",
"esri/dijit/Legend",
"esri/digit/HomeButton",
"dojo/_base/array",
"dojo/parser",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dijit/layout/AccordionContainer",
"dojo/domReady!"
], function(
Map, FeatureLayer, Legend, arrayUtils, parser, HomeButton
) {
parser.parse();
var map = new Map("map", {
basemap: "streets",
center: [-87.702733, 41.998508],
zoom: 15
});
var home = new HomeButton ({
map: map
}, "HomeButton");
home.startup();
var circuits = new FeatureLayer("http://54.243.188.50:6080/arcgis/rest/services/TYLIN/Streetlights_Pilot/MapServer/6", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields:["*"]
});
var power = new FeatureLayer("http://54.243.188.50:6080/arcgis/rest/services/TYLIN/Streetlights_Pilot/MapServer/2", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields:["*"]
});
//add the legend
map.on("layers-add-result", function (evt) {
var layerInfo = arrayUtils.map(evt.layers, function (layer, index) {
return {layer:layer.layer, title:layer.layer.name};
});
if (layerInfo.length > 0) {
var legendDijit = new Legend({
map: map,
layerInfos: layerInfo
}, "legendDiv");
legendDijit.startup();
}
});
map.addLayers([circuits, power]);
});
</script>
我已经能够通过将 HomeButton 部分与 Legend 部分分开来运行它。在拐角处,我必须调用 dojo.parser.parse() ——但这不适用于 Legend 部分。
我不太了解 dojo/parser 是如何工作的,所以我很难理解为什么有些部分需要 dojo.parser.parse() 而其他部分需要 parser.parse()。