▾
Median household income in southern California.
Data visualization has a paradox: to properly visualize a dataset, you first need to be familiar with it; but to understand the data, you usually first have to visualize it.
Understanding the data involves knowing summary statistics, such as the maximum and minimum values, the mean, standard deviation, and the overall distribution. Without that understanding, you can easily create misleading visualizations and spend a lot of time on trial and error before getting a visualization right.
In addition to understanding the data, you should also be familiar with basic principles of cartography and color theory when creating a spatial data visualization. Not everyone has an eye for design and understands problems associated with visualizing numeric and categorical data with color.
In short, data visualization is hard and requires a lot of patience.
What is Smart Mapping?
Smart Mapping is designed to help developers get started with data visualization. It consists of more than a dozen APIs that generate renderers specific to an input dataset. These APIs are designed to help users and developers understand their data so they can make informed decisions best suited for visualizing it.
Smart mapping will help you understand the nature of the data (the statistics and spread), and suggest a set of color ramps designed by seasoned cartographers specifically for the desired style.
Developers can use the Smart Mapping APIs to:
- Familiarize themselves with an unknown or unfamiliar dataset.
- Select colorblind-friendly color ramps and schemes best suited for a layer given its background.
- Build apps that allow users to explore unfamiliar datasets using a variety of styles and widgets.
- Build apps that allow users to style layers and save them to webmaps.
How Smart Mapping works
Smart mapping consists of the following modules, organized by style:
- colorRendererCreator
- dotDensityRendererCreator
- heatmapRendererCreator
- locationRendererCreator
- opacityVariableCreator
- predominanceRendererCreator
- relationshipRendererCreator
- sizeRendererCreator
- typeRendererCreator
- univariateColorSizeRendererCreator
The createRenderer method in each of these modules queries the summary statistics of the data, and selects a color scheme best suited for the given basemap or background color of the view.
Each smart mapping method typically requires the following:
- The layer to which the output renderer will be applied
- The view where the layer is rendered
- The field or Arcade expression containing the data for the visualization
A continuous color renderer can use a diverging, or above-and-below, color ramp.
const { renderer } = await colorRendererCreator.createContinuousRenderer({ layer: featureLayer, view: mapView, field: "Median_HH_Income", theme: "above-and-below",});
featureLayer.renderer = renderer;20 collapsed lines
<!doctype html><html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Smart mapping - income by color</title>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.2/"></script>
<style> html, body { height: 100%; margin: 0; } </style> </head>
<body> <arcgis-map item-id="d81a583f288f48f3afe4947a71fa3065"> <arcgis-zoom slot="top-left"></arcgis-zoom> <arcgis-expand slot="top-left"> <arcgis-legend></arcgis-legend> </arcgis-expand> </arcgis-map>2 collapsed lines
</body></html>79 collapsed lines
<!doctype html><html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Smart Mapping | Sample | ArcGIS Maps SDK for JavaScript</title>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.2/"></script>
<style> html, body { height: 100%; margin: 0; } calcite-card { padding: 3px; height: 400px; text-align: center; width: 300px; } </style> </head>
<body> <arcgis-map center="-117.603514, 33.955457" scale="1155581"> <arcgis-zoom slot="top-left"></arcgis-zoom> <arcgis-expand slot="top-left"> <arcgis-legend></arcgis-legend> </arcgis-expand> <calcite-card slot="top-right"> <strong>2019 Median Household Income</strong> <arcgis-slider-color-legacy precision="2"></arcgis-slider-color-legacy> <em> The U.S. Department of Housing and Urban Development (HUD) low-income threshold for a family of four in Los Angeles in shown. </em> </calcite-card> </arcgis-map>
<script type="module"> const [Map, FeatureLayer, colorRendererCreator, colorSymbology, histogram, Color, intl] = await $arcgis.import([ "@arcgis/core/Map.js", "@arcgis/core/layers/FeatureLayer.js", "@arcgis/core/smartMapping/renderers/color.js", "@arcgis/core/smartMapping/symbology/color.js", "@arcgis/core/smartMapping/statistics/histogram.js", "@arcgis/core/Color.js", "@arcgis/core/intl.js", ]);
const colorSlider = document.querySelector("arcgis-slider-color-legacy"); await colorSlider.componentOnReady();
// listen to arcgisThumbChange and arcgisThumbDrag events // update the layer's renderer to match the slider's color stops colorSlider.addEventListener("arcgisThumbChange", updateRendererFromSlider); colorSlider.addEventListener("arcgisThumbDrag", updateRendererFromSlider); colorSlider.addEventListener("arcgisPropertyChange", updateRendererFromSlider);
const layer = new FeatureLayer({ portalItem: { id: "340a8efc331f4cd59fecbc4ab8e2a311", }, definitionExpression: "MEDHINC_CY > 0", visible: false, });
const viewElement = document.querySelector("arcgis-map"); viewElement.map = new Map({ basemap: { portalItem: { id: "3582b744bba84668b52a16b0b6942544", }, }, layers: [layer], });
// configure parameters for the color renderer generator // the layer must be specified along with a field name // or arcade expression. The basemap and other properties determine // the appropriate default color scheme. const redAndGreenScheme = colorSymbology.getSchemeByName({ basemap: viewElement.map.basemap, geometryType: "polygon", theme: "above-and-below", name: "Red and Green 4", });
// flip the red and green scheme so green is on top const moneyScheme = colorSymbology.flipColors(redAndGreenScheme);
const colorParams = { view: viewElement.view, layer: layer, field: "MEDHINC_CY", theme: "above-and-below", colorScheme: moneyScheme, };
const rendererResult = await colorRendererCreator.createContinuousRenderer(colorParams);
// set the renderer to the layer and add it to the map const vv = rendererResult.visualVariable; layer.renderer = rendererResult.renderer; layer.visible = true;
const histogramResult = await histogram({ ...colorParams, numBins: 60, });
// create reference to histogram bar elements for updating // their style as the user drags slider thumbs const bars = []; const histogramConfig = { average: null, barCreatedFunction: (index, element) => { const bin = histogramResult.bins[index]; const midValue = (bin.maxValue - bin.minValue) / 2 + bin.minValue; const color = getColorFromValue(colorSlider.stops, midValue); element.setAttribute("fill", color.toHex()); bars.push(element); }, bins: histogramResult.bins, dataLines: [ { label: "HUD low income", value: 83500 }, { label: "Fed poverty line", value: 25750 }, ], standardDeviation: null, }; colorSlider.updateFromRendererResult(rendererResult, histogramResult); colorSlider.histogramConfig = histogramConfig; colorSlider.labelFormatFunction = (value) => { return intl.formatNumber(value, { style: "currency", currency: "USD", currencyDisplay: "symbol", maximumFractionDigits: 0, minimumFractionDigits: 0, }); };
function updateRendererFromSlider() { const renderer = layer.renderer.clone(); const colorVariable = renderer.visualVariables[0].clone(); colorVariable.stops = colorSlider.stops; renderer.visualVariables = [colorVariable]; layer.renderer = renderer;
bars.forEach((bar, index) => { const bin = colorSlider.histogramConfig.bins[index]; if (bin) { const midValue = (bin.maxValue - bin.minValue) / 2 + bin.minValue; const color = getColorFromValue(colorSlider.stops, midValue); bar.setAttribute("fill", color.toHex()); } }); }
42 collapsed lines
// infers the color for a given value // based on the stops from a ColorVariable function getColorFromValue(stops, value) { let minStop = stops[0]; let maxStop = stops[stops.length - 1];
const minStopValue = minStop.value; const maxStopValue = maxStop.value;
if (value < minStopValue) { return minStop.color; }
if (value > maxStopValue) { return maxStop.color; }
const exactMatches = stops.filter((stop) => { return stop.value === value; });
if (exactMatches.length > 0) { return exactMatches[0].color; }
minStop = null; maxStop = null; stops.forEach((stop, i) => { if (!minStop && !maxStop && stop.value >= value) { minStop = stops[i - 1]; maxStop = stop; } });
const weightedPosition = (value - minStop.value) / (maxStop.value - minStop.value);
return Color.blendColors(minStop.color, maxStop.color, weightedPosition); } </script> </body></html>The methods exposed by these modules may be used in conjunction with the following slider components:
- Classed Color Slider
- Classed Size Slider
- Color Size Slider
- Color Slider
- Heatmap Slider
- Opacity Slider
- Size Slider
Related samples and resources
Size visual variable themes
Generate continuous color visualization
Generate data-driven visualization of unique values
Generate a class breaks visualization
Generate a relationship visualization
Generate a predominance visualization
Generate a dot density visualization
Customize ColorSlider Histogram
API support
| 2D | 3D | Arcade | Points | Lines | Polygons | Mesh | |
|---|---|---|---|---|---|---|---|
| | | | | | | | |
| | | | | | | | |
| | | | | | | ||
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | |
- Color only
- Size variable creators only supported for points
- Size variable creators not supported in 3D