Skip To ContentArcGIS for DevelopersSign In Dashboard
require(["esri/widgets/smartMapping/SizeSlider"], function(SizeSlider) { /* code goes here */ });
Class: esri/widgets/smartMapping/SizeSlider
Inheritance: SizeSlider SmartMappingSliderBase Widget Accessor
Since: ArcGIS API for JavaScript 4.12

The SizeSlider widget is intended for authoring and exploring data-driven visualizations in any layer that can be rendered with a SizeVariable. At a minimum you must set the min, max, and stops properties of the widget.

See the image below for a summary of the configurable options available on this slider.

SizeSlider with annotations

The fromRendererResult method can be used to conveniently create this slider from the result of the createContinuousRenderer method.

const sizeParams = {
  layer: layer,
  basemap: map.basemap,
  valueExpression: "( $feature.POP_POVERTY / $feature.TOTPOP_CY ) * 100",
  view: view
};

let rendererResult = null;

sizeRendererCreator
  .createContinuousRenderer(sizeParams)
  .then(function(response) {
    rendererResult = response;
    layer.renderer = response.renderer;

    return histogram({
      layer: layer,
      valueExpression: sizeParams.valueExpression,
      view: view,
      numBins: 70
    });
  })
   .then(function(histogramResult) {
     const sizeSlider = SizeSlider.fromRendererResult(rendererResult, histogramResult);
     sizeSlider.container = "slider";
   })
   .catch(function(error) {
     console.log("there was an error: ", error);
   });

This slider should be used to update a size visual variable in a layer's renderer. It is the responsibility of the app developer to set up event listeners on that update the size variable of the appropriate renderer.

// when the user slides the handle(s), update the renderer
// with the updated size stops

sizeSlider.on(["thumb-change", "thumb-drag"], function() {
  const renderer = layer.renderer.clone();
  const sizeVariable = renderer.visualVariables[0];
  renderer.visualVariables = [ sizeSlider.updateVisualVariable(sizeVariable) ];
  layer.renderer = renderer;
});
For information about gaining full control of widget styles, see the Styling topic.
See also:

Constructors

new SizeSlider(properties)
Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Example:
// Typical usage
// rendererResponse is result of size.createContinuousRenderer()
const slider = new SizeSlider({
  container: "sliderDiv",
  min: rendererResponse.statistics.min,
  max: rendererResponse.statistics.max,
  stops: rendererResponse.visualVariable.stops
});

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
NameTypeSummaryClass
String|HTMLElement

The ID or node representing the DOM element containing the widget.

more details
more detailsWidget
String

The name of the class.

more details
more detailsAccessor
Boolean

When true, this property indicates whether the widget has been destroyed.

more details
more detailsWidget
HistogramConfig

The Histogram associated with the data represented on the slider.

more details
more detailsSmartMappingSliderBase
String

The unique ID assigned to the widget when the widget is created.

more details
more detailsWidget
String

The widget's default label.

more details
more detailsSizeSlider
LabelFormatter

A modified version of Slider.labelFormatFunction, which is a custom function used to format labels on the thumbs, min, max, and average values.

more details
more detailsSmartMappingSliderBase
Number

The maximum value or upper bound of the slider.

more details
more detailsSmartMappingSliderBase
Number

The minimum value or lower bound of the slider.

more details
more detailsSmartMappingSliderBase
String

The state of the view model.

more details
more detailsSmartMappingSliderBase
SizeStop[]

The size stops from the SizeVariable to link to the slider.

more details
more detailsSizeSlider
SizeSliderViewModel

The view model for the SizeSlider widget.

more details
more detailsSizeSlider

Property Details

The ID or node representing the DOM element containing the widget. This property can only be set once. The following examples are all valid use cases when working with widgets.

Examples:
// Create the HTML div element programatically at runtime and set to the widget's container
const basemapGallery = new BasemapGallery({
  view: view,
  container: document.createElement("div")
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});
// Specify an already-defined HTML div element in the widget's container

const basemapGallery = new BasemapGallery({
  view: view,
  container: basemapGalleryDiv
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});

// HTML markup
<body>
  <div id="viewDiv"></div>
  <div id="basemapGalleryDiv"></div>
</body>
// Specify the widget while adding to the view's UI
const basemapGallery = new BasemapGallery({
  view: view
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});
declaredClass Stringreadonly inherited

The name of the class. The declared class name is formatted as esri.folder.className.

destroyed Boolean inherited

When true, this property indicates whether the widget has been destroyed.

histogramConfig HistogramConfig inherited

The Histogram associated with the data represented on the slider. The bins are typically generated using the histogram statistics function.

See also:
Example:
histogram({
  layer: featureLayer,
  field: "fieldName",
  numBins: 30
}).then(function(histogramResult){
  // set the histogram to the slider
  slider.histogramConfig = {
    bins: histogramResult.bins
  };
});

The unique ID assigned to the widget when the widget is created. If not set by the developer, it will default to the container ID, or if that is not present then it will be automatically generated.

label String

The widget's default label. This label displays when it is used within another widget, such as the Expand or LayerList widgets.

labelFormatFunction LabelFormatter inherited

A modified version of Slider.labelFormatFunction, which is a custom function used to format labels on the thumbs, min, max, and average values. Overrides the default label formatter. This function also supports date formatting.

Example:
// For thumb values, rounds each label to whole numbers
slider.labelFormatFunction = function(value, type) {
  return (type === "value-change") ? value.toFixed(0): value;
}

The maximum value or upper bound of the slider. If the largest slider value in the constructor is greater than the max set in this property, then the max will update to match the largest slider value.

Example:
slider.max = 150;

The minimum value or lower bound of the slider. If the smallest slider value in the constructor is greater than the min set in this property, then the min will update to match the smallest slider value.

Example:
slider.min = -150;
state Stringreadonly inherited

The state of the view model.

Possible Values: ready | disabled

The size stops from the SizeVariable to link to the slider.

See also:
Example:
sizeRendererCreator.createContinuousRenderer({
  layer: featureLayer,
  field: "fieldName",
  basemap: "gray"
}).then(function(sizeResponse){
  const slider = new SizeSlider({
    stops: sizeResponse.visualVariable.stops,
    container: "sliderDiv"
  });
});

The view model for the SizeSlider widget. This class contains all the logic (properties and methods) that controls this widget's behavior. See the SizeSliderViewModel class to access all properties and methods on the SizeSlider widget.

Method Overview

NameReturn TypeSummaryClass
String

A utility method used for building the value for a widget's class property.

more details
more detailsWidget

Destroys the widget instance.

more details
more detailsWidget
Boolean

Emits an event on the instance.

more details
more detailsWidget
SizeSlider

A convenience function used to create a SizeSlider widget instance from the result of the createContinuousRenderer method.

more details
more detailsSizeSlider
Boolean

Indicates whether there is an event listener on the instance that matches the provided event name.

more details
more detailsWidget
Object

Registers an event handler on the instance.

more details
more detailsWidget

Widget teardown helper.

more details
more detailsWidget

This method is primarily used by developers when implementing custom widgets.

more details
more detailsWidget
Object

This method is primarily used by developers when implementing custom widgets.

more details
more detailsWidget

Renders widget to the DOM immediately.

more details
more detailsWidget

This method is primarily used by developers when implementing custom widgets.

more details
more detailsWidget

A convenience function used to update the properties of a SizeSlider widget instance from the result of the createContinuousRenderer method.

more details
more detailsSizeSlider
SizeVariable

A convenience function used to update the SizeVariable to match the values of the stops on the slider.

more details
more detailsSizeSlider

Method Details

classes(classNames){String}inherited

A utility method used for building the value for a widget's class property. This aids in simplifying CSS class setup.

Parameter:
classNames (String|String[]|Object)[]
repeatable

The class names.

Returns:
TypeDescription
StringThe computed class name.
See also:
Example:
// .tsx syntax showing how to set CSS classes while rendering the widget

render() {
  const dynamicIconClasses = {
    [CSS.myIcon]: this.showIcon,
    [CSS.greyIcon]: !this.showIcon
  };

  return (
    <div class={classes(CSS.root, CSS.mixin, dynamicIconClasses)} />
  );
}
destroy()inherited

Destroys the widget instance.

emit(type, event){Boolean}inherited

Emits an event on the instance. This method should only be used when creating subclasses of this class.

Parameters:
type String

The name of the event.

event Object
optional

The event payload.

Returns:
TypeDescription
Booleantrue if a listener was notified
fromRendererResult(rendererResult, histogramResult){SizeSlider}static

A convenience function used to create a SizeSlider widget instance from the result of the createContinuousRenderer method.

This method sets the slider stops, min, max, and histogramConfig. It is still the developer's responsibility to assign it a proper container and any other optional properties.

Parameters:

The result object from the createContinuousRenderer method.

histogramResult HistogramResult
optional

The result histogram object from the histogram method.

Returns:
TypeDescription
SizeSliderReturns a SizeSlider instance. This will not render until you assign it a valid container.
Example:
const params = {
  layer: layer,
  basemap: map.basemap,
  field: "POP_POVERTY"
};

let rendererResult = null;

sizeRendererCreator
  .createContinuousRenderer(colorParams)
  .then(function(response) {
    rendererResult = response;
    layer.renderer = response.renderer;

    return histogram({
      layer: layer,
      valueExpression: params.field,
      numBins: 30
    });
  })
   .then(function(histogramResult) {

     const sizeSlider = SizeSlider.fromRendererResult(rendererResult, histogramResult);
     sizeSlider.container = "slider";

     // when the user slides the handle(s), update the renderer
     // with the updated size properties

     sizeSlider.on(["thumb-change", "thumb-drag"], function() {
       const renderer = layer.renderer.clone();
       const sizeVariable = renderer.visualVariables[0];
       renderer.visualVariables = [ sizeSlider.updateVisualVariable( sizeVariable ) ];
       layer.renderer = renderer;
     });
   })
   .catch(function(error) {
     console.log("there was an error: ", error);
   });
hasEventListener(type){Boolean}inherited

Indicates whether there is an event listener on the instance that matches the provided event name.

Parameter:
type String

The name of the event.

Returns:
TypeDescription
BooleanReturns true if the class supports the input event.
on(type, listener){Object}inherited

Registers an event handler on the instance. Call this method to hook an event with a listener.

Parameters:

A event type, or an array of event types, to listen for.

listener Function

The function to call when the event is fired.

Returns:
TypeDescription
ObjectReturns an event handler with a remove() method that can be called to stop listening for the event(s).
PropertyTypeDescription
removeFunctionWhen called, removes the listener from the event.
Example:
view.on("click", function(event){
  // event is the event handle returned after the event fires.
  console.log(event.mapPoint);
});
own(handles)inherited

Widget teardown helper. Any handles added to it will be automatically removed when the widget is destroyed.

Parameter:

Handles marked for removal once the widget is destroyed.

postInitialize()inherited

This method is primarily used by developers when implementing custom widgets. Executes after widget is ready for rendering.

render(){Object}inherited

This method is primarily used by developers when implementing custom widgets. It must be implemented by subclasses for rendering.

Returns:
TypeDescription
ObjectThe rendered virtual node.
renderNow()inherited

Renders widget to the DOM immediately.

scheduleRender()inherited

This method is primarily used by developers when implementing custom widgets. Schedules widget rendering. This method is useful for changes affecting the UI.

updateFromRendererResult(rendererResult, histogramResult)

A convenience function used to update the properties of a SizeSlider widget instance from the result of the createContinuousRenderer method. This method is useful for cases when the app allows the end user to switch data variables used to render the data.

Parameters:

The result object from the createContinuousRenderer method.

histogramResult HistogramResult
optional

The result histogram object from the histogram method.

Example:
const params = {
  layer: layer,
  basemap: map.basemap,
  field: "POP_POVERTY"
};

let rendererResult = null;

sizeRendererCreator
  .createContinuousRenderer(colorParams)
  .then(function(response) {
    rendererResult = response;
    layer.renderer = response.renderer;

    return histogram({
      layer: layer,
      valueExpression: params.field,
      numBins: 30
    });
  })
   .then(function(histogramResult) {
     sizeSlider.updateFromRendererResult(rendererResult, histogramResult);
   })
   .catch(function(error) {
     console.log("there was an error: ", error);
   });
updateVisualVariable(sizeVariable){SizeVariable}

A convenience function used to update the SizeVariable to match the values of the stops on the slider.

This is particularly useful for Size visual variables that have a set minDataValue and maxDataValue. This method will properly reconstruct the variable to set on the renderer so it matches the stops on the slider.

Parameter:
sizeVariable SizeVariable

The size visual variable from the renderer to update to the set stops on the slider.

Returns:
TypeDescription
SizeVariableReturns the updated visual variable to set back on the renderer.
Example:
sizeSlider.on(["thumb-change", "thumb-drag"], function() {
  const renderer = layer.renderer.clone();
  const sizeVariable = renderer.visualVariables[0];
  renderer.visualVariables = [ sizeSlider.updateVisualVariable( sizeVariable ) ];
  layer.renderer = renderer;
});

Event Overview

NameTypeSummaryClass
{oldValue: Number,type: String,value: Number}

Fires when a user changes the max of the slider.

more details
more detailsSmartMappingSliderBase
{oldValue: Number,type: String,value: Number}

Fires when a user changes the min of the slider.

more details
more detailsSmartMappingSliderBase
{index: Number,oldValue: Number,type: String,value: Number}

Fires when a user changes the value of a thumb via keyboard editing of the label on the widget.

more details
more detailsSmartMappingSliderBase
{index: Number,state: String,type: String,value: Number}

Fires when a user drags a thumb on the widget.

more details
more detailsSmartMappingSliderBase

Event Details

max-changeinherited

Fires when a user changes the max of the slider.

Properties:
oldValue Number

The former max (or bound) of the slider.

type String

The type of the event. For this event, the type is always max-change.

value Number

The value of the max (or bound) of the slider when the event is emitted.

Example:
slider.on("max-change", function() {
  const renderer = layer.renderer.clone();
  const visualVariable = renderer.visualVariables[0].clone();
  colorVariable.stops = slider.stops;
  renderer.visualVariables = [ visualVariable ];
  layer.renderer = renderer;
});
min-changeinherited

Fires when a user changes the min of the slider.

Properties:
oldValue Number

The former min value (or bound) of the slider.

type String

The type of the event. For this event, the type is always min-change.

value Number

The value of the min value (or bound) of the slider when the event is emitted.

Example:
slider.on("min-change", function() {
  const renderer = layer.renderer.clone();
  const visualVariable = renderer.visualVariables[0].clone();
  colorVariable.stops = slider.stops;
  renderer.visualVariables = [ visualVariable ];
  layer.renderer = renderer;
});
thumb-changeinherited

Fires when a user changes the value of a thumb via keyboard editing of the label on the widget.

Properties:
index Number

The 0-based index of the thumb emitting the event.

oldValue Number

The former value of the thumb before the change was made.

type String

The type of the event. For this event, the type is always thumb-change.

value Number

The value of the thumb when the event is emitted.

Example:
slider.on("thumb-change", function() {
  const renderer = layer.renderer.clone();
  const visualVariable = renderer.visualVariables[0].clone();
  colorVariable.stops = slider.stops;
  renderer.visualVariables = [ visualVariable ];
  layer.renderer = renderer;
});
thumb-draginherited

Fires when a user drags a thumb on the widget.

Properties:
index Number

The 0-based index of the thumb emitting the event.

state String

The state of the drag.

Possible Values: start | drag

type String

The type of the event. For this event, the type is always thumb-drag.

value Number

The value of the thumb when the event is emitted.

Example:
slider.on("thumb-drag", function() {
  const renderer = layer.renderer.clone();
  const visualVariable = renderer.visualVariables[0].clone();
  colorVariable.stops = slider.stops;
  renderer.visualVariables = [ visualVariable ];
  layer.renderer = renderer;
});

API Reference search results

NameTypeModule
Loading...