1 | import { Where } from "./query";
|
2 |
|
3 | export function nearFilter(where: Where): false | GeoPointFilter[];
|
4 |
|
5 | export function filter(rawResults: GeoPointRawResult[], filters: GeoPointFilter[]): GeoPointFilter;
|
6 |
|
7 | export type GeoPointFilter = {
|
8 | near: GeoPoint | ConstructorParameters<typeof GeoPoint>;
|
9 | maxDistance: number;
|
10 | minDistance: number;
|
11 | unit: GeoDistanceUnit;
|
12 | mongoKey: string;
|
13 | key: string;
|
14 | }
|
15 |
|
16 | export type GeoPointRawResult = {
|
17 | [key: string]: {
|
18 | lat: number;
|
19 | lng: number;
|
20 | }
|
21 | }
|
22 |
|
23 | export class GeoPoint {
|
24 | lat: number;
|
25 | lng: number;
|
26 |
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | constructor(data: {
|
48 | lat: string | number,
|
49 | lng: string | number,
|
50 | })
|
51 |
|
52 | /**
|
53 | * @example
|
54 | * ```typescript
|
55 | * new GeoPoint('145,96');
|
56 | * ```
|
57 | *
|
58 | * @example
|
59 | * ```typescript
|
60 | * new GeoPoint('145 , 96');
|
61 | * ```
|
62 | *
|
63 | * @param data
|
64 | */
|
65 | constructor(data: `${number},${number}`)
|
66 |
|
67 | /**
|
68 | * @example
|
69 | * ```typescript
|
70 | * new GeoPoint([145, 96]);
|
71 | * ```
|
72 | *
|
73 | * @example
|
74 | * ```typescript
|
75 | * new GeoPoint(['145', '96']);
|
76 | * ```
|
77 | *
|
78 | * @param data
|
79 | */
|
80 | constructor(data: [string | number, string | number])
|
81 |
|
82 | /**
|
83 | * @example
|
84 | * ```typescript
|
85 | * new GeoPoint(145, 96);
|
86 | * ```
|
87 | *
|
88 | * @example
|
89 | * ```typescript
|
90 | * new GeoPoint('145', '96');
|
91 | * ```
|
92 | *
|
93 | * @param data
|
94 | */
|
95 | constructor(lat: string | number, lng: string | number)
|
96 |
|
97 | static distanceBetwen(
|
98 | a: GeoPoint | ConstructorParameters<typeof GeoPoint>,
|
99 | b: GeoPoint | ConstructorParameters<typeof GeoPoint>,
|
100 | options?: GeoDistanceOptions,
|
101 | ): number;
|
102 |
|
103 | distanceTo(
|
104 | point: GeoPoint | ConstructorParameters<typeof GeoPoint>,
|
105 | options?: GeoDistanceOptions,
|
106 | ): number;
|
107 |
|
108 | toString(): `$${number},${number}`;
|
109 | }
|
110 |
|
111 | export type GeoDistanceOptions = {
|
112 | type: GeoDistanceUnit;
|
113 | }
|
114 |
|
115 | export enum GeoDistanceUnit {
|
116 | 'kilometers',
|
117 | 'meters',
|
118 | 'miles',
|
119 | 'feet',
|
120 | 'radians',
|
121 | 'degrees',
|
122 | }
|