I cannot get an ArcGIS Javascript API Legend widget to show up. An excerpt of my code is as follows. I believe I'm failing somewhere near the console.log that I call...undefined comes up in the console at this point. So for some reason evt.layers is not getting populated. Have I provided enough code? If you need more snippets I can copy/paste more.
parser.parse(); //initialize the map object map = new Map("map", { basemap:"gray", center: [-96.53, 38.374], zoom: 13 }); //access the hydro layer as a feature layer var hydro = new FeatureLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hydrography/Watershed173811/MapServer/0", { mode: FeatureLayer.MODE_ONDEMAND, outFields: ["*"] }); //add hydro to map map.on("layer-add-result", function (evt) { console.log(evt.layers); 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([hydro]); });
أكثر...
parser.parse(); //initialize the map object map = new Map("map", { basemap:"gray", center: [-96.53, 38.374], zoom: 13 }); //access the hydro layer as a feature layer var hydro = new FeatureLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hydrography/Watershed173811/MapServer/0", { mode: FeatureLayer.MODE_ONDEMAND, outFields: ["*"] }); //add hydro to map map.on("layer-add-result", function (evt) { console.log(evt.layers); 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([hydro]); });
أكثر...