0

Using ArcGIS JavaScript API 3.24, can you please take a look at this snippet and let me know why I am not able to add Symbology to Feature Service out put by using ClassBreaksRenderer

Here is the code

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>FeatureLayer</title>

<link rel="stylesheet" href="https://js.arcgis.com/3.24/esri/css/esri.css">
<script src="https://js.arcgis.com/3.24/"></script>

<style>
html, body, #map {
  padding: 0;
  margin: 0;
  height: 100%;
  width: 100%;
}
</style>

<script>
require([
    "esri/map",
    "esri/layers/FeatureLayer",
    "esri/renderers/ClassBreaksRenderer",
    "esri/symbols/SimpleMarkerSymbol",
    "esri/symbols/SimpleLineSymbol",
    "esri/symbols/SimpleFillSymbol",
    "esri/Color",
    "dojo/domReady!"
  ],
  function(
    Map,
     FeatureLayer,
     ClassBreaksRenderer,
     SimpleMarkerSymbol,
     SimpleLineSymbol,
     SimpleFillSymbol,
     Color
  ) {

    var map = new Map("map", {
      basemap: "hybrid",
      center: [-82.44109, 35.6122],
      zoom: 17
    });

    var featureLayer = new FeatureLayer("https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0",{
            mode: FeatureLayer.MODE_SNAPSHOT,
            outFields: [ "*" ]   

    });
   var observationRenderer = new ClassBreaksRenderer(new SimpleMarkerSymbol(), "Ht_DBH_ft");
    observationRenderer.addBreak(3, 6,  new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
    new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,
    new Color([12,255,12]), 2),new Color([12,255,12,1])
  ));
    observationRenderer.addBreak(0, 3,  new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
    new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,
    new Color([255,0,0]), 2),new Color([128,255,128,1])
  ));

    map.addLayer(featureLayer);

  });
</script>
</head>

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

</html>
0

You did not define a marker symbol for the two break classes. Instead, you used SimpleFillColor to the geometries of that feature layer, which are Points. So, you will not see any results.
Plus, you forgot to apply your renderer to the feature Layer.

First, define the default SimpleMarkerSymbol :

var symbol = new SimpleMarkerSymbol(
  SimpleMarkerSymbol.STYLE_DIAMOND,
  5,
  new SimpleLineSymbol(
    SimpleLineSymbol.STYLE_SOLID,
    new Color([255,0,0]), 1
  ),
  new Color([255,0,0,0.25])
);

Create your renderer and apply to it the default symbol :

var observationRenderer = new ClassBreaksRenderer(symbol, "Ht_DBH_ft");

Now, define your break classes :

observationRenderer.addBreak(0, 3,
  new SimpleMarkerSymbol(
    SimpleMarkerSymbol.STYLE_DIAMOND,
    10,
    new SimpleLineSymbol(
      SimpleLineSymbol.STYLE_SOLID,
      new Color([0,255,0]), 1
    ),
    new Color([0,255,0,0.25])
  )
);

observationRenderer.addBreak(3, 6,
  new SimpleMarkerSymbol(
    SimpleMarkerSymbol.STYLE_DIAMOND,
    50,
    new SimpleLineSymbol(
      SimpleLineSymbol.STYLE_SOLID,
      new Color([0,0,255]), 1
    ),
    new Color([0,0,255,0.25])
  )
);

Apply your completed renderer to the feature layer :

featureLayer.setRenderer(observationRenderer);

Add that layer to the map :

map.addLayer(featureLayer);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.