benaller

LabelLayer using feature layer called via CreateMap?

Discussion created by benaller on Nov 4, 2013
Does anyone know if there's a way to label feature layers that are called through the arcgisUtils.CreateMap method? Perhaps there's a way to get at the operational layers in the webmap to build label layers without having to use map.addLayer for each feature layer I wish to label?    My test page seems overkill in that it's calling the same layer through both the CreateMap and through map.addLayer.  I'd like to leverage all the settings saved within my webmap, and guess I'm looking for the most efficient way of creating the labels. 

Thanks,
Ben

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <title></title>
    <link rel="stylesheet" href="//js.arcgis.com/3.7/js/esri/css/esri.css">
    <style>
      html, body, #map {
        height: 100%; width: 100%; margin: 0; padding: 0; 
      }
    </style>

    <script src="//js.arcgis.com/3.7/"></script>
    <script>
      var map;

      require([
        "esri/map",
        "esri/arcgis/utils",
        "esri/geometry/Extent",
        "esri/layers/FeatureLayer",
        "esri/symbols/SimpleLineSymbol",
        "esri/symbols/SimpleFillSymbol",
        "esri/symbols/TextSymbol",
        "esri/renderers/SimpleRenderer",
        "esri/renderers/ScaleDependentRenderer",
        "esri/layers/LabelLayer",
        "dojo/_base/Color",
        "dojo/domReady!"
      ], function(Map, arcgisUtils, Extent, FeatureLayer, SimpleLineSymbol, SimpleFillSymbol, TextSymbol, SimpleRenderer, ScaleDependentRenderer, LabelLayer, Color) 
        {
          arcgisUtils.createMap("a04f0acc513e4f8d94f008d2937bf9ab", "map").then(function(response) {
          map = response.map;
          

          // create a renderer for the monitoring wells layer to override default symbology
          var MonwellColor = new Color("#666");
          //var MonwellLine = new SimpleLineSymbol("solid", MonwellColor, 1.5);
          //var MonwellSymbol = new SimpleFillSymbol("solid", MonwellLine, null);
          //var MonwellRenderer = new SimpleRenderer(MonwellSymbol);
          var Monwell = new esri.layers.FeatureLayer(
            "http://services.arcgis.com/G4S1dGvn7PIgYd6Y/arcgis/rest/services/MonitoringWells/FeatureServer/0",
            {
              mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
              outFields: ["PERMITID"]
            }
           );
          
          map.addLayer(Monwell);

          // create a text symbol to define the style of labels
          var MonwellLabel = new TextSymbol().setColor(MonwellColor);
          MonwellLabel.font.setSize("9pt");
          MonwellLabel.font.setFamily("verdana");
          MonwellLabelRenderer = new SimpleRenderer(MonwellLabel);

          // scale dependent renderer for city labels
          var MonwellScaleDependent = new ScaleDependentRenderer({
              rendererInfos: [{
                  renderer: MonwellLabelRenderer,
                  minScale: 10000,
                  maxScale: 1
                }]
              })
              var labels = new LabelLayer({ id: "labels" });
              // tell the label layer to label the monitoring wells feature layer
              labels.addFeatureLayer(Monwell, MonwellScaleDependent, "${PERMITID}");
              // add the label layer to the map
              map.addLayer(labels);
          });
      });
    </script>
  </head>
  <body>
    <div id="map"></div>
  </body>
</html>

Outcomes