Class MapFollowMath
Pure geometry for offsetting a followed target away from view center.
public static class MapFollowMath
- Inheritance
-
objectMapFollowMath
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
targetLatLonGeographic position to place off-center.
offsetXPxdoubleScreen offset right of center, in the same view-pixel frame
BaseMapView.LatLonToScreenreturns (origin bottom left, Y up). Zero keepstargetcentered.offsetYPxdoubleScreen offset up from center, same frame as
offsetXPx. A negative value putstargetlow on screen, like a navigation app.templateMapViewStateZoom, rotation and pitch to build the view with; its own center is ignored.
screenScreenSizeViewport size in screen px.
tileSizePxintTile edge length in px; 256 or 512.
screenPixelScaledoubleThe 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, projectstargetto the requested offset. Equal totargetitself 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
headingDegdoubleCompass heading, degrees, 0 = north, 90 = east.
offsetDegdoubleExtra 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
currentXdoubleCurrent smoothed X, normalized mercator.
targetXdoubleRaw target X, normalized mercator, in [0, 1).
Returns
- double
A value equal to
targetXmodulo 1, chosen so a smoother stepping fromcurrentXtoward it crosses the antimeridian rather than sweeping across the whole map when the two are on opposite sides of the 0/1 seam.