Skip to content

LatLngPoint (Geographic Point)

Represents a geographic point with longitude, latitude, and altitude coordinates.

Constructor

ts
new ge3d.LatLngPoint(lng?: number | string, lat?: number | string, alt?: number | string): LatLngPoint

Parameters

ParameterTypeDefaultDescription
lngnumber | string0Longitude value (-180 to 180)
latnumber | string0Latitude value (-90 to 90)
altnumber | string0Altitude value in meters

Properties

PropertyTypeDescription
lngnumberLongitude value (-180 to 180)
latnumberLatitude value (-90 to 90)
altnumberAltitude value in meters

Instance Methods

MethodParametersReturn ValueDescription
clone()LatLngPointCreate a copy of this point
format()thisFormat coordinates to specified decimal places
toArray(noAlt?: boolean)number[]Convert to array [lng, lat, alt] or [lng, lat]
toString()stringConvert to string "lng,lat,alt"
toCartesian(clone?: boolean)Cesium.Cartesian3Convert to Cesium Cartesian3 coordinates
toCartographic()Cesium.CartographicConvert to Cesium Cartographic coordinates
toMercator()number[]Convert to Mercator projection coordinates
equals(other: LatLngPoint)booleanCheck if two points are equal
valid()booleanCheck if coordinates are valid

Static Methods

MethodParametersReturn ValueDescription
parse(position: any, time?: any)LatLngPointParse various input types to LatLngPoint
fromArray(array: number[])LatLngPointCreate from array [lng, lat, alt]
fromString(string: string)LatLngPointCreate from comma-separated string
fromCartesian(cartesian: Cesium.Cartesian3, time?: any)LatLngPointCreate from Cesium Cartesian3
fromCartographic(cartographic: Cesium.Cartographic)LatLngPointCreate from Cesium Cartographic
fromMercator(mercator: number[])LatLngPointCreate from Mercator projection coordinates
toCartesian(input: any, defaultValue?: any)Cesium.Cartesian3Convert input to Cartesian3
toCartographic(input: any, defaultValue?: any)Cesium.CartographicConvert input to Cartographic
toArray(input: any, noAlt?: boolean)number[]Convert input to array

Usage Examples

Basic Usage

javascript
// Create a point with coordinates
const point = new ge3d.LatLngPoint(116.3975, 39.9087, 100);

// Access properties
console.log(point.lng); // 116.3975
console.log(point.lat); // 39.9087
console.log(point.alt); // 100

// Modify coordinates
point.lng = 120.0;
point.lat = 40.0;
point.alt = 200;

Creating from Different Sources

javascript
// From array
const point1 = ge3d.LatLngPoint.fromArray([116.3975, 39.9087, 100]);

// From string
const point2 = ge3d.LatLngPoint.fromString("116.3975,39.9087,100");

// From Cesium Cartesian3
const cartesian = Cesium.Cartesian3.fromDegrees(116.3975, 39.9087, 100);
const point3 = ge3d.LatLngPoint.fromCartesian(cartesian);

// From Cesium Cartographic
const cartographic = Cesium.Cartographic.fromDegrees(116.3975, 39.9087, 100);
const point4 = ge3d.LatLngPoint.fromCartographic(cartographic);

// Parse any input type
const point5 = ge3d.LatLngPoint.parse({
  lng: 116.3975,
  lat: 39.9087,
  alt: 100
});

Converting to Different Formats

javascript
const point = new ge3d.LatLngPoint(116.3975, 39.9087, 100);

// Convert to array
const array = point.toArray(); // [116.3975, 39.9087, 100]
const array2D = point.toArray(true); // [116.3975, 39.9087]

// Convert to string
const str = point.toString(); // "116.3975,39.9087,100"

// Convert to Cesium coordinates
const cartesian = point.toCartesian();
const cartographic = point.toCartographic();

// Convert to object
const obj = point.toObject(); // { lng: 116.3975, lat: 39.9087, alt: 100 }

Working with Map Events

javascript
// Listen to map click events
core.addEventListener(ge3d.EventType.click, (event) => {
  // Convert click position to LatLngPoint
  const point = ge3d.LatLngPoint.fromCartesian(event.cartesian);
  console.log('Clicked at:', point.toString());
  
  // Use the point for other operations
  const cartesian = point.toCartesian();
  core.flyToPoint(cartesian);
});

Validation and Comparison

javascript
const point1 = new ge3d.LatLngPoint(116.3975, 39.9087, 100);
const point2 = new ge3d.LatLngPoint(116.3975, 39.9087, 100);

// Check if coordinates are valid
if (point1.valid()) {
  console.log('Valid coordinates');
}

// Compare two points
if (point1.equals(point2)) {
  console.log('Points are equal');
}

// Clone a point
const clonedPoint = point1.clone();

Coordinate Systems

LatLngPoint supports conversion between different coordinate systems:

  • Geographic (WGS84): Longitude, latitude, altitude
  • Cartesian3: 3D Cartesian coordinates in Cesium
  • Cartographic: Cesium's geographic representation
  • Mercator: Mercator projection coordinates

Notes

  1. All coordinate values are automatically converted to numbers
  2. Longitude range: -180 to 180 degrees
  3. Latitude range: -90 to 90 degrees
  4. Altitude is in meters above sea level
  5. The format() method rounds coordinates to 8 decimal places for lat/lng and 6 for altitude
  6. Static methods provide flexible input parsing for various data formats
  7. Coordinate validation ensures values are within valid ranges
  8. Caching is used for Cartesian3 conversion to improve performance