DrawLayer

class DrawLayer(entityRepository: EntityRepository, stateMachine: DrawStateMachine, scope: CoroutineScope, onContentChanged: () -> Unit = {}, handleStyle: HandleStyle = HandleStyle(), highlightStyle: HighlightStyle = HighlightStyle(), buildOnFirstFrame: Boolean = false) : RenderableLayer, Animatable

Keeps a WWK RenderableLayer in sync with entityRepository's live entity list, so a host app can add one DrawLayer to its WorldWindow and never touch WWK renderables directly.

Builds a WWK renderable only for what is new or changed: on every emission each renderable is looked up by what it was made from (the entity, whether it is selected or being edited, a live drag preview, the handle or highlight style...) and kept when that is unchanged. So selecting a shape, going into edit mode, deleting one or dragging a vertex touches only the shapes (and handles) involved, not every shape on the map — a rebuilt WWK shape costs its tessellation and GPU buffers again, which with hundreds of large polygons ran the heap out. The layer's content is then just the list of those renderables in draw order (polygons, then polylines, then markers, then the draft, then the editing handles), and it is only replaced when that list really differs.

Every renderable is tagged with its originating EntityId via ENTITY_ID_KEY (see Renderable.putUserProperty) — this is how adapter.input.PickInputBridge maps a WWK pick result back to a com.tcsappdev.worldwinddraw.core.geometry.DrawableEntity.

The entity DrawMode.Select/DrawMode.Edit names also gets a selection highlight (see HighlightMapper.kt): a separate, non-pickable outline/halo renderable, so the entity's own fill and style are never modified. These highlight renderables are deliberately NOT tagged with ENTITY_ID_KEY — they are never pick results.

While stateMachine reports DrawMode.Edit for a polygon/polyline, this layer also adds:

  • one small, individually pickable+Movable "vertex handle" Placemark per existing vertex, tagged with both ENTITY_ID_KEY and VERTEX_ID_KEY — dragging one moves that vertex (PickInputBridge resolves exactly which one from WWK's pick result, no geometry heuristic needed).

  • one smaller, dimmer "midpoint handle" per edge, tagged with ENTITY_ID_KEY and EDGE_INDEX_KEY (not VERTEX_ID_KEY — it isn't a real vertex yet). Dragging one grows the shape a new vertex there, the same interaction Mapbox GL Draw/Google My Maps use. While one is actively being dragged (DrawMode.Edit.ActiveDrag.NewVertex), the shape's outline is rendered with that live position spliced in (so it visibly reshapes as you drag) and the midpoint handle for that specific edge is suppressed — the handle WWK is already dragging is standing in for it until DragEnd actually commits the insert.

onContentChanged must be wired to the host WorldWindow's own redraw request (e.g. worldWindow::requestRedraw). WWK's Android surface renders on demand (RENDERMODE_WHEN_DIRTY) and only redraws itself automatically in response to its own gesture pipeline (pan/zoom/an active drag). A change that lands outside of that — e.g. undo/redo, or any other host-triggered repository mutation — updates this layer's renderables correctly but leaves a stale frame on screen until something else happens to ask for a redraw. This was a real bug caught by visual verification, not something WWK documents: dragging a vertex looked correct (the drag gesture itself keeps requesting redraws), but hitting Undo right after silently changed the data with no visible effect until an unrelated touch forced a redraw.

Constructors

Link copied to clipboard
constructor(entityRepository: EntityRepository, stateMachine: DrawStateMachine, scope: CoroutineScope, onContentChanged: () -> Unit = {}, handleStyle: HandleStyle = HandleStyle(), highlightStyle: HighlightStyle = HighlightStyle(), buildOnFirstFrame: Boolean = false)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val count: Int
Link copied to clipboard
open override var displayName: String?
Link copied to clipboard

How big and what colour the edit handles are (see HandleStyle). Safe to change at any time — e.g. from a host app's settings screen — the layer rebuilds and redraws right away.

Link copied to clipboard

The colours of the selected/edited shape's outline (see HighlightStyle). Live-changeable, like handleStyle.

Link copied to clipboard
open override var isDynamic: Boolean
Link copied to clipboard
open override var isEnabled: Boolean
Link copied to clipboard
open override var isPickEnabled: Boolean
Link copied to clipboard
open override var maxActiveAltitude: Double
Link copied to clipboard
open override var minActiveAltitude: Double
Link copied to clipboard
open override var opacity: Float

Functions

Link copied to clipboard
fun addAllRenderables(layer: RenderableLayer)
fun addAllRenderables(iterable: Iterable<Renderable>)
Link copied to clipboard
fun addRenderable(renderable: Renderable)
fun addRenderable(index: Int, renderable: Renderable)
Link copied to clipboard
Link copied to clipboard
fun getRenderable(index: Int): Renderable
Link copied to clipboard
fun getRenderablesByDisplayName(name: String): List<Renderable>
Link copied to clipboard
open override fun getUserProperty(key: Any): Any?
Link copied to clipboard
open override fun hasUserProperty(key: Any): Boolean
Link copied to clipboard
fun indexOfRenderable(renderable: Renderable): Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun isWithinActiveAltitudes(rc: RenderContext): Boolean
Link copied to clipboard
open operator override fun iterator(): MutableIterator<Renderable>
Link copied to clipboard
open override fun onTick(deltaMs: Long)

Pulses the selection highlight's opacity (see PULSE_DURATION_MS/PULSE_MIN_ALPHA). Register this layer with the host's AnimationController and tick that once per frame. Does nothing — and, importantly, asks for no redraw — while nothing is highlighted, so an idle map isn't redrawn every frame (WWK renders on demand, see onContentChanged).

Link copied to clipboard
open override fun putUserProperty(key: Any, value: Any): Any?
Link copied to clipboard
fun removeAllRenderables(renderables: Iterable<Renderable>): Boolean
Link copied to clipboard
fun removeRenderable(renderable: Renderable): Boolean
fun removeRenderable(index: Int): Renderable
Link copied to clipboard
open override fun removeUserProperty(key: Any): Any?
Link copied to clipboard
open override fun render(rc: RenderContext)
Link copied to clipboard
fun setRenderable(index: Int, renderable: Renderable): Renderable