Class AvaloniaMapsuiMapAdapter
- Assembly
- EncDotNet.S100.Renderers.Mapsui.Avalonia.dll
Adapts a live Mapsui Avalonia control to framework-specific redraw, coordinate conversion, and capture operations.
public sealed class AvaloniaMapsuiMapAdapter : IDisposable
- Inheritance
-
AvaloniaMapsuiMapAdapter
- Implements
- Inherited Members
Remarks
The adapter borrows its control and map. It does not own layers, navigation policy, datasets, or presentation state, and disposing it does not dispose either borrowed object.
Use MapsuiLayerBands and MapsuiMapNavigator directly for framework-neutral layer and navigation behavior.
Fields
DefaultPickRadiusMeters
The default point/curve pick tolerance in metres, mirroring RadiusMeters.
public const double DefaultPickRadiusMeters = 50
Field Value
Methods
Attach(MapControl)
Attaches an adapter to an initialized live map control.
public static AvaloniaMapsuiMapAdapter Attach(MapControl mapControl)
Parameters
mapControlMapControlThe control to adapt. Any Mapsui Avalonia map control works. A CaptureSynchronizedMapControl additionally makes RenderCurrentViewToPngAsync(int, int, double, CancellationToken) race-safe against live paints; a plain control captures best-effort (see that method's remarks).
Returns
- AvaloniaMapsuiMapAdapter
A disposable adapter that borrows the control and its map.
Exceptions
- ArgumentNullException
mapControlis null.- InvalidOperationException
The call is not on Avalonia's UI thread, or the control has no map.
Dispose()
Detaches the adapter without disposing the borrowed control or map.
public void Dispose()
PickAtScreenAsync(IS100MapQuery, double, double, double, int?, CancellationToken)
Picks the S-100 features and coverage samples under a live-viewport pixel by translating it to a geographic query against a session's IS100MapQuery.
public Task<IReadOnlyList<S100Pick>> PickAtScreenAsync(IS100MapQuery query, double xPx, double yPx, double radiusMeters = 50, int? maxResults = null, CancellationToken cancellationToken = default)
Parameters
queryIS100MapQueryThe session query surface to pick against.
xPxdoubleHorizontal live-control pixel coordinate.
yPxdoubleVertical live-control pixel coordinate.
radiusMetersdoublePoint/curve tolerance in metres; defaults to DefaultPickRadiusMeters.
maxResultsint?Optional cap on the returned picks (topmost-first).
cancellationTokenCancellationTokenOptional cancellation token.
Returns
- Task<IReadOnlyList<S100Pick>>
The ranked picks, topmost-first — empty when the pixel is invalid, the viewport is not laid out, or the map CRS is unsupported.
Remarks
This is the UI-framework interaction adapter for PickAsync(GeographicPickQuery, CancellationToken): it reads the live viewport on the UI thread to convert the pixel to WGS-84 and to capture the current resolution (so the session can drop cells scaled out at this zoom), then runs the pick off the UI thread. Pointer gestures, hit panels, and selection remain the host's responsibility.
Exceptions
- ArgumentNullException
queryis null.- ObjectDisposedException
The adapter is detached.
- OperationCanceledException
cancellationTokenis canceled.
RenderCurrentViewToPngAsync(int, int, double, CancellationToken)
Renders the current live map view to PNG bytes without mutating the live navigator.
public Task<byte[]?> RenderCurrentViewToPngAsync(int widthPx, int heightPx, double pixelDensity, CancellationToken cancellationToken = default)
Parameters
widthPxintOutput width in pixels.
heightPxintOutput height in pixels.
pixelDensitydoubleOutput pixel-density multiplier.
cancellationTokenCancellationTokenOptional cancellation token.
Returns
Remarks
When the adapted control is a CaptureSynchronizedMapControl, the capture is serialized against the control's live paint so it never reads shared Skia/GPU resources mid-frame. Over a plain Mapsui map control there is no gate to synchronize against, so the capture runs best-effort: on a quiescent map it renders the current view, but it is not serialized against a concurrent live paint touching the shared render resources, so under active repaint the result can, in rare cases, be torn or partial. Hosts that capture under an actively repainting map should adapt a CaptureSynchronizedMapControl.
Exceptions
- ArgumentOutOfRangeException
An output dimension or
pixelDensityis not positive and finite.- ObjectDisposedException
The adapter is detached.
- OperationCanceledException
cancellationTokenis canceled.
RequestRedraw()
Schedules a live map redraw on Avalonia's UI thread.
public void RequestRedraw()
Exceptions
- ObjectDisposedException
The adapter is detached.
TryGetViewportSizePx()
Returns the laid-out live viewport size in pixels.
public (double Width, double Height)? TryGetViewportSizePx()
Returns
Exceptions
- ObjectDisposedException
The adapter is detached.
TryImagePixelToWgs84(double, double, int, int)
Converts a current-view snapshot pixel to WGS-84 using the same extent, fit, and rotation rules as RenderCurrentViewToPngAsync(int, int, double, CancellationToken).
public GeoPosition? TryImagePixelToWgs84(double xPx, double yPx, int imageWidthPx, int imageHeightPx)
Parameters
xPxdoubleHorizontal snapshot pixel coordinate.
yPxdoubleVertical snapshot pixel coordinate.
imageWidthPxintSnapshot width in pixels.
imageHeightPxintSnapshot height in pixels.
Returns
- GeoPosition?
The geographic position, or null for invalid input or an unlaid-out viewport.
Exceptions
- ObjectDisposedException
The adapter is detached.
TryScreenToWgs84(double, double)
Converts a live viewport pixel to WGS-84.
public GeoPosition? TryScreenToWgs84(double xPx, double yPx)
Parameters
xPxdoubleHorizontal live-control pixel coordinate.
yPxdoubleVertical live-control pixel coordinate.
Returns
- GeoPosition?
The geographic position, or null for invalid input or an unlaid-out viewport.
Exceptions
- ObjectDisposedException
The adapter is detached.