DrawnPolygon

data class DrawnPolygon(val id: EntityId, val style: ShapeStyle, val vertices: List<Vertex>, val outlineStyle: ShapeStyle? = null, val outlineWidth: Float = 1.0f, val extraRings: List<List<Vertex>> = emptyList(), val description: String? = null, val zIndex: Int = 0, val properties: Map<String, String> = emptyMap()) : DrawableEntity

A closed, filled shape: a ring of vertices, and optionally extraRings — more rings of the same shape, each of them either another separate part (the Aegean islands, Thrace beside Anatolia) or a hole in a part (a lake, an enclave). Every ring needs at least 3 vertices, as fewer points cannot describe an enclosed area.

There is no flag saying which ring is a part and which a hole: the shape is what the rings enclose under the even-odd rule — a point is inside it when it is inside an odd number of rings. A ring inside another one is a hole, a ring inside that hole is a part again, a ring away from the others is a part. This is the same rule WWK fills a Polygon with and the one the image fill is cut with, so all three agree. The first ring, vertices, is the one the shape's visual centre and everything that had a single ring before refer to; the order of the others is only the order they were added in. Rings may not share vertices: every VertexId is unique across all of them.

Unlike DrawnPolyline/DrawnMarker, a polygon has both an interior AND a border, so it needs two independent styles: style (inherited from DrawableEntity) fills the interior, outlineStyle draws the border. They're separate because either can vary on its own (e.g. same fill color, thicker border when selected).

Constructors

Link copied to clipboard
constructor(id: EntityId, style: ShapeStyle, vertices: List<Vertex>, outlineStyle: ShapeStyle? = null, outlineWidth: Float = 1.0f, extraRings: List<List<Vertex>> = emptyList(), description: String? = null, zIndex: Int = 0, properties: Map<String, String> = emptyMap())

Properties

Link copied to clipboard
open override val description: String?

Free text about the shape (what it is, a source, a note), for the host to show where it likes, for example in a popup when the shape is tapped. The library only keeps it: nothing is drawn from it. null is no description.

Link copied to clipboard
Link copied to clipboard
open override val id: EntityId

The id that names this shape, stable for as long as it exists.

Link copied to clipboard

the border's color, or null for no visible border at all (isDrawOutline = false — a deliberate choice, not "unspecified", so a polygon nobody asked to have a border doesn't render WWK's default one).

Link copied to clipboard

the border's thickness in screen pixels, must be greater than 0. Only meaningful when outlineStyle is non-null.

Link copied to clipboard
open override val properties: Map<String, String>

Data attached to the shape, as named values: what a GeoJSON feature's properties or a KML placemark's ExtendedData hold (a population, a country code, a year, a source). The library only keeps it, it is not drawn, and it is carried through the file formats: nothing in it means anything to the engine, so a host may put what it needs there. Values are text; a number or a flag read from a file comes in as its text (5000000, true) and goes back out as a text. Empty when there is none.

Link copied to clipboard

Every ring: vertices first, then extraRings.

Link copied to clipboard
open override val style: ShapeStyle

How the shape looks (see ShapeStyle for what it means for each kind of shape).

Link copied to clipboard
Link copied to clipboard
open override val zIndex: Int

Where the shape lies in the drawing order: a shape with a higher number is drawn over one with a lower number, whatever kind each of them is. Shapes with the same number keep the order of their kinds (polygons below lines below markers) and, within a kind, the order they were added in. A tap on a place where shapes overlap reaches the one that is drawn on top.

Functions

Link copied to clipboard
fun mapRings(transform: (List<Vertex>) -> List<Vertex>): DrawnPolygon

This polygon with every ring replaced by what transform makes of it, keeping the order.

Link copied to clipboard
fun ringIndexOf(vertexId: VertexId): Int

The index in rings of the ring that holds vertexId, or -1 if no ring does.

Link copied to clipboard
Link copied to clipboard

This polygon with ring added as one more ring (another part, or a hole in one).

Link copied to clipboard

This polygon without the ring at index; the next one becomes the first when it is the first that goes.

Link copied to clipboard
Link copied to clipboard
fun withRing(index: Int, ring: List<Vertex>): DrawnPolygon

This polygon with the ring at index (in rings) replaced by ring.

Link copied to clipboard

This polygon with ring inserted at index in rings (the inverse of withoutRing).

Link copied to clipboard

This shape with another zIndex (see DrawableEntity.zIndex).