Selections and region editing
Ordinary click and hover selections use zero-based component indices in one loaded collection. A NamedSelection instead groups semantic feature IDs, geographic regions, and flows under a name and color. It can be shared with a database through selection SQL.
Native editor
Enable selection in showUi to display the native editor. Run the example, choose Polygon or Rectangle, and draw a region. Create a second region and use Flow Arrow to connect them; Move, Undo, and Delete edit the selection. Changes replace the console result below the map.
The native overlay follows the map's view and terrain. Named selection events do not replace ordinary click/hover events. The playground destroys its map before a rerun or page navigation; applications must call map.destroy() themselves.
Choose which UI elements are visible
new AutkMap(canvas, { showUi: { menu: true, legend: false, selection: true } })
map.updateUi({ legend: true })
console.log(map.uiConfig)| Setting | Behavior |
|---|---|
showUi: true (default) | Menu and legend enabled; selection editor disabled. |
showUi: false | All optional controls disabled; credits remain visible. |
showUi: { ... } | Only explicitly true keys are enabled; omitted keys are false. |
updateUi({ ... }) | Patches only supplied keys, preserving the others. |
updateUi(true) / updateUi(false) | Restores the boolean presets above. |
map.showUi reports whether any optional control is enabled; map.uiConfig reports each element. Hidden controls do not disable programmatic APIs.
Manage groups programmatically
Use createNamedSelection(name?, color?), addNamedSelection(selection), setActiveNamedSelection(selection), and removeNamedSelection(selection). Read map.namedSelections, map.activeNamedSelection, and map.selectionTool; choose a tool through setSelectionTool().
A place is either { kind: 'feature', layer: 'zones', id: 'south' } or { kind: 'region', ring }. IDs are semantic strings/numbers; they are not a click event's collection index. Regions are closed [longitude, latitude] rings in WGS84 regardless of the workspace CRS.
A flow has { from, to, a, b }: its endpoint places define origin and destination; a and b are geographic arrow anchors. selection.moveRegion(ring, [deltaLon, deltaLat]) shifts a region and connected endpoints atomically. removePlace(place, { cascadeFlows: true }) also removes its flows; undo() and clear() edit the group.
SelectionEvent.CHANGE observes an individual group. MapEvent.NAMED_SELECTION reports { active, selections, changed } when a registered group changes or the active group switches. Treat ringKey() and placeKey() as short cache keys, not equality proofs; use samePlace() for equality and containment helpers for geographic tests.
Lower-level drawing and projection
Use RegionDrawer when your application owns its own controls instead of the native editor:
import { RegionDrawer, RegionDrawerEvent } from '@urban-toolkit/autk-map'
const drawer = new RegionDrawer(map, canvas.parentElement)
drawer.events.on(RegionDrawerEvent.REGION, ({ ring }) => {
selection.addPlace({ kind: 'region', ring })
})
drawer.setTool('polygon')The host must be positioned (for example position: relative). Polygon, rectangle, and arrow completion use REGION/ARROW events. Enter finishes a polygon; Escape cancels. Redrawing is event-driven, and destroying the map tears down attached drawers.
screenToLonLat(x, y) accepts CSS-pixel coordinates relative to the canvas, not page coordinates. lonLatToScreen(lon, lat) returns the inverse mapping. Either can return null when a point cannot be projected (for example above the horizon); do not substitute zero coordinates.
End-to-end example
Explore Manhattan taxi flows connects native region/flow editing to DuckDB predicates and linked plot subsets. The database guide explains the CRS and identity contracts used by those queries.