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 how the MouseLocationComponent, which displays the coordinates under the mouse pointer on the screen, uses transformations. The code creates a transformation from the map’s CoordinateReference, which typically 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, it creates points that hold transformation results.

When the mouse moves on the screen, event objects with location of the mouse in the browser window are passed to the MouseLocationComponent. With this location, you can calculate the location of the mouse pointer on the map. By calling transform() on the Map’s viewtoMapTransformation, you transform the view coordinates, stored in this._tempViewPoint, to coordinates on the map . At this point, this._tempMapPoint has the location on the map in meters. To know the location in latitude/longitude degrees, you pass this._tempMapPoint to the transform() method of the created transformation. The location on the globe under the mouse pointer is available in this._tempModelPoint.

Program: Transforming points between georeferences (from samples/common/hooks/useMouseCoordinate.ts)
tempViewPoint.move2D(
    event.clientX - mapNodePosition.left,
    event.clientY - mapNodePosition.top
);
map.getViewToMapTransformation(LocationMode.TERRAIN).transform(tempViewPoint, tempMapPoint);

map2Model.transform(tempMapPoint, tempModelPoint);

On a 3D map, the viewToMapTransformation determines a world point on the terrain at the input view coordinate. If the view coordinate doesn’t touch the terrain, the transformation throws an OutOfBoundsError. The world point is determined by intersecting terrain triangles, so its accuracy depends on the elevation data visible in the view at that point.

The mapToViewTransformation also throws an OutOfBoundsError when the input world coordinate isn’t visible in the current view. This happens when terrain obscures the world coordinate, or on the back-facing side of the globe.

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

Advanced control of view to map transformation

On a 3D map, you can obtain a view-to-world point transformation with Map.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 LocationMode parameter. The returned Transformation object is the same as the one you get from Map.viewToMapTransformation.