Skip To ContentArcGIS for DevelopersSign In Dashboard
Loading...

Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

This sample demonstrates how to generate a data-driven continuous size visualization based on statistics returned from a numeric field in a FeatureLayer.

This is accomplished with the createContinuousRenderer() in the size renderer creator helper object. All that is required for generating a renderer is a Feature Layer and a field name.

var params = {
  layer: layer,
  basemap: map.basemap,
  view: view,
  valueExpression: "( $feature.POP_POVERTY / $feature.TOTPOP_CY ) * 100",
  legendOptions: {
    title: "% population living in poverty"
  },
  minValue: 15,
  maxValue: 60,
  outlineOptimizationEnabled: true
};

sizeRendererCreator.createContinuousRenderer(params).then(function(response) {
  // set the renderer to the layer
  povLayer.renderer = response.renderer;
});

To generate the histogram used by the slider, simply pass similar parameters to the histogram() function. You can then pass the resulting object to the SizeSlider.

histogram({
  layer: povLayer,
  view: view,
  valueExpression: sizeParams.valueExpression,
  minValue: sizeParams.minValue,
  maxValue: sizeParams.maxValue
}).then(function(histogram) {
  // add the histogram to the size slider
  const sizeSlider = SizeSlider.fromRendererResult(rendererResult, histogramResult);
  sizeSlider.container = "slider";
  sizeSlider.labelFormatFunction = function(value){
    return value.toFixed(1);
  }
  view.ui.add("containerDiv", "bottom-left");
});

After the slider is set up with the statistics of the FeatureLayer, you can listen to its events to update the renderer of the layer with the output visual variable in the event object.

function changeEventHandler () {
  const renderer = layer.renderer.clone();
  const sizeVariable = renderer.visualVariables[0];
  renderer.visualVariables = [ sizeSlider.updateVisualVariable(sizeVariable) ];
  layer.renderer = renderer;
}

sizeSlider.on(["thumb-change", "thumb-drag", "min-change", "max-change"], changeEventHandler);

A word of caution

Keep in mind that generating renderers should be avoided in most applications because of the performance cost affecting the end user. As stated in the Visualization overview: Smart mapping API guide topic, the Smart Mapping APIs were designed for two types of applications: data exploration apps and visualization authoring apps similar to ArcGIS Online. In all other cases, renderers should be saved to the layer or manually created using any of the renderer classes.

Additional visualization samples and resources

Sample search results

TitleSample
Loading...