Visualize all features with the same symbol

This device does not support 3D.

View the system requirements for more information.

This sample demonstrates how to symbolize all features in the same layer with the same symbol. In some cases users only want to know where features are located, such as cities, project areas, roads, boundaries, etc. The data may be stored in a single layer where all features must have the same symbol. In this case, we'll use a SimpleRenderer to render all features with the same symbol.

Prior to completing the following steps, you should be familiar with views, Map, and FeatureLayer. If necessary, complete the following tutorials first:

The basic components of this app, such as creating instances of the Map and MapView classes and understanding HTML and CSS structure will not be reviewed. See the tutorials listed above if you need to familiarize yourself with those components in this application. As a general rule the introductory principles discussed in the tutorials above apply to most samples in the documentation.

1. Create a symbol for each layer

Three layers are added to this app; one for state boundaries, another for major highways, and another for major cities. In each layer, we want to render all features with the same symbol. Since cities are represented with points, we'll use a SimpleMarkerSymbol.

var citiesSym = new SimpleMarkerSymbol({
  size: 10,
  color: "#FF4000",
  outline: {
    color: [255, 64, 0, 0.4],
    width: 7
  }
});

For the highways and states we'll use a SimpleLineSymbol and SimpleFillSymbol respectively.

2. Set the symbol in a SimpleRenderer

Next, set the symbol object in the symbol property of the SimpleRenderer.

var citiesRenderer = new SimpleRenderer({
  symbol: citiesSym
});

You can also define the symbol directly in the renderer without having to do it beforehand.

var citiesRenderer = new SimpleRenderer({
  symbol: new SimpleMarkerSymbol({
    size: 10,
    color: "#FF4000",
    outline: {
      color: [255, 64, 0, 0.4],
      width: 7
    }
  })
});

3. Set other properties on the renderer (optional)

You can optionally set additional properties in the renderer, such as label, which sets the label of the symbol in the legend.

var citiesRenderer = new SimpleRenderer({
  symbol: new SimpleMarkerSymbol({
    size: 10,
    color: "#FF4000",
    outline: {  // autocasts as new SimpleLineSymbol()
      color: [255, 64, 0, 0.4],  // autocasts as new Color()
      width: 7
    }
  }),
  label: "Major cities"  // this will appear next to the symbol in the legend
});

4. Summary

Assigning all features in a single layer with a single symbol is the simplest scenario for visualizing data. Adding a legend to the app helps the user understand what the graphic represents in the real world. See the Legend widget sample for more information about adding a legend to a view.

Click the sandbox button below to see the full code of the app.

5. Additional visualization tutorials and samples

Sample search results

TitleSample

There were no match results from your search criteria.