Appearance
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): LatLngPointParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| lng | number | string | 0 | Longitude value (-180 to 180) |
| lat | number | string | 0 | Latitude value (-90 to 90) |
| alt | number | string | 0 | Altitude value in meters |
Properties
| Property | Type | Description |
|---|---|---|
| lng | number | Longitude value (-180 to 180) |
| lat | number | Latitude value (-90 to 90) |
| alt | number | Altitude value in meters |
Instance Methods
| Method | Parameters | Return Value | Description |
|---|---|---|---|
| clone | () | LatLngPoint | Create a copy of this point |
| format | () | this | Format coordinates to specified decimal places |
| toArray | (noAlt?: boolean) | number[] | Convert to array [lng, lat, alt] or [lng, lat] |
| toString | () | string | Convert to string "lng,lat,alt" |
| toCartesian | (clone?: boolean) | Cesium.Cartesian3 | Convert to Cesium Cartesian3 coordinates |
| toCartographic | () | Cesium.Cartographic | Convert to Cesium Cartographic coordinates |
| toMercator | () | number[] | Convert to Mercator projection coordinates |
| equals | (other: LatLngPoint) | boolean | Check if two points are equal |
| valid | () | boolean | Check if coordinates are valid |
Static Methods
| Method | Parameters | Return Value | Description |
|---|---|---|---|
| parse | (position: any, time?: any) | LatLngPoint | Parse various input types to LatLngPoint |
| fromArray | (array: number[]) | LatLngPoint | Create from array [lng, lat, alt] |
| fromString | (string: string) | LatLngPoint | Create from comma-separated string |
| fromCartesian | (cartesian: Cesium.Cartesian3, time?: any) | LatLngPoint | Create from Cesium Cartesian3 |
| fromCartographic | (cartographic: Cesium.Cartographic) | LatLngPoint | Create from Cesium Cartographic |
| fromMercator | (mercator: number[]) | LatLngPoint | Create from Mercator projection coordinates |
| toCartesian | (input: any, defaultValue?: any) | Cesium.Cartesian3 | Convert input to Cartesian3 |
| toCartographic | (input: any, defaultValue?: any) | Cesium.Cartographic | Convert 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
- All coordinate values are automatically converted to numbers
- Longitude range: -180 to 180 degrees
- Latitude range: -90 to 90 degrees
- Altitude is in meters above sea level
- The
format()method rounds coordinates to 8 decimal places for lat/lng and 6 for altitude - Static methods provide flexible input parsing for various data formats
- Coordinate validation ensures values are within valid ranges
- Caching is used for Cartesian3 conversion to improve performance