LuciadRIA can convert coordinates of objects such as points from one coordinate reference system to another.
To perform such a conversion, you first need to create a Transformation object using the factory methods in the TransformationFactory module.
You can use a Transformation instance to transform Point and Bounds objects from a source reference to a destination reference.
Program: Transforming points between georeferences shows a controller that uses transformations to determine the coordinates under the mouse pointer.
The code creates a transformation from the map’s CoordinateReference, which typically expresses coordinates in meters, to WGS84, which expresses coordinates in longitude and latitude degrees.
Together with the transformation, it creates points that hold transformation results.
When the mouse moves over the map, the controller receives a GestureEvent of type MOVE.
The event’s viewPoint holds the location of the mouse pointer in view coordinates: pixels relative to the upper left corner of the map.
By calling transform() on the transformation returned by the RIAMap's getViewToMapTransformation(), you transform those view coordinates to coordinates on the map.
At this point, _mapPoint has the location on the map in meters.
To know the location in longitude/latitude degrees, you pass _mapPoint to the transform() method of the created transformation.
The location on the globe under the mouse pointer is available in _modelPoint.
|
Use the view coordinates of a |
class MouseLocationController extends Controller {
private readonly _mapToModel = createTransformation(map.reference, getReference("CRS:84"));
private readonly _mapPoint = createPoint(map.reference, []);
private readonly _modelPoint = createPoint(getReference("CRS:84"), []);
constructor() {
super();
}
onGestureEvent(event: GestureEvent): HandleEventResult {
if (event.type === GestureEventType.MOVE && this.map) {
try {
this.map.getViewToMapTransformation(LocationMode.TERRAIN).transform(event.viewPoint, this._mapPoint);
this._mapToModel.transform(this._mapPoint, this._modelPoint);
console.log(`lon: ${this._modelPoint.x}, lat: ${this._modelPoint.y}`);
} catch (e) {
if (!(e instanceof OutOfBoundsError)) {
throw e;
}
// the mouse pointer is not on the earth's surface
}
}
return HandleEventResult.EVENT_IGNORED;
}
}
|
On a 3D map, the The |
|
In a 2D map, the |
Advanced control of view to map transformation
On a 3D map, you can obtain a view-to-world point transformation with RIAMap.getViewToMapTransformation() API.
This function creates a Transformation object that you can use to transform a view position to a corresponding world (map) position in 3D scenes. It’s based on
a mechanism defined by a LocationMode parameter:
-
LocationMode.TERRAIN- This transformation yields a world point position on the terrain. -
LocationMode.ELLIPSOID- This transformation yields a world point position on the ellipsoid of the map reference. -
LocationMode.CLOSEST_SURFACE- This transformation yields a world point position corresponding to the visible object at the view location closest to the viewer, from the camera view point. The closest 3D object can be represented by 3D meshes, point clouds, extruded shapes, 3D icons or the terrain.
|
In 2D space, LuciadRIA ignores the |