Hi Avishek,
Here is example on how to read a JSON file using the dojo/request/xhr provider. The coordinates and additional attribute information is added to a GraphicsLayer and then labels are generated using the LabelLayer class.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Sample Map</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.9/js/esri/css/esri.css">
<style>
html, body, #mapDiv {
padding:0;
margin:0;
height:100%;
}
</style>
<script src="http://js.arcgis.com/3.9/"></script>
<script>
var map;
require([
"esri/map", "esri/graphic", "esri/SpatialReference",
"esri/geometry/Point", "esri/symbols/SimpleMarkerSymbol",
"esri/Color", "esri/InfoTemplate", "esri/layers/GraphicsLayer",
"esri/symbols/TextSymbol", "esri/renderers/SimpleRenderer", "esri/layers/LabelLayer",
"dojo/dom", "dojo/on", "dojo/_base/array", 'dojo/_base/lang',
"dojo/json", "dojo/request/xhr", "dojo/parser", "dojo/domReady!"
], function(
Map, Graphic, SpatialReference,
Point, SimpleMarkerSymbol,
Color, InfoTemplate, GraphicsLayer,
TextSymbol, SimpleRenderer, LabelLayer,
dom, on, array, lang,
JSON, xhr, parser
) {
parser.parse();
map = new Map("mapDiv", {
basemap: "topo",
center: [4.1, 52.1],
zoom: 10
});
map.on("load", addPts);
graphicsLayer = new GraphicsLayer();
function addPts(){
xhr("locations.json", {
handleAs: "Json",
sync: "true"
}).then(lang.hitch(document, function(data){
locations = JSON.parse(data);
array.forEach(locations, function(feature){
var pt = new Point(feature.longitude, feature.latitude, new SpatialReference({ wkid: 4326 }));
var sms = new SimpleMarkerSymbol().setStyle(
SimpleMarkerSymbol.STYLE_SQUARE).setColor(
new Color([255,0,0,0.5]));
var attr = {"Attributes": feature.textToDisplayOnThePictureMarkerSymbol};
var infoTemplate = new InfoTemplate("Info:","Attributes: ${Attributes}");
var graphic = new Graphic(pt,sms, attr, infoTemplate);
graphicsLayer.add(graphic);
})
map.addLayer(graphicsLayer);
var textColor = new Color("#cc0000");
var textLabel = new TextSymbol().setColor(textColor);
textLabel.font.setSize("14pt");
textLabel.font.setFamily("arial");
textLabel.xoffset = -12;
textLabel.yoffset = 10;
textLabelRenderer = new SimpleRenderer(textLabel);
var labels = new LabelLayer();
labels.addFeatureLayer(graphicsLayer, textLabelRenderer, "${Attributes}");
map.addLayer(labels);
}));
}
});
</script>
</head>
<body>
<div id="mapDiv"></div>
</body>
</html>