-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
geographyPoint.ts
39 lines (35 loc) · 1018 Bytes
/
geographyPoint.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const WorldGeodeticSystem1984 = "EPSG:4326"; // See https://epsg.io/4326
/**
* Represents a geographic point in global coordinates.
*/
export default class GeographyPoint {
/**
* The latitude in decimal.
*/
public latitude: number;
/**
* The longitude in decimal.
*/
public longitude: number;
/**
* Constructs a new instance of GeographyPoint given
* the specified coordinates.
* @param geographyPoint - object with longitude and latitude values in decimal
*/
constructor(geographyPoint: { longitude: number; latitude: number }) {
this.longitude = geographyPoint.longitude;
this.latitude = geographyPoint.latitude;
}
/**
* Used to serialize to a GeoJSON Point.
*/
public toJSON(): Record<string, unknown> {
return {
type: "Point",
coordinates: [this.longitude, this.latitude],
crs: { type: "name", properties: { name: WorldGeodeticSystem1984 } }
};
}
}