Skip to content
ESM
import "@arcgis/map-components/components/arcgis-slider-classed-color-legacy";
Inheritance:
ArcgisSliderClassedColorLegacyPublicLitElement
Since
ArcGIS Maps SDK for JavaScript 5.0

This is a legacy component. It relies on an underlying widget as part of our migration to native web components.

A fully native replacement for this component is in development. Once it reaches feature parity, the legacy component will be deprecated and no longer maintained. At that point, development should use the native component.

The Classed Color Slider component is designed for authoring and exploring data-driven visualizations in any layer that can be rendered with color in a ClassBreaksRenderer.

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

Classed Color Slider with annotations

The updateFromRendererResult() method can be used to intelligently populate slider properties including max, min, the classBreakInfos configuration, and the slider's histogram after the renderer has been created from the result of the createClassBreaksRenderer() method.

const colorRendererCreator = await import("@arcgis/core/smartMapping/renderers/color.js");
const viewElement = document.querySelector("arcgis-map")!;
const classedColorSlider = document.querySelector("arcgis-slider-classed-color-legacy")!;
const featureLayer = new FeatureLayer({
url: "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/ACS_Poverty_by_Age_Boundaries/FeatureServer/1",
});
await viewElement.viewOnReady();
viewElement.map?.add(featureLayer);
const params = {
layer: featureLayer,
field: "B17020_calc_pctPovE",
view: viewElement.view,
numClasses: 4
};
const rendererResult = await colorRendererCreator.createClassBreaksRenderer(params);
featureLayer.renderer = rendererResult.renderer;
const histogramResult = await histogram({
...params,
numBins: 30,
});
await classedColorSlider?.updateFromRendererResult(rendererResult, histogramResult);

This slider should be used to update the classBreakInfos in a ClassBreaksRenderer. It is the responsibility of the app developer to set up event listeners on this slider that update the breaks of the appropriate renderer.

const updateRendererFromSlider = async () => {
const renderer = featureLayer?.renderer?.clone();
if (!renderer || !("classBreakInfos" in renderer) || !renderer.classBreakInfos?.[0]) {
return;
}
const updatedClassBreakInfos = await classedColorSlider.updateClassBreakInfos(renderer.classBreakInfos);
if (!updatedClassBreakInfos) {
return;
}
renderer.classBreakInfos = updatedClassBreakInfos;
featureLayer.renderer = renderer;
};
classedColorSlider.addEventListener("arcgisThumbChange", updateRendererFromSlider);
classedColorSlider.addEventListener("arcgisThumbDrag", updateRendererFromSlider);
classedColorSlider.addEventListener("arcgisPropertyChange", updateRendererFromSlider);
See also

Demo

Properties

autoDestroyDisabled

Property
Type
boolean

If true, the component will not be destroyed automatically when it is disconnected from the document. This is useful when you want to move the component to a different place on the page, or temporarily hide it. If this is set, make sure to call the destroy() method when you are done to prevent memory leaks.

Attribute
auto-destroy-disabled
Default value
false

breaks

Property
Type
Array<ColorBreak>

An array of class breaks with associated colors. The colors mapped to each break can be used to update the renderer of a layer. A minimum of two breaks must be provided to the slider.

See also
Example
classedColorSlider.breaks = [
{ min: 0, max: 15, color: new Color([255, 200, 210]) },
{ min: 15, max: 30, color: new Color([255, 160, 170]) },
{ min: 30, max: 45, color: new Color([255, 110, 120]) },
{ min: 45, max: 60, color: new Color([240, 70, 70]) },
];

histogramConfig

Property
Type
HistogramConfig | null | undefined

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

See also
Example
const histogramResult = await histogram({
layer: featureLayer,
field: "fieldName",
numBins: 30,
});
slider.histogramConfig = {
bins: histogramResult.bins
};
```

icon

Property
Type
IconName

Icon which represents the component. Typically used when the component is controlled by another component (e.g. by the Expand component).

See also
Attribute
icon

inputFormatFunction

Property
Type
LabelFormatFunction | null | undefined

A function used to format user inputs. As opposed to labelFormatFunction, which formats thumb labels, the inputFormatFunction formats thumb values in the input element when the user begins to edit them.

The image below demonstrates how slider input values resemble corresponding slider values by default and won't match the formatting set in labelFormatFunction.

Slider without input formatter

If you want to format slider input values so they match thumb labels, you can pass the same function set in labelFormatFunction to inputFormatFunction for consistent formatting.

Slider with input formatter

However, if an inputFormatFunction is specified, you must also write a corresponding inputParseFunction to parse user inputs to understandable slider values. In most cases, if you specify an inputFormatFunction, you should set the labelFormatFunction to the same value for consistency between labels and inputs.

This property overrides the default input formatter, which formats by calling toString() on the input value.

See also
Example
// Formats the slider input to abbreviated numbers with units
// e.g. a thumb at position 1500 will render with an input label of 1.5k
slider.inputFormatFunction = (value: number): string => {
if (value >= 1000000) {
return (value / 1000000).toPrecision(3) + "m";
}
if (value >= 100000) {
return (value / 1000).toPrecision(3) + "k";
}
if (value >= 1000) {
return (value / 1000).toPrecision(2) + "k";
}
return value.toFixed(0);
};
```

inputParseFunction

Property
Type
InputParseFunction | null | undefined

Function used to parse slider inputs formatted by the inputFormatFunction. This property must be set if an inputFormatFunction is set. Otherwise the slider values will likely not update to their expected positions.

Overrides the default input parses, which is a parsed floating point number.

See also
Example
// Parses the slider input (a string value) to a number value understandable to the slider
// This assumes the slider was already configured with an inputFormatFunction
// For example, if the input is 1.5k this function will parse
// it to a value of 1500
colorSlider.inputParseFunction = (value: string): number => {
const charLength = value.length;
const valuePrefix = parseFloat(value.substring(0, charLength - 1));
const finalChar = value.substring(charLength - 1);
if (parseFloat(finalChar) >= 0) {
return parseFloat(value);
}
if (finalChar === "k") {
return valuePrefix * 1000;
}
if (finalChar === "m") {
return valuePrefix * 1000000;
}
return parseFloat(value);
};
```

labelFormatFunction

Property
Type
LabelFormatFunction | null | undefined

A 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 = (value: number, type?: SliderFormatType): string => {
return (type === "value") ? value.toFixed(0) : value.toString();
};
```

max

Property
Type
number

The maximum value or upper bound of the slider. Once the slider has rendered with the updateFromRendererResult() method, the user may change this property by selecting the label containing the max value on the slider UI. It is the responsibility of the app developer to set up event listeners that update the breaks of the appropriate renderer.

Attribute
max
Example
classedColorSlider.max = 150;

min

Property
Type
number

The minimum value or lower bound of the slider. Once the slider has rendered with the updateFromRendererResult() method, the user may change this property by selecting the label containing the min value on the slider UI. It is the responsibility of the app developer to set up event listeners that update the breaks of the appropriate renderer.

Attribute
min
Example
classedColorSlider.min = -150;

precision

Property
Type
number

Defines how slider thumb values should be rounded. This number indicates the number of decimal places slider thumb values should round to when they have been moved.

Keep in mind this property rounds thumb values and shouldn't be used exclusively for formatting purposes.

Attribute
precision
Default value
4
Example
// Rounds slider thumb values to 7 decimal places
slider.precision = 7;

referenceElement

Property
Type
ArcgisReferenceElement | string | undefined

By assigning the id attribute of the Map or Scene component to this property, you can position a child component anywhere in the DOM while still maintaining a connection to the Map or Scene.

See also
Attribute
reference-element

state

readonly Property
Type
SmartMappingSliderBaseState

The current state of the component.

Methods

MethodSignature
componentOnReady
inherited
componentOnReady(): Promise<this>
destroy(): Promise<void>
updateClassBreakInfos(breakInfos: ClassBreakInfo[]): Promise<ClassBreakInfo[] | null | undefined>
updateFromRendererResult(rendererResult: ClassBreaksRendererResult, histogramResult?: HistogramResult): Promise<void>

componentOnReady

inherited Method
Signature
componentOnReady (): Promise<this>
Inherited from: PublicLitElement

Creates a promise that resolves once the component is fully loaded.

Returns
Promise<this>
Example
const arcgisSliderClassedColorLegacy = document.querySelector("arcgis-slider-classed-color-legacy");
document.body.append(arcgisSliderClassedColorLegacy);
await arcgisSliderClassedColorLegacy.componentOnReady();
console.log("arcgis-slider-classed-color-legacy is ready to go!");

destroy

Method
Signature
destroy (): Promise<void>

Permanently destroy the component.

Returns
Promise<void>

updateClassBreakInfos

Method
Signature
updateClassBreakInfos (breakInfos: ClassBreakInfo[]): Promise<ClassBreakInfo[] | null | undefined>

A convenience function used to update the classBreakInfos of a ClassBreaksRenderer associated with this slider.

The number of breaks from the renderer must match the number of breaks in the slider. Generally, the input breaks for this method should come from the same renderer as one used to create the slider with the updateFromRendererResult() method.

Parameters
ParameterTypeDescriptionRequired
breakInfos

The classBreakInfos from a ClassBreaksRenderer instance to update based on the properties of the slider.

Returns
Promise<ClassBreakInfo[] | null | undefined>

The updated classBreakInfos to set on a ClassBreaksRenderer object.

Example
const renderer = featureLayer?.renderer?.clone();
const updatedClassBreakInfos = await classedColorSlider.updateClassBreakInfos(renderer.classBreakInfos);
renderer.classBreakInfos = updatedClassBreakInfos;
featureLayer.renderer = renderer;

updateFromRendererResult

Method
Signature
updateFromRendererResult (rendererResult: ClassBreaksRendererResult, histogramResult?: HistogramResult): Promise<void>

A convenience function used to update the properties a ClassedColorSlider from the result of the createClassBreaksRenderer() method. Note that this method always expects rendererResult to be defined for the slider to function, but histogramResult is optional.

Parameters
ParameterTypeDescriptionRequired
rendererResult

The result object from the createClassBreaksRenderer() method.

histogramResult

The result histogram object from the histogram() method.

Returns
Promise<void>
Example
const rendererResult = await colorRendererCreator.createClassBreaksRenderer(params);
featureLayer.renderer = rendererResult.renderer;
const histogramResult = await histogram({
...params,
numBins: 30,
});
await classedColorSlider?.updateFromRendererResult(rendererResult, histogramResult);

Events

NameType
CustomEvent<{ name: "breaks" | "histogramConfig" | "max" | "min" | "precision" | "state"; }>

arcgisPropertyChange

Event
arcgisPropertyChange: CustomEvent<{ name: "breaks" | "histogramConfig" | "max" | "min" | "precision" | "state"; }>

Emitted when the value of a property is changed. Use this to listen to changes to properties.

bubbles composed cancelable

arcgisReady

Event
arcgisReady: CustomEvent<void>

Emitted when the component associated with a map or scene view is ready to be interacted with.

bubbles composed cancelable

arcgisThumbChange

Event
arcgisThumbChange: CustomEvent<ThumbChangeEvent>

Fires when a user changes the value of a thumb via the arrow keys or by keyboard editing of the label on the slider.

bubbles composed cancelable

arcgisThumbDrag

Event
arcgisThumbDrag: CustomEvent<ThumbDragEvent>

Fires when a user drags a thumb on the component.

bubbles composed cancelable