-
Notifications
You must be signed in to change notification settings - Fork 1
/
GlobeCoordinateSnak.ts
91 lines (81 loc) · 2.77 KB
/
GlobeCoordinateSnak.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { GlobeCoordinateSnak as WikidataGlobeCoordinateSnak } from '@wmde/wikibase-datamodel-types';
import Snak from '../Snak';
import normalizeOutput from '../utils/normalizeOutput';
/**
* class for the GlobeCoordinateSnak
*
* most used property of this type P625 (coordinate location)
*
* @class
*/
export default class GlobeCoordinateSnak extends Snak {
/** the latitude of the Coordinate */
latitude: number | undefined;
/** the longitude of the Coordinate */
longitude: number | undefined;
/** the altitude of the Coordinate */
altitude: null | undefined;
/** the precision of the Coordinate */
precision: number | undefined;
/**
* the "globe" that this coordinate refers to.
* Globe defaults to "Earth" (globe: http://www.wikidata.org/entity/Q2)
*/
globe: string | undefined;
datatype = 'globe-coordinate';
/**
* @param {WikidataGlobeCoordinateSnak} snak the snak for this class in json format
* @example
* const snak = new GlobeCoordinateSnak(json);
*/
constructor(snak: WikidataGlobeCoordinateSnak) {
super(snak);
this.latitude = snak.datavalue?.value.latitude;
this.longitude = snak.datavalue?.value.longitude;
this.altitude = snak.datavalue?.value.altitude;
this.precision = snak.datavalue?.value.precision;
this.globe = snak.datavalue?.value.globe;
}
/**
*
* @returns {WikidataGlobeCoordinateSnak} the snak as json
* @example
* const json = coordinateSnak.toJson();
*/
toJSON(): WikidataGlobeCoordinateSnak {
return normalizeOutput({
snaktype: this.snaktype,
property: this.property,
hash: this.hash,
datavalue: this.hasValue ? {
value: {
latitude: this.latitude,
longitude: this.longitude,
altitude: this.altitude,
precision: this.precision,
globe: this.globe
},
type: 'globecoordinate' as const
} : undefined,
datatype: this.datatype
}) as WikidataGlobeCoordinateSnak;
}
/**
* this function checks if two snaks are equal
*
* @param {GlobeCoordinateSnak} other the other snak
* @returns {boolean} true if the snaks are equal
* @example
* if (snak.equals(other)) {
* // do something
* }
*/
equals(other: GlobeCoordinateSnak): boolean {
return this.latitude === other.latitude
&& this.longitude === other.longitude
&& this.altitude === other.altitude
&& this.precision === other.precision
&& this.globe === other.globe
&& this.property === other.property;
}
}