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.

A Transformation instance can be used to transform Point and Bounds objects from a source reference to a destination reference.

Program: Transforming points between georeferences shows how transformations are used in the MouseLocationComponent, which displays the coordinates under the mouse pointer on the screen. A transformation is created from the map’s CoordinateReference, which usually expresses coordinates in meters, to an arbitrary output CoordinateReference. The output CoordinateReference defaults to WGS84, which expresses coordinates in latitude and longitude degrees. Together with the transformation, a number of points are created that will hold transformation results.

When the mouse is moved on the screen, event objects that contain the location of the mouse in the browser window are passed to the MouseLocationComponent. This location allows us to calculate the location of the mouse pointer on the map. These view coordinates (stored in this._tempViewPoint) are transformed to coordinates on the map by calling transform() on the Map’s viewtoMapTransformation. At this point, this._tempMapPoint contains the location on the map in meters. To know them in latitude/longitude degrees, this._tempMapPoint is passed to the transform() method of the transformation we created. The location on the globe under the mouse pointer is available in this._tempModelPoint.

Program: Transforming points between georeferences (from samples/common/mouseLocation/MouseLocationComponent.js)
//transform points from view coordinates (in pixels) to map coordinates (in meters)
this._tempViewPoint.move2D(
  event.clientX - this._mapNodePosition.left,
  event.clientY - this._mapNodePosition.top
);
this._map.viewToMapTransformation.transform(this._tempViewPoint, this._tempMapPoint);
//transform the point in map coordinates to the output reference (latitude/longitude)
this._transformation.transform(this._tempMapPoint, this._tempModelPoint);

On a 3D map, the viewToMapTransformation will determine a world point on the terrain at the input view coordinate. If the view coordinate does not touch the terrain, the transformation will throw an OutOfBoundsError. The world point is determined by intersecting terrain triangles, so its accuracy depends on the elevation data currently visible in the view.

In addition, the mapToViewTransformation will throw an OutOfBoundsError when the input world coordinate is not visible in the current view. This happens when the world coordinate is obscured by terrain or on the back-facing side of the globe.

In a 2D map, the viewToMapTransformation will never include height information in the resulting world point, even if you have an elevation layer in your map.