New Code: I updated the code a bit to more a recent recent version of the api, but ashima was correct in that I was not passing my layer as an array. Fixed that and it worked
map = new Map("map", {
basemap: "streets",
center: [ -84.32, 46.5], // long, lat
zoom: 13
});
//fetches myMap layer
var myMap = new FeatureLayer(myMapLocation, {
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
}, "legend");
legendDijit.startup();
}
});
map.addLayers([myMap]);
So I've been using the ESRI Javascript API, so far what I've been able to do is create a map, fetch a layer from another source and combine them, but I'm stuck on grabbing the legend from the other source and also adding that. This is what I currently have after my attempts (also tried switching the map : map to map : mymap) The myMapLocation is just set to "/MapServer" and not "/mapServer/layers" or anything
map = new Map("mapDiv", {
basemap: "streets"
});
myMap = new esri.layers.ArcGISDynamicMapServiceLayer(myMapLocation);
map.on('layers-add-result', function () {
//this section breaks v
var legend = new Legend({
map: map,
layerInfos: legendLayers
}, "legendDiv");
// ^
legend.startup();
});
legendLayers.push({ layer: myMap });
map.addLayers([myMap]);