Select to view content in your preferred language

Labeling query results in Javascript API

968
3
02-21-2011 08:26 PM
SowmyaK
Emerging Contributor
Hi,

     I am creating graphics layer using esri.layers.GraphicsLayer. I need to display some key field value of that layer on graphics as label.Can i achieve using esri.symbol.TextSymbol?
My code is like this :

function ZoomshowResults(featureSet)
       {     
          var zoomresultFeatures = featureSet.features;
          var ZoomGraphicsLayer= new esri.layers.GraphicsLayer({id:"1"});
          var il;
          for (var i=0, il=zoomresultFeatures.length; i<il; i++) {
          var zoomgraphic = zoomresultFeatures;
          var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([72,61,139,0.35]), 1),new dojo.Color([72,61,139,0.35]));
          zoomgraphic.setSymbol(symbol);
          ZoomGraphicsLayer.add(zoomgraphic);
         }
          map.addLayer(ZoomGraphicsLayer);
          map.graphics.enableMouseEvents();
       }


Thanks in advance..
Sowmya
0 Kudos
3 Replies
HemingZhu
Frequent Contributor
Hi,

     I am creating graphics layer using esri.layers.GraphicsLayer. I need to display some key field value of that layer on graphics as label.Can i achieve using esri.symbol.TextSymbol?
My code is like this :

function ZoomshowResults(featureSet)
       {     
          var zoomresultFeatures = featureSet.features;
          var ZoomGraphicsLayer= new esri.layers.GraphicsLayer({id:"1"});
          var il;
          for (var i=0, il=zoomresultFeatures.length; i<il; i++) {
          var zoomgraphic = zoomresultFeatures;
          var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([72,61,139,0.35]), 1),new dojo.Color([72,61,139,0.35]));
          zoomgraphic.setSymbol(symbol);
          ZoomGraphicsLayer.add(zoomgraphic);
         }
          map.addLayer(ZoomGraphicsLayer);
          map.graphics.enableMouseEvents();
       }


Thanks in advance..
Sowmya


Yes if you don't want to use InfoTemplate to display field value. However, you have to figure out a labeling point to display your text. There are a lot of ways to get the labeling point such as using geometry serivce's labelPoints method, using the centroid of the graphic's extend, or popluating x, y of the label point into your query layer and get them through graphic.attributes["X"]...
0 Kudos
SowmyaK
Emerging Contributor
Yes if you don't want to use InfoTemplate to display field value. However, you have to figure out a labeling point to display your text. There are a lot of ways to get the labeling point such as using geometry serivce's labelPoints method, using the centroid of the graphic's extend, or popluating x, y of the label point into your query layer and get them through graphic.attributes["X"]...


Hi,

  Thanks for the response 🙂

   I am getting set of polygon feature for querytask. One of the key field i need to display on polygon as label. I can create label for clicked point on map. How to label polygon?


Thanks,
Sowmya
0 Kudos
HemingZhu
Frequent Contributor
Hi,

  Thanks for the response 🙂

   I am getting set of polygon feature for querytask. One of the key field i need to display on polygon as label. I can create label for clicked point on map. How to label polygon?


Thanks,
Sowmya


here is the link that might help you: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/geometryservice.htm#labelPoints
0 Kudos