I have successfully added a graphicsLayer. when i want to view legend for the added layer i couldnt add it, i get "No legend".
here my function adding the graphics layer, please help me or explain whats the issue when i try to add legend to the div id ="legendDivD"
async function conversionFunction() {
try {
for (i = 0; i < obj.length; i++) {
var lati = obj[i].Latitude;
var longi = obj[i].Longitude;
var schoolCode = obj[i].Departmentcode;
var pointxy = await xyConversion(longi, lati);
var newData = {
Latitude: pointxy.pnt_lat,
Longitude: pointxy.pnt_lon,
schoolCode: schoolCode
}
dataArr.push(newData)
}
console.log(dataArr)
schLayer = new GraphicsLayer({ id: 'SchoolsLayer' }); // Create a single GraphicsLayer
for (var i = 0; i < dataArr.length; i++) {
var tmplteJson = { title: "Details", content: `Department code : ${dataArr[i].schoolCode} ` };
var attributes = {}
var poly_point1 = new esri.geometry.Point([dataArr[i].Longitude, dataArr[i].Latitude], new esri.SpatialReference({ wkid: 4326 }));
var pointgraphic = new Graphic(poly_point1, dataArr[i].schoolCode.length == 11 ? markerPresSymbol : markerPropSymbol);
pointgraphic.setInfoTemplate(new InfoTemplate(tmplteJson));
schLayer.add(pointgraphic);
}
var legend = new Legend({
map: map,
//autoUpdate: true,
layerInfos: [{ layer: schLayer, title: "" }]
}, "legendDivD");
map.addLayer(schLayer);
legend.startup();
$("#loading1").css('display', 'none');
} catch (error) {
console.error(error);
}
}
Legend widget does not support GraphicsLayer. It's listed as a "Known limitation" on https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend.html
The same is true for the legacy version (3.x) that it looks like you are using -- https://developers.arcgis.com/javascript/3/jsapi/legend-amd.html