2013-10-11 57 views
1

我有另一個問題,也許有人可以幫我修復。我試圖遵循示例代碼HEREdojo複選框對象和ArcGIS JS api

我試圖將代碼合併到一個更大的腳本中 - 除了複選框沒有出現,一切正常。

這裏是我的代碼:

<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

嘗試增加的dijit /表格/複選框,您需要聲明。