0

I am using using featurelayer and sceneview in ArcGIS API for JavaScript 4.3 and want to add labels. I have followed code examples from the API documentation but the labels do not show. How do I get the labels to appear?

this.map = new Map({
  basemap: 'streets',
});

this.map.layers.add(new FeatureLayer({
  url: 'http://slcipuapp2.slcgov.com/arcgis/rest/services/waterhardness/MapServer',
  id: '0',
  visible: true,
  labelsVisible: true,
  outFields: ["*"],
  popupTemplate: this.locationsTemplate,
  labelingInfo: this.labelTemplate
}));

this.labelTemplate = new LabelClass();
this.labelTemplate.symbol = {
  type: "text",  
  symbol: {
    type: "text",  // autocasts as new TextSymbol()
    color: "black",
    haloSize: 1,
    haloColor: "white"
  }
};
this.labelTemplate.labelExpressionInfo = { expression: "$feature.reading" };

this.view = new SceneView({
  container: "viewDiv",
  map: this.map,
  camera: {
    position: [
      -111.7496032288646, // lon
      40.478774371255994, // lat
      7671.145575070754  // elevation in meters
    ],
    tilt: 72.34558755016394,
    heading: -26.290004118126618,
    fov: 55
  }
});
  • 1
    Did you try to create the labelTemplate first before initiate the Feature Layer? Or you can create the Feature Layer first, then specify the labelingInfo property after the labelTemplate is created: featureLayer.labelingInfo = [ labelTemplate ]; Also, the URL that you use to create the Feature Layer dose not look correct, it is an URL for map service, not feature service. – Vanni Zhang Sep 13 '18 at 23:16
  • Also review the Labeling documentation. There are some known limitations for [LabelClass][1] like "FeatureLayers only support labeling for Point and Polygon geometries rendered with WebGL". [1]: developers.arcgis.com/javascript/latest/api-reference/… – Katah Sep 14 '18 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.