require(["esri/views/support/colorUtils"], (viewColorUtils) => { /* code goes here */ });
import * as viewColorUtils from "@arcgis/core/views/support/colorUtils.js";
esri/views/support/colorUtils
Contains utilities for working with colors in the View.
Method Overview
Name | Return Type | Summary | Object |
---|---|---|---|
Promise<Color> | Returns the average color of the view's background within the view's extent. | colorUtils | |
Promise<("light"|"dark")> | This method inspects the basemap and background of a MapView and returns either | colorUtils |
Method Details
-
getBackgroundColor
getBackgroundColor(view){Promise<Color>}
-
Returns the average color of the view's background within the view's extent. The view's background includes the non-reference base layers of the map's basemap, the background color of the web map (if applicable), and the background color of the view's container.
ParameterReturnsType Description Promise<Color> Resolves to the average color of the input view's background. ExampleviewColorUtils.getBackgroundColor(view) .then(function(averageColor){ // averageColor is the input view's average background color });
-
This method inspects the basemap and background of a MapView and returns either
light
ordark
as the theme of the background depending on if the average color of the basemap and the view's background is light or dark.The background theme is determined by taking the average color of the view's background and basemap and determining its brightness based on this algorithm for determining color visibility.
ReturnsType Description Promise<("light"|"dark")> Resolves to a string whose value can be either light
ordark
.Exampleconst backgroundTheme = await viewColorUtils.getBackgroundColorTheme(view); if(backgroundTheme === "dark"){ // style other app elements with a dark theme }