我还有另一个问题,也许有人可以帮我修复。我正在尝试按照示例代码HERE。
我正在尝试将代码合并到一个更大的脚本中 - 除了没有出现复选框外,一切正常。
这是我的代码:
<script>
require([
"esri/map",
"esri/dijit/HomeButton",
"esri/layers/FeatureLayer",
"esri/dijit/Legend",
"dojo/_base/array",
"dojo/parser",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dijit/layout/AccordionContainer",
"dojo/domReady!"
], function(Map, HomeButton, FeatureLayer, Legend, arrayUtils, parser){
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 junctions = new FeatureLayer("http://54.243.188.50:6080/arcgis/rest/services/TYLIN/Streetlights_Pilot/MapServer/0", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
var power = new FeatureLayer("http://54.243.188.50:6080/arcgis/rest/services/TYLIN/Streetlights_Pilot/MapServer/1", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
var cityNorth = new FeatureLayer("http://54.243.188.50:6080/arcgis/rest/services/TYLIN/Streetlights_Pilot/MapServer/2", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
var citySouth = new FeatureLayer("http://54.243.188.50:6080/arcgis/rest/services/TYLIN/Streetlights_Pilot/MapServer/3", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
var controllers = new FeatureLayer("http://54.243.188.50:6080/arcgis/rest/services/TYLIN/Streetlights_Pilot/MapServer/4", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
var circuits = new FeatureLayer("http://54.243.188.50:6080/arcgis/rest/services/TYLIN/Streetlights_Pilot/MapServer/6", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
var elec = new FeatureLayer("http://54.243.188.50:6080/arcgis/rest/services/TYLIN/Streetlights_Pilot/MapServer/8", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
var cityBoundary = new FeatureLayer("http://54.243.188.50:6080/arcgis/rest/services/TYLIN/Streetlights_Pilot/MapServer/9", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
var curbs = new FeatureLayer("http://54.243.188.50:6080/arcgis/rest/services/TYLIN/Streetlights_Pilot/MapServer/10", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
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.on("layers-add-result", function(evt){
var layerInfo = arrayUtils.map(evt.layers, function(layer, index){
return {
layer: layer.layer,
title: layer.layer.name
};
});
dojo.forEach(layerInfo, function(layer){
var layerName = layer.title;
var checkBox = new dijit.form.CheckBox({
name: "checkBox" + layer.layer.id,
value: layer.layer.id,
checked: layer.layer.visible,
onChange: function(evt){
var clayer = map.getLayer(this.value);
clayer.setVisibility(!clayer.visible);
this.checked = clayer.visible;
}});
dojo.place(checkBox.domNode, dojo.byID("toggle"), "after");
var checkLabel = dojo.create('label', {
'for': checkbox.name,
innerHTML: layerName
}, checkBox.domNode, "after");
dojo.place("<br />", checkLabel, "after");
});
});
map.addLayers([junctions, power, cityNorth, citySouth, controllers, circuits, elec, cityBoundary, curbs]);
});
</script>
答案 0 :(得分:0)
尝试将dijit / form / CheckBox添加到您的require语句中。