Skip to content

Commit 3379be7

Browse files
committed
fix: geojson type error
1 parent b8b77c2 commit 3379be7

File tree

5 files changed

+216
-3
lines changed

5 files changed

+216
-3
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ const users = geo.collection('users', ref =>
182182
const nearbyOnlineUsers = users.within(center, radius, field);
183183
```
184184

185+
### Usage with RxJS < 6.2, or Ionic v3
186+
187+
This package requires RxJS 6.2, but you can still use it with older versions without blowing up you app by installing rxjs-compat.
188+
189+
Example:
190+
191+
```shell
192+
npm i rxjs@latest rxjs-compat
193+
```
194+
185195
### Seeing this error: `DocumentReference.set() called with invalid data`
186196

187197
Firestore writes cannot use custom classes, so make sure to call the `data` getter on the point.

integration/src/app/realtime-geoquery/realtime-geoquery.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { switchMap, tap, map, take, finalize } from 'rxjs/operators';
44
import * as firebaseApp from 'firebase/app';
55
import * as geofirex from 'geofirex';
66
import { GeoFireCollectionRef } from 'geofirex';
7+
import { Point, Feature } from 'geojson';
78

89
@Component({
910
selector: 'app-realtime-geoquery',

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "geofirex",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "Realtime Firestore GeoQueries with RxJS",
55
"main": "dist/index.cjs.js",
66
"module": "dist/index.esm.js",

src/geohash.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { firestore } from './interfaces';
1+
import { firestore, Point, Feature } from './interfaces';
22

3-
import { Point, Feature } from 'geojson';
43
import { neighbors, encode, flip } from './util';
54

65
import distance from '@turf/distance';

src/interfaces.ts

+203
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,206 @@ export namespace firestore {
3030
firestore?(): types.FirebaseFirestore;
3131
}
3232
}
33+
34+
/// GEOJSON
35+
36+
// Type definitions for geojson 7946.0
37+
// Project: https://geojson.org/
38+
// Definitions by: Jacob Bruun <https://github.com/cobster>
39+
// Arne Schubert <https://github.com/atd-schubert>
40+
// Jeff Jacobson <https://github.com/JeffJacobson>
41+
// Ilia Choly <https://github.com/icholy>
42+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
43+
// TypeScript Version: 2.3
44+
45+
// Note: as of the RFC 7946 version of GeoJSON, Coordinate Reference Systems
46+
// are no longer supported. (See https://tools.ietf.org/html/rfc7946#appendix-B)}
47+
48+
/**
49+
* The valid values for the "type" property of GeoJSON geometry objects.
50+
* https://tools.ietf.org/html/rfc7946#section-1.4
51+
*/
52+
export type GeoJsonGeometryTypes =
53+
| 'Point'
54+
| 'LineString'
55+
| 'MultiPoint'
56+
| 'Polygon'
57+
| 'MultiLineString'
58+
| 'MultiPolygon'
59+
| 'GeometryCollection';
60+
61+
/**
62+
* The value values for the "type" property of GeoJSON Objects.
63+
* https://tools.ietf.org/html/rfc7946#section-1.4
64+
*/
65+
export type GeoJsonTypes =
66+
| 'FeatureCollection'
67+
| 'Feature'
68+
| GeoJsonGeometryTypes;
69+
70+
/**
71+
* Bounding box
72+
* https://tools.ietf.org/html/rfc7946#section-5
73+
*/
74+
export type BBox =
75+
| [number, number, number, number]
76+
| [number, number, number, number, number, number];
77+
78+
/**
79+
* A Position is an array of coordinates.
80+
* https://tools.ietf.org/html/rfc7946#section-3.1.1
81+
* Array should contain between two and three elements.
82+
* The previous GeoJSON specification allowed more elements (e.g., which could be used to represent M values),
83+
* but the current specification only allows X, Y, and (optionally) Z to be defined.
84+
*/
85+
export type Position = number[]; // [number, number] | [number, number, number];
86+
87+
/**
88+
* The base GeoJSON object.
89+
* https://tools.ietf.org/html/rfc7946#section-3
90+
* The GeoJSON specification also allows foreign members
91+
* (https://tools.ietf.org/html/rfc7946#section-6.1)
92+
* Developers should use "&" type in TypeScript or extend the interface
93+
* to add these foreign members.
94+
*/
95+
export interface GeoJsonObject {
96+
// Don't include foreign members directly into this type def.
97+
// in order to preserve type safety.
98+
// [key: string]: any;
99+
/**
100+
* Specifies the type of GeoJSON object.
101+
*/
102+
type: GeoJsonTypes;
103+
/**
104+
* Bounding box of the coordinate range of the object's Geometries, Features, or Feature Collections.
105+
* https://tools.ietf.org/html/rfc7946#section-5
106+
*/
107+
bbox?: BBox;
108+
}
109+
110+
/**
111+
* Union of GeoJSON objects.
112+
*/
113+
export type GeoJSON = Geometry | Feature | FeatureCollection;
114+
115+
/**
116+
* A geometry object.
117+
* https://tools.ietf.org/html/rfc7946#section-3
118+
*/
119+
export interface GeometryObject extends GeoJsonObject {
120+
type: GeoJsonGeometryTypes;
121+
}
122+
123+
/**
124+
* Union of geometry objects.
125+
* https://tools.ietf.org/html/rfc7946#section-3
126+
*/
127+
export type Geometry =
128+
| Point
129+
| MultiPoint
130+
| LineString
131+
| MultiLineString
132+
| Polygon
133+
| MultiPolygon
134+
| GeometryCollection;
135+
136+
/**
137+
* Point geometry object.
138+
* https://tools.ietf.org/html/rfc7946#section-3.1.2
139+
*/
140+
export interface Point extends GeometryObject {
141+
type: 'Point';
142+
coordinates: Position;
143+
}
144+
145+
/**
146+
* MultiPoint geometry object.
147+
* https://tools.ietf.org/html/rfc7946#section-3.1.3
148+
*/
149+
export interface MultiPoint extends GeometryObject {
150+
type: 'MultiPoint';
151+
coordinates: Position[];
152+
}
153+
154+
/**
155+
* LineString geometry object.
156+
* https://tools.ietf.org/html/rfc7946#section-3.1.4
157+
*/
158+
export interface LineString extends GeometryObject {
159+
type: 'LineString';
160+
coordinates: Position[];
161+
}
162+
163+
/**
164+
* MultiLineString geometry object.
165+
* https://tools.ietf.org/html/rfc7946#section-3.1.5
166+
*/
167+
export interface MultiLineString extends GeometryObject {
168+
type: 'MultiLineString';
169+
coordinates: Position[][];
170+
}
171+
172+
/**
173+
* Polygon geometry object.
174+
* https://tools.ietf.org/html/rfc7946#section-3.1.6
175+
*/
176+
export interface Polygon extends GeometryObject {
177+
type: 'Polygon';
178+
coordinates: Position[][];
179+
}
180+
181+
/**
182+
* MultiPolygon geometry object.
183+
* https://tools.ietf.org/html/rfc7946#section-3.1.7
184+
*/
185+
export interface MultiPolygon extends GeometryObject {
186+
type: 'MultiPolygon';
187+
coordinates: Position[][][];
188+
}
189+
190+
/**
191+
* Geometry Collection
192+
* https://tools.ietf.org/html/rfc7946#section-3.1.8
193+
*/
194+
export interface GeometryCollection extends GeometryObject {
195+
type: 'GeometryCollection';
196+
geometries: Geometry[];
197+
}
198+
199+
export type GeoJsonProperties = { [name: string]: any } | null;
200+
201+
/**
202+
* A feature object which contains a geometry and associated properties.
203+
* https://tools.ietf.org/html/rfc7946#section-3.2
204+
*/
205+
export interface Feature<
206+
G extends GeometryObject | null = Geometry,
207+
P = GeoJsonProperties
208+
> extends GeoJsonObject {
209+
type: 'Feature';
210+
/**
211+
* The feature's geometry
212+
*/
213+
geometry: G;
214+
/**
215+
* A value that uniquely identifies this feature in a
216+
* https://tools.ietf.org/html/rfc7946#section-3.2.
217+
*/
218+
id?: string | number;
219+
/**
220+
* Properties associated with this feature.
221+
*/
222+
properties: P;
223+
}
224+
225+
/**
226+
* A collection of feature objects.
227+
* https://tools.ietf.org/html/rfc7946#section-3.3
228+
*/
229+
export interface FeatureCollection<
230+
G extends GeometryObject | null = Geometry,
231+
P = GeoJsonProperties
232+
> extends GeoJsonObject {
233+
type: 'FeatureCollection';
234+
features: Array<Feature<G, P>>;
235+
}

0 commit comments

Comments
 (0)