For various reasons I need to add layers to a map object using a response returned by an esriRequest to an ArcGIS Server. One reason being the data will change constantly and hard coding FeatureLayer URLs would prove inefficient.
I have successfully been able to return a JSON object containing attribution that appears to be the same data one would see on the layers REST node.
maps = [];
require([
"esri/map", "esri/layers/FeatureLayer",
"esri/dijit/Print", "esri/tasks/PrintTemplate", "esri/request",
"esri/config","esri/dijit/BasemapToggle",
"dojo/_base/array", "dojo/dom", "dojo/parser", "dojo/domReady!"
], function (Map, FeatureLayer,Print, PrintTemplate, esriRequest, esriConfig,BasemapToggle,arrayUtils, dom, parser){
parser.parse();
console.log("Map Start");
esriConfig.defaults.io.proxyUrl = "http://........./proxy.ashx";
maps.addRespLyrs = function addRespLyrs (layer) {
if (layer.type == "Feature layer") {
console.log(layer.name);
maps.map.addLayer(layer);
}
};
maps.handleMapInfo = function handleMapInfo (resp) {
console.log("handleMapInfo called");
maps.layers = resp.layers;
console.log(maps.layers);
for (i in maps.layers) {
var layer = maps.layers[i];
maps.addRespLyrs(layer);
}
};
maps.layerRequest = function layerRequest () {
var mapInfo = esriRequest({
"url": "https://........./Application Name/MapServer/layers",
"content" : {"f":"json"},
"handleAs" : "json",
"callbackParamName" : "callback"
});
mapInfo.then(maps.handleMapInfo);
};
maps.map = new Map("cpCentCent", {
basemap:"topo",
center: [-98.5795, 39.8282],
zoom: 5
});
console.log("Map End");
When attempting to add the data using the addLayer() method I recieve an error thrown from deep with in esri's API.
init.js:199 TypeError: a.id.match is not a function(…) "TypeError: a.id.match is not a function
Any thoughts as to what could be going wrong here or how to create a layer from my JSON?