I am looking to see if anyone can help me with some details and an example on how to add a points to a JS API 4.6 map when retrieved from a JSON web service.
I know I need to use the request function but an lost as to then how to put the points on the map AFTER I have retrieved the JSON data from the web service.
I have studied the esri samples like Flickr, etc but cant seem to get anything to work.
Any help is appreciated.
Thanks
That's the method I use to add a geoJSON do my map, You need to put the requires and adjust to your application.
function loadJson(content, title) {
var obj = eval('(' + content + ');');
var gl = new GraphicsLayer({
title: title
});
if (obj.features) {
var symbol;
switch (obj.geometryType) {
case "esriGeometryPolyline":
symbol = simboloAdicionaCamadaLinha.clone();
break;
case "esriGeometryPoint":
symbol = simboloAdicionaCamadaPonto.clone();
break;
case "esriGeometryPolygon":
var symbol = simboloAdicionaCamadaPoligono.clone();
break;
};
if (obj.spatialReference.wkid != 4326) {
copagisAlert.info('Sistema de coordenadas da camada a adicionar na web deve ser o GCS_WGS_1984 WKID: 4326');
return false;
}
for (var i = 0; i < obj.features.length; i++) {
var graphic = new Graphic({
geometry: geometryJsonUtils.fromJSON(obj.features[i].geometry),
symbol: symbol,
attributes: obj.features[i].attributes
});
gl.add(graphic);
}
gl.then(function () {
view.goTo(gl.graphics);
});
map.add(gl);
}
}