Namespace: IconUtilities

IconUtilities

A generic utility object that contains functions used throughout MetacatUI to perform useful functions related to icons, but not used to store or manipulate any state about the application.
Since:
  • 2.28.0
Source:

Methods

adjustViewBox(svgElement, strokeWidth)

Adjusts the viewBox of an SVG element to accommodate a stroke width.
Parameters:
Name Type Description
svgElement SVGElement The SVG element.
strokeWidth number The stroke width applied to the SVG (in pixels).
Since:
  • 2.29.0
Source:

fetchIcon(pid) → {string}

Fetches an SVG given a pid, sanitizes it, then returns the SVG string (after sanitizing it).
Parameters:
Name Type Description
pid string
Source:
Returns:
The icon data.
Type
string

formatSvgForCesiumBillboard(svgString, strokeWidthopt, strokeColoropt) → {SVGElement|null}

Converts an SVG icon string into an SVG element suitable for use as an image in a Cesium billboard. This function enhances the SVG by applying optional stroke properties and ensures the viewBox is adjusted to accommodate the stroke. It is designed in particular to work with Font Awesome 6 solid icons, but may work with other SVGs as well.
Parameters:
Name Type Attributes Default Description
svgString string The SVG markup as a string.
strokeWidth number <optional>
0 The stroke width to apply to the SVG (in pixels).
strokeColor string <optional>
"white" The stroke color.
Since:
  • 2.29.0
Source:
Returns:
- The modified SVG element or null if an error occurs.
Type
SVGElement | null

isSVG(str) → {Boolean}

Simple test to see if a string is an SVG
Parameters:
Name Type Description
str string The string to check
Source:
Returns:
Returns true if the string starts with ``, regardless of case
Type
Boolean

parseSvg(svgString) → {SVGElement}

Parses an SVG string and returns the SVG element.
Parameters:
Name Type Description
svgString string The SVG markup as a string.
Since:
  • 2.29.0
Source:
Returns:
- The SVG element.
Type
SVGElement

removeCommentNodes(svgElement)

Removes comment nodes from an SVG element.
Parameters:
Name Type Description
svgElement SVGElement The SVG element.
Since:
  • 2.29.0
Source:

sanitizeIcon(icon) → {string}

Takes an SVG string and returns it with only the allowed tags and attributes
Parameters:
Name Type Description
icon string The SVG icon string to sanitize
Source:
Returns:
Sanitized icon string.
Type
string

setStrokeProperties(svgElement, strokeWidth, strokeColor)

Sets stroke properties on an SVG element.
Parameters:
Name Type Description
svgElement SVGElement The SVG element.
strokeWidth number The stroke width to apply to the SVG (in pixels).
strokeColor string The stroke color as a CSS color value.
Since:
  • 2.29.0
Source:

svgToBase64(svgElement) → {string}

Takes a SVG element and converts it to a base64 encoded string that can be used as a data URI in an image tag.
Parameters:
Name Type Description
svgElement SVGElement The SVG element to convert.
Since:
  • 2.29.0
Source:
Returns:
- The base64 encoded SVG string.
Type
string