AnsweredAssumed Answered

create graphic from coordinates of json file onto map

Question asked by Charmila on Nov 19, 2018
Latest reply on Nov 20, 2018 by Charmila

Hi,

 

I need immediate help . Iam new to arcgis javascript api.Iam working on 3.26 version. I have a geojson file as below : Please let me know how i can create a graphic at the coordinate given in this json file. Actually i should be able to read co-ordinates from this json file and display it as a graphic on map

 

{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-88.13198711899997, 41.79304797900005]
},
"properties": {
"LocationId": 1,
"GeometryType": "Point"

}
}

]
}

 

 

Please find my code snippet below :

 

 

var map;

require([
"esri/map", "esri/layers/FeatureLayer", "esri/layers/GraphicsLayer",
"esri/tasks/query", "esri/geometry/Circle", "esri/SpatialReference", "esri/geometry/Point",
"esri/graphic", "esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/renderers/SimpleRenderer",
"esri/config", "esri/Color", "dojo/dom", "dojo/domReady!"
], function(
Map, FeatureLayer,
GraphicsLayer,
Query, Circle, SpatialReference, Point,
Graphic, SimpleMarkerSymbol,
SimpleLineSymbol, SimpleFillSymbol, SimpleRenderer,
esriConfig, Color, dom
) {

map = new Map("mapDiv", {
basemap: "streets",
center: [-88.158805, 41.786075],
zoom: 17,
slider: false
});

var pointGLayer = new GraphicsLayer();

map.addLayer(pointGLayer);

var data = [
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-88.13198711899997, 41.79304797900005]
},
"properties": {
"LocationId": 1,
"GeometryType": "esriGeometryPoint"

}
}]
}];
var symbol = new SimpleMarkerSymbol(
SimpleMarkerSymbol.STYLE_CIRCLE,
12,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_NULL,
new Color([247, 34, 101, 0.9]),
1
),
new Color([207, 34, 171, 0.5])
);

for (i = 0; i < data.features.length; i++) {
var pt = new Point(features[i].geometry.coordinates[i][0], features[i].geometry.coordinates[i][1],
new SpatialReference({
wkid: 4326
}));
var graphic = new Graphic(pt, symbol);
pointGLayer.add(graphic);
console.log(data);

}

 

});

Outcomes