five application :Labeling features

<!DOCTYPE html>
<html>
  <head>
    <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></title>
    <link rel="stylesheet" href="//js.arcgis.com/3.13/esri/css/esri.css">
    <style>
      html, body, #map {
        height: 100%; width: 100%; margin: 0; padding: 0; 
      }
    </style>

    <script src="//js.arcgis.com/3.13/"></script>
    <script>
      var map;
    
      require([
        "esri/map", 
        "esri/geometry/Extent",
        "esri/layers/FeatureLayer",

        "esri/symbols/SimpleLineSymbol",
        "esri/symbols/SimpleFillSymbol",
        "esri/symbols/TextSymbol",
        "esri/renderers/SimpleRenderer",

        "esri/layers/LabelLayer",

        "esri/Color",
        "dojo/domReady!"
      ], function(
        Map, Extent, FeatureLayer,
        SimpleLineSymbol, SimpleFillSymbol, TextSymbol, SimpleRenderer,
        LabelLayer,
        Color
      ) {
        // load the map centered on the United States
        var bbox = new Extent({"xmin": -1940058, "ymin": -814715, "xmax": 1683105, "ymax": 1446096, "spatialReference": {"wkid": 102003}});
        map = new Map("map", {
          extent: bbox
        });

        var labelField = "STATE_NAME";

        // create a renderer for the states layer to override default symbology
        var statesColor = new Color("#f00");
        var statesLine = new SimpleLineSymbol("solid", statesColor, 1);
        var statesSymbol = new SimpleFillSymbol("solid", statesLine, null);
        var statesRenderer = new SimpleRenderer(statesSymbol);
        // create a feature layer to show country boundaries
        var statesUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3";
        var states = new FeatureLayer(statesUrl, {
          id: "states",
          outFields: [labelField]
        });
        states.setRenderer(statesRenderer);
        map.addLayer(states);

        // create a text symbol to define the style of labels
        var statesLabel = new TextSymbol().setColor(new Color("#00f"));
        statesLabel.font.setSize("12pt");
        statesLabel.font.setFamily("arial");
        var statesLabelRenderer = new SimpleRenderer(statesLabel);
        var labels = new LabelLayer({ id: "lab" });
        // tell the label layer to label the countries feature layer 
        // using the field named "admin"
        labels.addFeatureLayer(states, statesLabelRenderer, "{" + labelField + "}");
        // add the label layer to the map
        map.addLayer(labels);
      });
    </script>
  </head>
  <body>
    <div id="map"></div>
  </body>
</html>

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。