To display the mouse cursor position on the map, you first need to find out what the lon-lat coordinates of the map position
of the mouse cursor are.
In LuciadLightspeed, you can calculate this lon-lat position by first using ILcdGXYViewXYWorldTransformation
. It transforms view coordinates to world coordinates.
Next, you convert the world point to lon-lat coordinates. You can use TLcdDefaultModelXYWorldTransformation
for that.
All this is shown in Program: A component that displays the model coordinates of the mouse cursor.
Program: A component that displays the model coordinates of the mouse cursor (from
samples/gxy/common/MouseLocationComponent
)
@Override
public ILcdPoint retrieveMouseReadout(ILcdPoint aAWTPoint, ILcdModelReference aReference) throws TLcdOutOfBoundsException {
TLcdXYPoint worldPoint = new TLcdXYPoint();
ILcd3DEditablePoint modelPoint = aReference.makeModelPoint().cloneAs3DEditablePoint();
fView.getGXYViewXYWorldTransformation().viewAWTPoint2worldSFCT(new Point((int) aAWTPoint.getX(), (int) aAWTPoint.getY()), worldPoint);
TLcdDefaultModelXYWorldTransformation transformation = new TLcdDefaultModelXYWorldTransformation(
aReference,
fView.getXYWorldReference()
);
transformation.worldPoint2modelSFCT(worldPoint, modelPoint);
return modelPoint;
}
}