ImageFill

data class ImageFill(val image: ImageRef, val fit: ImageFit = ImageFit.Contain, val scale: Float = 1.0f, val opacity: Float = 1.0f, val backgroundColor: ColorRgba? = null, val repeat: Boolean = false, val anchorX: Float? = null, val anchorY: Float? = null, val extendEdges: Boolean = false, val edgeSoftness: Float = 0.0f) : ShapeStyle

The shape is filled with ONE copy of image — placed per fit, not repeated — drawn at opacity and clipped to the shape. This is the fill for a flag, a floor plan or a photo inside a shape; use ImagePattern for a small tile repeated across it.

The image is laid over the shape's bounding box, centred on it (so for a concave shape the centre can fall outside the shape itself), then clipped to the shape. fit decides its size and scale shrinks or grows that about the centre (0.5f = half the fitted size); with ImageFit.Inscribed the picture goes in the shape's visual centre instead.

backgroundColor, when set, fills the rest of the shape under the picture: the part a picture that doesn't cover the shape leaves empty (the sides a ImageFit.Contain picture doesn't reach, all of the shape around an ImageFit.Inscribed one). Its own alpha is its opacity within the fill. The picture and the background are blended first and opacity then fades the two together, so a background of the picture's main colour (a flag's red) runs seamlessly into it. null leaves the shape empty there, so the map shows through.

extendEdges fills that empty part from the picture itself instead: its outermost row or column of pixels carries on outwards, so a flag's own colours continue past it (a plain red flag turns the shape red, stripes keep running) and no colour has to be picked by hand. The background colour is then laid under it and only shows through a transparent picture. It does nothing with repeat, which leaves no empty part.

edgeSoftness fades the picture out towards its own edges instead of cutting it off sharply: 0f is the sharp edge, 1f fades from the edge all the way to the middle. What shows through is what is under the picture, the backgroundColor or the map, so the picture melts into it. The fade is a smooth curve over a band of that fraction of half the picture's shorter side. With repeat every copy fades at its own edges; with extendEdges there is nothing to fade into and it has no effect.

anchorX/anchorY move the picture: where its centre goes in the shape's bounding box, as fractions of it (0 is the west and north edge, 1 the east and south edge, 0.5 the middle). null keeps where fit puts it (the middle of the box, or the visual centre for ImageFit.Inscribed); either can be set alone. With repeat the picture, sized by fit and scale, is tiled across the shape instead of placed once, one copy centred where it would have been. The tiles are laid on the ground (they grow and shrink with the map and keep the same number across the shape), not on the screen like an ImagePattern's.

Only ImageRef.Bytes are supported: the picture has to be in memory to be clipped to the shape, and a URL is only downloaded later. A URL, an undecodable image, a platform with no decoder yet (web and iOS for now) or a shape spanning more than 180 degrees of longitude (e.g. across the antimeridian) all fall back to a neutral grey placeholder fill. On a line or a marker this behaves like ImagePattern (the image is the line's or the icon's picture).

Constructors

Link copied to clipboard
constructor(image: ImageRef, fit: ImageFit = ImageFit.Contain, scale: Float = 1.0f, opacity: Float = 1.0f, backgroundColor: ColorRgba? = null, repeat: Boolean = false, anchorX: Float? = null, anchorY: Float? = null, extendEdges: Boolean = false, edgeSoftness: Float = 0.0f)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard