Table of Contents

Class AvaloniaMapsuiMapAdapter

Namespace
EncDotNet.S100.Renderers.Mapsui.Avalonia
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

double

Methods

Attach(MapControl)

Attaches an adapter to an initialized live map control.

public static AvaloniaMapsuiMapAdapter Attach(MapControl mapControl)

Parameters

mapControl MapControl

The 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

mapControl is 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

query IS100MapQuery

The session query surface to pick against.

xPx double

Horizontal live-control pixel coordinate.

yPx double

Vertical live-control pixel coordinate.

radiusMeters double

Point/curve tolerance in metres; defaults to DefaultPickRadiusMeters.

maxResults int?

Optional cap on the returned picks (topmost-first).

cancellationToken CancellationToken

Optional 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

query is null.

ObjectDisposedException

The adapter is detached.

OperationCanceledException

cancellationToken is 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

widthPx int

Output width in pixels.

heightPx int

Output height in pixels.

pixelDensity double

Output pixel-density multiplier.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<byte[]>

PNG bytes, or null when the live viewport is not laid out.

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 pixelDensity is not positive and finite.

ObjectDisposedException

The adapter is detached.

OperationCanceledException

cancellationToken is 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

(double Width, double Height)?

Width and height, or null when the viewport is not laid out.

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

xPx double

Horizontal snapshot pixel coordinate.

yPx double

Vertical snapshot pixel coordinate.

imageWidthPx int

Snapshot width in pixels.

imageHeightPx int

Snapshot 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

xPx double

Horizontal live-control pixel coordinate.

yPx double

Vertical 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.