AnsweredAssumed Answered

Labeling Point Graphics

Question asked by fayaz_esri on Jul 10, 2017
Latest reply on Aug 12, 2017 by fayaz_esri

I am trying to label graphics that is returned by a query task as points but could not success. Anyone can please help. here is my code:

 

function zoompnt() {
require(["dojo/parser", "esri/layers/LabelClass", 'esri/layers/LabelLayer',"esri/renderers/SimpleRenderer", "dojo/promise/all", "dojo/_base/connect", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol",
"esri/Color", "dojo/_base/array", "dojo/dom", "esri/symbols/TextSymbol","esri/InfoTemplate",
"esri/config", "esri/map", "esri/geometry/Extent", "esri/layers/FeatureLayer",
"esri/symbols/SimpleFillSymbol", "esri/layers/ArcGISDynamicMapServiceLayer",
"esri/tasks/query", "esri/tasks/QueryTask","esri/layers/GraphicsLayer",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane",
"dojo/domReady!"], function (parser,LabelClass,LabelLayer,SimpleRenderer, all, connect, SimpleMarkerSymbol, SimpleLineSymbol,
Color, arrayUtils, dom,TextSymbol,InfoTemplate,
esriConfig, Map, Extent,FeatureLayer,
SimpleFillSymbol, ArcGISDynamicMapServiceLayer,
Query, QueryTask, GraphicsLayer) {
var queryLayer = "http://00.000.00.00:6080/arcgis/rest/services/Operational_Test/MapServer/21";
var fir, sec;
var graLayer;
var labels;
var selFeatureLayer;
fir = document.getElementById("DropDownList2").value;
sec = document.getElementById("DropDownList3").value;

var qTask = new QueryTask("http://00.000.00.00:6080/arcgis/rest/services/Operational_Test/MapServer/21");
var query = new Query();

query.where = "SUBDIV_NO LIKE '%" + fir + "%' AND PARCEL_NO LIKE '" + sec + "'";
query.outFields = ["*"];
query.returnGeometry = true;
qTask.execute(query, function (featureset) {


var selSymbol = new SimpleMarkerSymbol().setStyle(SimpleMarkerSymbol.STYLE_DIAMOND).setColor(new Color([255, 0, 0, 0.5]));
var selSymbol1 = new SimpleMarkerSymbol().setStyle(SimpleMarkerSymbol.STYLE_DIAMOND).setColor(new Color([255, 5, 5, 5.5]));
// create a text symbol to define the style of labels
var textColor = new Color("#666");
var textLabel = new TextSymbol().setColor(textColor);
textLabel.font.setSize("8pt");
textLabel.font.setFamily("arial");
textLabelRenderer = new SimpleRenderer(textLabel);
labels = new LabelLayer({
id: "labels"
});

 


var gra = "";

var i;
for (i = 0; i < featureset.features.length; i++) {

gra = featureset.features[i];
gra.setSymbol(selSymbol1);
map.graphics.add(gra);

graLayer = new GraphicsLayer();
var infoTemplate = new InfoTemplate("Serial_No", "District Name:${PARCEL_NO}");

graLayer.setInfoTemplate(infoTemplate);
graLayer.add(gra);
map.addLayer(graLayer);

labels.addFeatureLayer(graLayer, textLabelRenderer, "${PARCEL_NO}");

map.addLayer(labels);

gra++;


}

});

 

});
}

Outcomes