Method Overview
Name | Return Type | Summary | Object | |
---|---|---|---|---|
Promise<Color> | more details Returns a color representing the input graphic's symbol. | more details | symbolUtils | |
Promise<Symbol> | more details Returns a symbol representing the input Graphic. | more details | symbolUtils | |
HTMLElement | more details Generates a preview image of a color ramp to display in a custom widget or other DOM element. | more details | symbolUtils | |
Promise<HTMLElement> | more details Generates a preview image of a given symbol that can be displayed in a custom widget or other DOM element. | more details | symbolUtils |
Method Details
-
Since: ArcGIS API for JavaScript 4.19
-
Returns a color representing the input graphic's symbol. This method is useful when you need to know the exact color of a Graphic's symbol, particularly when the graphic comes from the result of a hitTest() and its symbol properties may be empty. A symbol's properties won't be populated when a Renderer defines the visualization of a layer rather than symbols set individually on each graphic of a layer. This is the case for FeatureLayer, and any other layer that has a
renderer
property.Parameters:Specification:graphic GraphicThe graphic from which to retrieve the displayed color. This commonly comes from a hitTest() or layer view query operation.
options ObjectoptionalOptions for generating the display color of the input graphic. These must be specified if the input graphic comes from a layer with a renderer that has visual variables applied. See the object specification below.
Specification:scale NumberoptionalThe view scale at which the graphic is displayed.
viewingMode StringoptionalThe viewingMode of the view, if the graphic is displayed in a SceneView.
spatialReference SpatialReferenceoptionalThe spatial reference of the view in which the graphic is displayed.
renderer RendereroptionalThe renderer of the layer associated with the
graphic
.resolution NumberoptionalThe resolution of the view at which the graphic is displayed.
Returns:Type Description Promise<Color> Returns the color representing the input graphic. Example:view.on("click", async (event) => { const { results } = await view.hitTest(event, { include: layer }); const graphic = results[0].graphic; // do something with the result color const color = await symbolUtils.getDisplayedColor(graphic); });
-
Returns a symbol representing the input Graphic. This method is useful when you need to know the exact visual properties of a Graphic's symbol, particularly when the graphic comes from the result of a hitTest() and its symbol properties may be empty. A symbol's properties won't be populated when a Renderer defines the visualization of a layer rather than symbols set individually on each graphic of a layer. This is the case for FeatureLayer, and any other layer that has a
renderer
property.Parameters:Specification:graphic GraphicThe graphic from which to retrieve the displayed symbol. This commonly comes from a hitTest() operation.
options ObjectoptionalOptions for generating the display symbol of the input graphic. These must be specified if the input graphic comes from a layer with a renderer that has visual variables applied. See the object specification below.
Specification:scale NumberoptionalThe view scale at which the symbol is displayed.
viewingMode StringoptionalThe viewingMode of the view, if the symbol is displayed in a SceneView.
spatialReference SpatialReferenceoptionalThe spatial reference of the view in which the symbol is displayed.
renderer RendereroptionalThe renderer of the layer associated with the
graphic
.resolution NumberoptionalThe resolution of the view at which the symbol is displayed.
Returns:Type Description Promise<Symbol> Returns the symbol representing the input graphic. Example:view.on("click", async (event) => { const { results } = await view.hitTest(event, { include: layer }); const graphic = results[0].graphic; // do something with the result symbol const symbol = await symbolUtils.getDisplayedSymbol(graphic, { scale: view.scale, spatialReference: view.spatialReference, resolution: view.resolution }); });
-
renderColorRampPreviewHTML(colors, options){HTMLElement}Since: ArcGIS API for JavaScript 4.13
-
Generates a preview image of a color ramp to display in a custom widget or other DOM element.
Parameters:Specification:An array of colors from which to construct the color ramp.
options ObjectoptionalFormatting options for the color ramp.
Specification:align StringoptionalDefault Value: verticalSpecifies the alignment of the color ramp.
Possible Values:"horizontal"|"vertical"
gradient BooleanoptionalDefault Value: trueIndicates whether to render the color ramp with a continuous gradient. When
false
, distinct colors will appear in the ramp without a gradient.width NumberoptionalThe width of the ramp in pixels.
height NumberoptionalThe height of the ramp in pixels.
Returns:Type Description HTMLElement Returns a preview of the color ramp for display in the DOM. Examples:const colors = [ "#d6ffe1", "#8ceda6", "#2ee860", "#00e33d" ]; const colorRamp = symbolUtils.renderColorRampPreviewHTML(colors, { align: "vertical" }); body.appendChild(colorRamp);
// Primary color scheme from colorSchemes.getSchemes() const schemes = colorSchemes.getSchemes({ basemap: "gray-vector", geometryType: "polygon", theme: "above-and-below" }); const colorRamp = symbolUtils.renderColorRampPreviewHTML(schemes.primaryScheme.colors, { align: "horizontal" }); body.appendChild(colorRamp);
-
renderPreviewHTML(symbol, options){Promise<HTMLElement>}
-
Generates a preview image of a given symbol that can be displayed in a custom widget or other DOM element.
Parameters:Specification:symbol SymbolThe symbol for which to generate a preview image.
options ObjectoptionalFormatting options for the symbol preview image.
Specification:node HTMLElementoptionalThe parent node to append to the symbol.
optional Use a number to set the size (in points) of the symbol preview for any symbol representing a point. Starting at version 4.23, you can provide an object with width and height properties when creating previews for SimpleLineSymbol and SimpleFillSymbol.
Specification:width NumberoptionalThe width of the SimpleLineSymbol or SimpleFillSymbol preview in points. Previews for SimpleFillSymbol must have
isSquareFill
enabled insymbolConfig
for this property to take effect.height NumberoptionalThe height of the SimpleLineSymbol or SimpleFillSymbol preview in points. Previews for SimpleFillSymbol must have
isSquareFill
enabled insymbolConfig
for this property to take effect.maxSize NumberoptionalThe maximum size of the symbol preview in points.
opacity NumberoptionalThe opacity of the layer represented by the
symbol
. Must be a number between 0 and 1.scale BooleanoptionalDefault Value: trueWhen
true
the size of the symbol preview will include the outline in the measurement of the entire symbol. Whenfalse
, the symbol preview will not include the outline in the size measurement, thus matching the symbol size in the view.disableUpsampling BooleanoptionalIndicates whether to disable upsampling for raster images.
optional Options for setting the shape of a fill symbol preview. This can be a single string value (
tall
is the only option), or an object with config options. See the table below for specifics on the configuration options available.Possible Values:"tall"
Specification:isTall BooleanoptionalDefault Value: falseSet to
true
for "tall" symbols in portrait view. This is typically used for 3D cylinder object symbols.isSquareFill BooleanoptionalDefault Value: falseSet to
true
to render the preview as a square instead of a generic polygon shape.rotation NumberoptionalThe rotation of the symbol.
Returns:Type Description Promise<HTMLElement> Returns a preview of the given symbol to display to the DOM. Example:// symbol from SimpleRenderer; const symbol = layer.renderer.symbol.clone(); symbolUtils.renderPreviewHTML(symbol, { node: document.getElementById("preview"), size: 8 });