WorldWindDrawEngine
The whole draw engine in one object: the shapes, the undo history, the drawing state, the layer that puts them on the map and the input that lets a person draw and edit on it. It builds and connects those, so a host does not have to.
// In a Compose screen (what the demo does; a plain Android or iOS host does the same three things):
val engine = remember { WorldWindDrawEngine(scope, overlay = JtsOverlayEngine()) } // 1. build it
LaunchedEffect(engine) { // 2. give it the clock
var last = withFrameNanos { it }
while (true) {
val now = withFrameNanos { it }
engine.tick((now - last) / 1_000_000)
last = now
}
}
WorldWindow(
state = rememberWorldWindowState { ... },
onCreated = { window -> engine.attachTo(window) }, // 3. put it on the map
)
// The host's own buttons:
val state by engine.state.collectAsState()
when (val mode = state.mode) {
is DrawMode.Draw -> { Button("Finish") { engine.finishDrawing() }; Button("Cancel") { engine.cancel() } }
is DrawMode.Edit -> Button("Done") { engine.stopEditing() }
is DrawMode.Select -> { Button("Edit") { engine.edit(mode.entityId) }; Button("Delete") { engine.deleteSelected() } }
else -> Button("Draw") { engine.startDrawing(DrawableEntityType.Polygon) }
}What the host does: attachTo its map window (there is one for each platform, because WorldWind's WorldWindow is not one common type), and call tick once per frame so that animations (the selected shape's pulse, an effect that is playing) advance: the engine has no clock of its own. Everything else is the engine's.
What a person does reaches it through input (taps and drags on the map), and the host's own buttons call the functions here (startDrawing, finishDrawing, select, edit, undo, ...). What the engine shows is in state, entities, canUndo and canRedo, all of them flows to collect.
The parts it is made of are public for a host that needs more than this: repository (to put shapes in without a history step, or to play an effect on), history, layer and send (any DrawEvent).
Parameters
the scope the layer builds the shapes in (the host's own, so that it ends when the host's does).
how many steps can be undone.
how the handles of a shape being edited look; can be changed later through layer.
how a selected shape is marked; can be changed later through layer.
whether the layer builds the shapes in the first frame instead of in the background (see DrawLayer).
Constructors
Properties
The shapes that exist, as a flow.
The shapes that exist. Putting one in here directly is not a step of the history (it cannot be undone); see DrawEvent for what is.
What the engine is doing: idle, drawing, selecting, editing...
Functions
Puts the engine on window: adds its layer, gives it the touches on the map and lets it ask the window to draw again. WorldWind's WorldWindow is a different class on each platform, so this is a function of each platform and the host's code on that platform calls it.
Puts the engine on window: adds its layer, gives it the touches on the map and lets it ask the window to draw again. WorldWind's WorldWindow is a different class on each platform, so this is a function of each platform and the host's code on that platform calls it.
Puts the engine on window: adds its layer, gives it the touches on the map and lets it ask the window to draw again. WorldWind's WorldWindow is a different class on each platform, so this is a function of each platform and the host's code on that platform calls it.
Puts the engine on window: adds its layer, gives it the touches on the map and lets it ask the window to draw again. WorldWind's WorldWindow is a different class on each platform, so this is a function of each platform and the host's code on that platform calls it.
Puts the engine on window: adds its layer, gives it the touches on the map and lets it ask the window to draw again. WorldWind's WorldWindow is a different class on each platform, so this is a function of each platform and the host's code on that platform calls it.
Deletes the selected shape (or the one being edited); it can be undone.
Turns what is being drawn into a shape with the id id (a new one by default) and returns the id; null, and nothing happens, if nothing is being drawn. Whether the points make a shape (a polygon needs 3) is for the engine to say: if they do not, it stays as it was.
Lets the engine ask the host's window to draw again when something changed (a shape, a selection, a step undone). attachTo does this; call it yourself to use a window attachTo does not know.
Moves animatable (an effect, see the morph module) along with every tick until stop is called for it.
Does again the step that was taken back (see HistoryManager.redo); canRedo says whether there is one.
Starts drawing a new shape of type; the person taps the map to place its points, then finishDrawing. style is how it looks while drawn.
Stops moving animatable (an effect that has finished); the opposite of play.
Ends editing and leaves the shape selected.
Takes back the last step (see HistoryManager.undo); canUndo says whether there is one.