In some cases, you may want to find out what the lon-lat coordinates of a map position are, the coordinates for the map position
of a mouse cursor for instance.
For a Lightspeed view, you can calculate this lon-lat position by using ALspViewXYZWorldTransformation
or ILspTerrainSupport
, depending on the use case:
-
ALspViewXYZWorldTransformation
provides the methodtoolkitPoint2WorldSFCT
which calculates the location in world coordinates of the given view point. The world point then needs to be converted to lon-lat coordinates. It is possible to tweak the calculation by supplying aLocationMode
parameter set to one of two location modes:-
ELLIPSOID.
The coordinates of the result are calculated on the ellipsoid of the geodetic datum of the view’s world reference. -
CLOSEST_SURFACE.
The resulting point will be on the surface that is closest to the viewer. In other words, the returned coordinates may be on the surface of a domain object, if one is under the specified view coordinates.
-
-
ILspTerrainSupport
provides the methodgetPointOnTerrain
which returns the front-most point on the terrain which projects to the same view coordinates. This is useful, for example, to query the terrain under the mouse cursor. The result also needs to be converted to lon-lat coordinates.
Note that toolkitPoint2WorldSFCT
takes a point in "toolkit" coordinates as input, whereas getPointOnTerrain()
takes a point in view coordinates.
If DPI scaling is enabled in the host operating system, toolkit coordinates are
different from Lightspeed view coordinates. See
Support high-resolution displays on a Lightspeed map
for more information on this distinction and how to deal with it in your application code.
Program: A component that displays the model coordinates of the mouse cursor shows a snippet of a component that displays the lon-lat coordinates of the mouse cursor. It does this by transforming mouse
locations to world coordinates using the getPointOnTerrain
method. The world coordinates are then converted to lon-lat coordinates.
samples/lightspeed/common/MouseReadoutProvider
)
@Override
public ILcdPoint retrieveMouseReadout(ILcdPoint aPoint2D, ILcdModelReference aModelReference) throws TLcdOutOfBoundsException {
// calculate DPI scale value if applicable
double dpiScale = fView.getDPIScale();
ILcdPoint worldPoint = fView.getServices().getTerrainSupport().getPointOnTerrain(
new TLcdXYPoint(aPoint2D.getX() * dpiScale, aPoint2D.getY() * dpiScale), new TLspContext(null, fView));
if (worldPoint == null) {
return null;
}
TLcdXYZPoint modelPoint = new TLcdXYZPoint();
TLcdDefaultModelXYZWorldTransformation transformation = new TLcdDefaultModelXYZWorldTransformation();
transformation.setXYZWorldReference(fView.getXYZWorldReference());
transformation.setModelReference(aModelReference);
transformation.worldPoint2modelSFCT(worldPoint, modelPoint);
return modelPoint;
}
|