AnsweredAssumed Answered

labels off function

Question asked by wthughes on Jun 3, 2016
Latest reply on Jun 6, 2016 by kenbuja

I added a labelsOff function to the following "labeling features client-site" sample. In the console I get an error saying cannot find variable "labelsOff" which is the name of the function. What am I missing? Thanks.


<!DOCTYPE html>



    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">

    <title>Labeling features client-side</title>

    <link rel="stylesheet"   href="//">


      html, body, #map {

        height: 100%; width: 100%; margin: 0; padding: 0;



          top:20px; right:20px; position: absolute; z-index:100;





   <script src="//"></script>


      var map;














      ], function(Map, Extent, FeatureLayer,

                  SimpleLineSymbol, SimpleFillSymbol,

                  TextSymbol, SimpleRenderer, LabelClass, Color)


        // load the map centered on the United States

        var bbox = new Extent({"xmin": -1940058, "ymin": -814715, "xmax": 1683105, "ymax": 1446096, "spatialReference": {"wkid": 102003}});


        //create the map and set the extent, making sure to "showLabels"

        map = new Map("map", {

          extent: bbox,

          showLabels : true //very important that this must be set to true!  



        // create a renderer for the states layer to override default symbology

        var statesColor = new Color("#666");

        var statesLine = new SimpleLineSymbol("solid", statesColor, 1.5);

        var statesSymbol = new SimpleFillSymbol("solid", statesLine, null);

        var statesRenderer = new SimpleRenderer(statesSymbol);


        // create the feature layer to render and label

        var statesUrl = "";

        var states = new FeatureLayer(statesUrl, {

          id: "states",

          outFields: ["*"]




        // create a text symbol to define the style of labels

        var statesLabel = new TextSymbol().setColor(statesColor);





        //this is the very least of what should be set within the JSON 

        var json = {

          "labelExpressionInfo": {"value": "{STATE_NAME}"}




        //create instance of LabelClass (note: multiple LabelClasses can be passed in as an array)

        var labelClass = new LabelClass(json);

        labelClass.symbol = statesLabel; // symbol also can be set in LabelClass' json

        states.setLabelingInfo([ labelClass ]);



        function labelsOff() {

          var optionsArray = []; 

          var drawingOptions = new esri.layers.LayerDrawingOptions(); 

          drawingOptions.showLabels = false; 

          //drawingOptions.renderer = renderer; 

          optionsArray[0] = drawingOptions; 








    <div id="map"></div>

    <input type="button" id="btn" value="Labels Off" onClick="labelsOff()"/>