Table of Contents

Class MapFollowMath

Namespace
LansMap.Core.Control

Pure geometry for offsetting a followed target away from view center.

public static class MapFollowMath
Inheritance
object
MapFollowMath

Methods

CenterForOffsetTarget(LatLon, double, double, MapViewState, ScreenSize, int, double)

The view center that puts target at (offsetXPx, offsetYPx) from the view center, for template's zoom, rotation and pitch.

public static LatLon CenterForOffsetTarget(LatLon target, double offsetXPx, double offsetYPx, MapViewState template, ScreenSize screen, int tileSizePx, double screenPixelScale)

Parameters

target LatLon

Geographic position to place off-center.

offsetXPx double

Screen offset right of center, in the same view-pixel frame BaseMapView.LatLonToScreen returns (origin bottom left, Y up). Zero keeps target centered.

offsetYPx double

Screen offset up from center, same frame as offsetXPx. A negative value puts target low on screen, like a navigation app.

template MapViewState

Zoom, rotation and pitch to build the view with; its own center is ignored.

screen ScreenSize

Viewport size in screen px.

tileSizePx int

Tile edge length in px; 256 or 512.

screenPixelScale double

The live view's ScreenPixelScale; 1 in the editor.

Returns

LatLon

The view center that, built into a MapViewTransform with template's zoom/rotation/pitch and the same screen, projects target to the requested offset. Equal to target itself when both offsets are zero.

Remarks

Unprojects the requested on-screen spot in a view centered on target, then reflects that point through the view's own center: a point's projection depends only on its mercator delta from the view center, so the target's delta from the reflected center equals the point's delta negated, landing at the requested screen spot under any rotation or pitch. With an elevation sampler active, the live LatLonToScreen adds terrain parallax this flat-ground solve does not, the same approximation the other inverse paths make.

HeadingUpRotationDeg(double, double)

Map rotation that puts a target's heading up the screen.

public static double HeadingUpRotationDeg(double headingDeg, double offsetDeg)

Parameters

headingDeg double

Compass heading, degrees, 0 = north, 90 = east.

offsetDeg double

Extra rotation added on top, degrees.

Returns

double

A RotationDeg value in [0, 360). Map rotation is counterclockwise and heading is clockwise, so the two share a sign: heading 90 (east) needs rotation 90, which turns the map until east points up.

WrapTowardX(double, double)

Moves targetX by whole worlds to sit within half a world of currentX.

public static double WrapTowardX(double currentX, double targetX)

Parameters

currentX double

Current smoothed X, normalized mercator.

targetX double

Raw target X, normalized mercator, in [0, 1).

Returns

double

A value equal to targetX modulo 1, chosen so a smoother stepping from currentX toward it crosses the antimeridian rather than sweeping across the whole map when the two are on opposite sides of the 0/1 seam.