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:
-
ALspViewXYZWorldTransformationprovides the methodtoolkitPoint2WorldSFCTwhich 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 aLocationModeparameter 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.
-
-
ILspTerrainSupportprovides the methodgetPointOnTerrainwhich 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(Point aToolkitPoint, ILcdModelReference aModelReference) throws TLcdOutOfBoundsException {
TLcdXYZPoint viewPoint = new TLcdXYZPoint();
fView.getViewXYZWorldTransformation().toolkitPoint2ViewSFCT(aToolkitPoint, viewPoint);
ILcdPoint worldPoint = fView.getServices().getTerrainSupport().getPointOnTerrain(viewPoint, 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;
}
|
|