You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Finally, create a new `GeospatialIndex` within your `convex/` folder, and point it to the installed component:
57
+
Finally, create a new `GeospatialIndex` within your `convex/` folder, and point
58
+
it to the installed component:
51
59
52
60
```ts
53
61
// convex/index.ts
@@ -59,9 +67,10 @@ const geospatial = new GeospatialIndex(components.geospatial);
59
67
60
68
## Inserting points
61
69
62
-
After installing the component, you can `insert`, `get`, and `remove` points from the index. You can specify
63
-
a `filterKeys` record for filtering at query time and optionally a `sortKey` for the query result order. We
64
-
currently only support ascending order on the `sortKey`.
70
+
After installing the component, you can `insert`, `get`, and `remove` points
71
+
from the index. You can specify a `filterKeys` record for filtering at query
72
+
time and optionally a `sortKey` for the query result order. We currently only
73
+
support ascending order on the `sortKey`.
65
74
66
75
```ts
67
76
// convex/index.ts
@@ -85,9 +94,11 @@ const example = mutation({
85
94
});
86
95
```
87
96
88
-
If you would like some more typesafety, you can specify a type argument for the `GeospatialIndex` class. This
89
-
will also provide you with auto-complete for the `filterKeys` and `sortKey` parameters.
90
-
Above the key was "American Museum of Natural History" but most commonly the `key` will be an ID in another table of yours.
97
+
If you would like some more typesafety, you can specify a type argument for the
98
+
`GeospatialIndex` class. This will also provide you with auto-complete for the
99
+
`filterKeys` and `sortKey` parameters. Above the key was "American Museum of
100
+
Natural History" but most commonly the `key` will be an ID in another table of
101
+
yours.
91
102
92
103
```ts
93
104
// convex/index.ts
@@ -125,13 +136,13 @@ const example = query({
125
136
});
126
137
```
127
138
128
-
This query will find all points that lie within the query rectangle, sort them in ascending
129
-
`sortKey` order, and return at most 16 results.
139
+
This query will find all points that lie within the query rectangle, sort them
140
+
in ascending `sortKey` order, and return at most 16 results.
130
141
131
142
You can optionally add filter conditions to queries.
132
143
133
-
The first type of filter condition is an `in()` filter, which requires that a matching
134
-
document have a filter field with a value in a specified set.
144
+
The first type of filter condition is an `in()` filter, which requires that a
145
+
matching document have a filter field with a value in a specified set.
135
146
136
147
```ts
137
148
// convex/index.ts
@@ -153,8 +164,8 @@ const example = query({
153
164
});
154
165
```
155
166
156
-
The second type of filter condition is an `eq()` filter, which requires that a matching
157
-
document have a filter field with a value equal to a specified value.
167
+
The second type of filter condition is an `eq()` filter, which requires that a
168
+
matching document have a filter field with a value equal to a specified value.
158
169
159
170
```ts
160
171
// convex/index.ts
@@ -170,7 +181,9 @@ const example = query({
170
181
});
171
182
```
172
183
173
-
The final type of filter condition allows you to specify ranges over the `sortKey`. We currently only support (optional) inclusive lower bounds and exclusive upper bounds.
184
+
The final type of filter condition allows you to specify ranges over the
185
+
`sortKey`. We currently only support (optional) inclusive lower bounds and
186
+
exclusive upper bounds.
174
187
175
188
```ts
176
189
// convex/index.ts
@@ -192,10 +205,13 @@ const example = query({
192
205
});
193
206
```
194
207
195
-
Queries take in a `limit`, which bounds the maximum number of rows returned. If this limit is hit,
196
-
the query will return a `nextCursor` for continuation. The query may also return a `nextCursor` with fewer than `limit` results if it runs out of its IO budget while executing.
208
+
Queries take in a `limit`, which bounds the maximum number of rows returned. If
209
+
this limit is hit, the query will return a `nextCursor` for continuation. The
210
+
query may also return a `nextCursor` with fewer than `limit` results if it runs
211
+
out of its IO budget while executing.
197
212
198
-
In either case, you can continue the stream by passing `nextCursor` to the next call's `cursor` parameter.
213
+
In either case, you can continue the stream by passing `nextCursor` to the next
214
+
call's `cursor` parameter.
199
215
200
216
```ts
201
217
// convex/index.ts
@@ -234,11 +250,13 @@ const example = query({
234
250
});
235
251
```
236
252
237
-
**Note: you typically pass the `nextCursor` in from a client that is paginating through results, to avoid loading too much data in a single query.**
253
+
**Note: you typically pass the `nextCursor` in from a client that is paginating
254
+
through results, to avoid loading too much data in a single query.**
238
255
239
256
## Querying the points nearest a query point
240
257
241
-
You can also query for the points closest to a given point, optionally limiting to a maximum distance (in meters).
258
+
You can also query for the points closest to a given point, optionally limiting
259
+
to a maximum distance (in meters).
242
260
243
261
```ts
244
262
// convex/index.ts
@@ -258,11 +276,13 @@ const example = query({
258
276
});
259
277
```
260
278
261
-
The `maxDistance` parameter is optional, but providing it can greatly speed up searching the index.
279
+
The `maxDistance` parameter is optional, but providing it can greatly speed up
280
+
searching the index.
262
281
263
282
## Example
264
283
265
-
See [`example/`](./example/) for a full example with a [Leaflet](https://leafletjs.com/)-based frontend.
284
+
See [`example/`](./example/) for a full example with a
285
+
[Leaflet](https://leafletjs.com/)-based frontend.
266
286
267
287
## Development
268
288
@@ -275,7 +295,8 @@ npm install
275
295
npm run dev
276
296
```
277
297
278
-
The component definition is in `src/` and reflects what users of the component will install. The example app,
279
-
which is entirely independent, lives in `example/`.
298
+
The component definition is in `src/` and reflects what users of the component
299
+
will install. The example app, which is entirely independent, lives in
300
+
`example/`.
280
301
281
302
<!-- END: Include on https://convex.dev/components -->
0 commit comments