Class: Icon

ol/style/Icon~Icon


import Icon from 'ol/style/Icon';

Set icon style for vector features.

new Icon(opt_options)

style/Icon.js, line 60
Name Type Description
options

Options.

Name Type Default Description
anchor Array.<number> [0.5, 0.5]

Anchor. Default value is the icon center.

anchorOrigin module:ol/style/IconOrigin

Origin of the anchor: bottom-left, bottom-right, top-left or top-right. Default is top-left.

anchorXUnits module:ol/style/IconAnchorUnits

Units in which the anchor x value is specified. A value of 'fraction' indicates the x value is a fraction of the icon. A value of 'pixels' indicates the x value in pixels. Default is 'fraction'.

anchorYUnits module:ol/style/IconAnchorUnits

Units in which the anchor y value is specified. A value of 'fraction' indicates the y value is a fraction of the icon. A value of 'pixels' indicates the y value in pixels. Default is 'fraction'.

color module:ol/color~Color | string

Color to tint the icon. If not specified, the icon will be left as is.

crossOrigin null | string

The crossOrigin attribute for loaded images. Note that you must provide a crossOrigin value if you are using the WebGL renderer or if you want to access pixel data with the Canvas renderer. See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.

img HTMLImageElement | HTMLCanvasElement

Image object for the icon. If the src option is not provided then the provided image must already be loaded. And in that case, it is required to provide the size of the image, with the imgSize option.

offset Array.<number> [0, 0]

Offset, which, together with the size and the offset origin, define the sub-rectangle to use from the original icon image.

offsetOrigin module:ol/style/IconOrigin

Origin of the offset: bottom-left, bottom-right, top-left or top-right. Default is top-left.

opacity number 1

Opacity of the icon.

scale number 1

Scale.

snapToPixel boolean true

If true integral numbers of pixels are used as the X and Y pixel coordinate when drawing the icon in the output canvas. If false fractional numbers may be used. Using true allows for "sharp" rendering (no blur), while using false allows for "accurate" rendering. Note that accuracy is important if the icon's position is animated. Without it, the icon may jitter noticeably.

rotateWithView boolean false

Whether to rotate the icon with the view.

rotation number 0

Rotation in radians (positive rotation clockwise).

size module:ol/size~Size

Icon size in pixel. Can be used together with offset to define the sub-rectangle to use from the origin (sprite) icon image.

imgSize module:ol/size~Size

Image size in pixels. Only required if img is set and src is not, and for SVG images in Internet Explorer 11. The provided imgSize needs to match the actual size of the image.

src string

Image source URI.

Methods

clone(){module:ol/style/Icon~Icon}

style/Icon.js, line 219

Clones the style. The underlying Image/HTMLCanvasElement is not cloned.

Returns:
The cloned style.

getAnchor()

style/Icon.js, line 243

getColor(){module:ol/color~Color}

style/Icon.js, line 300

Get the icon color.

Returns:
Color.

getImage(pixelRatio){HTMLImageElement|HTMLCanvasElement}

style/Icon.js, line 311

Get the image icon.

Name Type Description
pixelRatio number

Pixel ratio.

Returns:
Image or Canvas element.

getOrigin()

style/Icon.js, line 347

getSize()

style/Icon.js, line 386

getSrc(){string|undefined}

style/Icon.js, line 378

Get the image URL.

Returns:
Image src.

load()

style/Icon.js, line 406

Load not yet loaded URI. When rendering a feature with an icon style, the vector renderer will automatically call this method. However, you might want to call this method yourself for preloading or other purposes.

setAnchor(anchor)

style/Icon.js, line 290

Set the anchor point. The anchor determines the center point for the symbolizer.

Name Type Description
anchor Array.<number>

Anchor.