Why doesn't my layer show labels?

7801
8
Jump to solution
03-14-2012 12:34 PM
BenStewart
New Contributor III
I'm adding a feature layer to an esri.map, and I can't understand why labels aren't showing up. This is the layer I'm trying to add, and it has a labeling definition. Am I missing something in the definition of the map? Or of the feature layer?

        var map = new esri.Map("map", { extent: esri.geometry.geographicToWebMercator(initialExtent), slider: true, nav: false });         dojo.connect(map, "onLoad", initSelectToolbar);            var baseMapLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");         map.addLayer(baseMapLayer);      //Add regional summation data   var content = "<b>Region</b>: ${Region_1}" +                         "<br><b>Value USD(Millions)</b>: ${SUM_MAX_TotalAmt}" +                         "<br><b>Number of Projects</b>: ${SUM_COUNT_ProjectID}";   var infoTemplate = new esri.InfoTemplate("${FIELD_NAME}", content);     featureLayer = new esri.layers.FeatureLayer("http://maps4.arcgisonline.com/ArcGIS/rest/services/World_Bank/WB_World_Bank_Projects/MapServer/1",{           mode: esri.layers.FeatureLayer.MODE_ONDEMAND,           infoTemplate: infoTemplate,     outFields: ["*"]             });  map.addLayer(featureLayer);
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Frequent Contributor II
Use a dynamic map service layer. You can control individual layer visibility with setVisibileLayers.

View solution in original post

0 Kudos
8 Replies
derekswingley1
Frequent Contributor II
Feature Layers don't support a layer's labels. When you create a feature layer from a layer in a map service, you get the geometry and attributes. If you want to label feautres, look into using a Text Symbol.
0 Kudos
BenStewart
New Contributor III
Is there a better way to add a feature layer to my map then? I feel like I must be missing something. Placing each label with the TextSymbol function seems like an incredibly in-efficient way to add labels to a map service.
0 Kudos
derekswingley1
Frequent Contributor II
Use a dynamic map service layer. You can control individual layer visibility with setVisibileLayers.

View solution in original post

0 Kudos
jonathanlee1
New Contributor
Use a dynamic map service layer. You can control individual layer visibility with setVisibileLayers.


hi i know this thread is months old, but i am wondering if you guys can help out. I bumped into the same problem as the TS and I tried using the visible layers, but the problem is that i have several hundred layers, if i add one layer the rest disappear and I cannot add more than like 10 layers to it as the old map just hangs there.

I have been trying to set the default visibility to a layer of the dynamic map service but to no avail as the map does not take the value of the default visibility and set the layer i want to be visible.
0 Kudos
nicogis
MVP Frequent Contributor
0 Kudos
JosieBock1
New Contributor III
I've tried implementing the code used in the developers.arcgis.com/javascript/samples/layers_label/, but now my points do not show up and neither do my labels.

function init() {

        //use the info window instead of the popup
        var infoWindow = new esri.dijit.InfoWindow(null, dojo.create("div"));
        infoWindow.startup();
 
  //var bbox = new Extent({"xmin":-7600182.13249805,"ymin":-446969.667305208,"xmax":2866021.96822699,"ymax":5458542.14371841,"spatialReference":{"wkid":102039}});
 
  map = new esri.Map("map", {
    //extent: bbox,
          basemap: "streets",
          center: [-96, 37],
          infoWindow: infoWindow,
          zoom: 4
        });

 
 
        var template = new esri.InfoTemplate();
        //flag icons are from http://twitter.com/thefella, released under creative commons
        template.setTitle("Store <b>${StoreNum}</b>");
        template.setContent(getWindowContent);

        //create a renderer for the stores layer to override default symbology
  var storeSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE,9,new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,new dojo.Color([0,0,0]), .5),new dojo.Color([0,92,230]));
  var storeRenderer = new SimpleRenderer(storeSymbol);
  //create a feature layer to show store points
  //var storesLayer = new esri.layers.FeatureLayer("http://gis-server.greatriv.com/ArcGIS/rest/services/ShamrockMktg/StoreLocations/MapServer/0", {
          var storesURL = "http://gis-server.greatriv.com/ArcGIS/rest/services/ShamrockMktg/StoreLocations/MapServer/0";
    var stores = new FeatureLayer(storesURL, {
    mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
          outFields: ["*"],
    id: "stores",
    infoTemplate: template,
        });
  var labelField = "StoreNum";
  stores.setRenderer(storeRenderer);     
        map.addLayer(stores);
  map.infoWindow.resize(675, 475);
 
  //create a text symbol to define the style of labels
  var storesColor = new Color("#666");
  var storesLabel = new TextSymbol().setColor(storesColor);
  storesLabel.font.setSize("8pt");
  storesLabel.font.setFamily("arial");
  storesLabelRenderer = new SimpleRenderer(storesLabel);
  var labels = new LabelLayer({id: "labels" });
  //tell the label layer to label the stores feature layer
  //using the field named "StoreNum"
  labels.addFeatureLayer(stores, storesLabelRenderer, "${" + labelField + "}");
  //add the label layer to the map
  map.addLayer(labels);       

}


Any suggestions?
0 Kudos
JonathanUihlein
Esri Regular Contributor
Hi Josie.

It's hard to troubleshoot without seeing the rest of your code.
If you could create a working sample that shows off the issue using jsfiddle.net, I can take a look.

Also, try to create a new thread if you have a specific question.
People are less likely to respond when you post a question in a thread that is 2 years old.
0 Kudos
AmroAhmed
New Contributor

add option 

 showLabels: true

for map constructor

same as

 map = new Map("map", {
          extent
: bbox,
          showLabels
: true //very important that this must be set to true!  
       
});
0 Kudos