rendezvous-kit 0.0.0-development
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +184 -0
- package/dist/engines/graphhopper.d.ts +14 -0
- package/dist/engines/graphhopper.d.ts.map +1 -0
- package/dist/engines/graphhopper.js +72 -0
- package/dist/engines/graphhopper.js.map +1 -0
- package/dist/engines/openrouteservice.d.ts +14 -0
- package/dist/engines/openrouteservice.d.ts.map +1 -0
- package/dist/engines/openrouteservice.js +79 -0
- package/dist/engines/openrouteservice.js.map +1 -0
- package/dist/engines/osrm.d.ts +11 -0
- package/dist/engines/osrm.d.ts.map +1 -0
- package/dist/engines/osrm.js +48 -0
- package/dist/engines/osrm.js.map +1 -0
- package/dist/engines/valhalla.d.ts +11 -0
- package/dist/engines/valhalla.d.ts.map +1 -0
- package/dist/engines/valhalla.js +72 -0
- package/dist/engines/valhalla.js.map +1 -0
- package/dist/geo.d.ts +16 -0
- package/dist/geo.d.ts.map +1 -0
- package/dist/geo.js +142 -0
- package/dist/geo.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/rendezvous.d.ts +14 -0
- package/dist/rendezvous.d.ts.map +1 -0
- package/dist/rendezvous.js +72 -0
- package/dist/rendezvous.js.map +1 -0
- package/dist/types.d.ts +73 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/venues.d.ts +7 -0
- package/dist/venues.d.ts.map +1 -0
- package/dist/venues.js +74 -0
- package/dist/venues.js.map +1 -0
- package/llms-full.txt +481 -0
- package/llms.txt +86 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TheCryptoDonkey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# rendezvous-kit
|
|
2
|
+
|
|
3
|
+
**Find fair meeting points for N people — isochrone intersection, venue search, and fairness scoring.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/rendezvous-kit)
|
|
6
|
+
[](https://github.com/TheCryptoDonkey/rendezvous-kit/blob/main/LICENSE)
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Why rendezvous-kit?
|
|
10
|
+
|
|
11
|
+
- **Full pipeline** — isochrone computation → polygon intersection → venue search → fairness scoring, all in one library
|
|
12
|
+
- **Engine-agnostic** — bring your own routing engine: Valhalla, OpenRouteService, GraphHopper, or OSRM
|
|
13
|
+
- **Fairness strategies** — `min_max` (minimise worst case), `min_total` (minimise sum), `min_variance` (equalise travel times)
|
|
14
|
+
- **Built on geohash-kit** — leverages our spatial primitives; only runtime dependency
|
|
15
|
+
- **Zero third-party dependencies** — ships with a pure-TypeScript Sutherland–Hodgman polygon intersection, Overpass API venue search, and all engine adapters
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install rendezvous-kit
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { findRendezvous } from 'rendezvous-kit'
|
|
27
|
+
import { ValhallaEngine } from 'rendezvous-kit/engines/valhalla'
|
|
28
|
+
|
|
29
|
+
const engine = new ValhallaEngine({ baseUrl: 'http://localhost:8002' })
|
|
30
|
+
|
|
31
|
+
const suggestions = await findRendezvous(engine, {
|
|
32
|
+
participants: [
|
|
33
|
+
{ lat: 51.5074, lon: -0.1278, label: 'Alice' }, // London
|
|
34
|
+
{ lat: 51.4545, lon: -2.5879, label: 'Bob' }, // Bristol
|
|
35
|
+
{ lat: 52.4862, lon: -1.8904, label: 'Carol' }, // Birmingham
|
|
36
|
+
],
|
|
37
|
+
mode: 'drive',
|
|
38
|
+
maxTimeMinutes: 90,
|
|
39
|
+
venueTypes: ['cafe', 'restaurant'],
|
|
40
|
+
fairness: 'min_max',
|
|
41
|
+
limit: 5,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
for (const s of suggestions) {
|
|
45
|
+
console.log(`${s.venue.name} — score: ${s.fairnessScore.toFixed(1)} min`)
|
|
46
|
+
console.log(' Travel times:', s.travelTimes)
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Engine Support
|
|
51
|
+
|
|
52
|
+
| Engine | Isochrone | Route Matrix | Auth |
|
|
53
|
+
|--------|:---------:|:------------:|------|
|
|
54
|
+
| Valhalla | Yes | Yes | None (self-hosted) |
|
|
55
|
+
| OpenRouteService | Yes | Yes | API key |
|
|
56
|
+
| GraphHopper | Yes | Yes | API key (optional) |
|
|
57
|
+
| OSRM | No | Yes | None (self-hosted) |
|
|
58
|
+
|
|
59
|
+
OSRM does not support isochrone computation — use it only when you need a fast route matrix and are supplying your own intersection polygon.
|
|
60
|
+
|
|
61
|
+
## Fairness Strategies
|
|
62
|
+
|
|
63
|
+
| Strategy | Optimises | Use when... |
|
|
64
|
+
|----------|-----------|-------------|
|
|
65
|
+
| `min_max` | Worst-case travel time | You want nobody to travel excessively |
|
|
66
|
+
| `min_total` | Sum of all travel times | You want minimum total travel for the group |
|
|
67
|
+
| `min_variance` | Variance in travel times | You want everyone to travel roughly equally |
|
|
68
|
+
|
|
69
|
+
## API Reference
|
|
70
|
+
|
|
71
|
+
### Core function
|
|
72
|
+
|
|
73
|
+
| Function | Description |
|
|
74
|
+
|----------|-------------|
|
|
75
|
+
| `findRendezvous(engine, options)` | Run the full pipeline and return ranked suggestions |
|
|
76
|
+
|
|
77
|
+
### Geometry (`rendezvous-kit/geo`)
|
|
78
|
+
|
|
79
|
+
| Function | Description |
|
|
80
|
+
|----------|-------------|
|
|
81
|
+
| `intersectPolygons(polygons)` | Sutherland–Hodgman N-polygon intersection; returns `GeoJSONPolygon \| null` |
|
|
82
|
+
| `boundingBox(polygon)` | Compute `BBox` (minLon, minLat, maxLon, maxLat) |
|
|
83
|
+
| `centroid(polygon)` | Geometric centre as `{ lat, lon }` |
|
|
84
|
+
| `polygonArea(polygon)` | Area in square metres |
|
|
85
|
+
|
|
86
|
+
### Engines
|
|
87
|
+
|
|
88
|
+
| Class | Import path | Constructor |
|
|
89
|
+
|-------|-------------|-------------|
|
|
90
|
+
| `ValhallaEngine` | `rendezvous-kit/engines/valhalla` | `{ baseUrl }` |
|
|
91
|
+
| `OpenRouteServiceEngine` | `rendezvous-kit/engines/openrouteservice` | `{ apiKey, baseUrl? }` |
|
|
92
|
+
| `GraphHopperEngine` | `rendezvous-kit/engines/graphhopper` | `{ baseUrl, apiKey? }` |
|
|
93
|
+
| `OsrmEngine` | `rendezvous-kit/engines/osrm` | `{ baseUrl }` |
|
|
94
|
+
|
|
95
|
+
### Venues (`rendezvous-kit/venues`)
|
|
96
|
+
|
|
97
|
+
| Function | Description |
|
|
98
|
+
|----------|-------------|
|
|
99
|
+
| `searchVenues(polygon, venueTypes, overpassUrl?)` | Search Overpass API within polygon bounding box |
|
|
100
|
+
|
|
101
|
+
### Types
|
|
102
|
+
|
|
103
|
+
| Type | Shape |
|
|
104
|
+
|------|-------|
|
|
105
|
+
| `LatLon` | `{ lat, lon, label? }` |
|
|
106
|
+
| `GeoJSONPolygon` | Standard GeoJSON polygon geometry |
|
|
107
|
+
| `TransportMode` | `'drive' \| 'cycle' \| 'walk' \| 'public_transit'` |
|
|
108
|
+
| `FairnessStrategy` | `'min_max' \| 'min_total' \| 'min_variance'` |
|
|
109
|
+
| `VenueType` | `'park' \| 'cafe' \| 'restaurant' \| 'service_station' \| 'library' \| 'pub' \| 'playground' \| 'community_centre' \| string` |
|
|
110
|
+
| `RoutingEngine` | Interface — `computeIsochrone` + `computeRouteMatrix` |
|
|
111
|
+
| `Isochrone` | `{ origin, mode, timeMinutes, polygon }` |
|
|
112
|
+
| `MatrixEntry` | `{ originIndex, destinationIndex, durationMinutes, distanceKm }` |
|
|
113
|
+
| `RouteMatrix` | `{ origins, destinations, entries }` |
|
|
114
|
+
| `Venue` | `{ name, lat, lon, venueType, osmId? }` |
|
|
115
|
+
| `RendezvousOptions` | `{ participants, mode, maxTimeMinutes, venueTypes, fairness?, limit? }` |
|
|
116
|
+
| `RendezvousSuggestion` | `{ venue, travelTimes, fairnessScore }` |
|
|
117
|
+
|
|
118
|
+
## Subpath Exports
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { findRendezvous } from 'rendezvous-kit' // barrel
|
|
122
|
+
import { intersectPolygons, centroid } from 'rendezvous-kit/geo' // geometry
|
|
123
|
+
import { ValhallaEngine } from 'rendezvous-kit/engines/valhalla'
|
|
124
|
+
import { OpenRouteServiceEngine } from 'rendezvous-kit/engines/openrouteservice'
|
|
125
|
+
import { GraphHopperEngine } from 'rendezvous-kit/engines/graphhopper'
|
|
126
|
+
import { OsrmEngine } from 'rendezvous-kit/engines/osrm'
|
|
127
|
+
import { searchVenues } from 'rendezvous-kit/venues'
|
|
128
|
+
import { findRendezvous } from 'rendezvous-kit/rendezvous' // same as barrel
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Pipeline
|
|
132
|
+
|
|
133
|
+
`findRendezvous` runs six steps:
|
|
134
|
+
|
|
135
|
+
1. **Isochrones** — compute a reachability polygon for each participant
|
|
136
|
+
2. **Intersection** — intersect all polygons using Sutherland–Hodgman; returns `null` if there is no overlap
|
|
137
|
+
3. **Venue search** — query Overpass API within the intersection's bounding box
|
|
138
|
+
4. **Route matrix** — compute travel times from every participant to every candidate venue
|
|
139
|
+
5. **Scoring** — apply the fairness strategy to produce a single score per venue
|
|
140
|
+
6. **Ranking** — sort by score ascending and return the top `limit` suggestions
|
|
141
|
+
|
|
142
|
+
If the isochrones do not overlap, `findRendezvous` returns an empty array. If no venues are found, it falls back to the geometric centroid of the intersection.
|
|
143
|
+
|
|
144
|
+
## Implementing a Custom Engine
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import type { RoutingEngine, LatLon, TransportMode, Isochrone, RouteMatrix } from 'rendezvous-kit'
|
|
148
|
+
|
|
149
|
+
class MyEngine implements RoutingEngine {
|
|
150
|
+
readonly name = 'MyEngine'
|
|
151
|
+
|
|
152
|
+
async computeIsochrone(origin: LatLon, mode: TransportMode, timeMinutes: number): Promise<Isochrone> {
|
|
153
|
+
// call your API and return an Isochrone
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async computeRouteMatrix(origins: LatLon[], destinations: LatLon[], mode: TransportMode): Promise<RouteMatrix> {
|
|
157
|
+
// call your API and return a RouteMatrix
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Companion Library
|
|
163
|
+
|
|
164
|
+
**geohash-kit** — spatial primitives (pointInPolygon, GeoJSON types, distance utilities) used internally by rendezvous-kit.
|
|
165
|
+
|
|
166
|
+
- npm: [`geohash-kit`](https://www.npmjs.com/package/geohash-kit)
|
|
167
|
+
- GitHub: [`TheCryptoDonkey/geohash-kit`](https://github.com/TheCryptoDonkey/geohash-kit)
|
|
168
|
+
|
|
169
|
+
## For AI Assistants
|
|
170
|
+
|
|
171
|
+
See [llms.txt](./llms.txt) for a concise API summary, or [llms-full.txt](./llms-full.txt) for the complete reference with examples.
|
|
172
|
+
|
|
173
|
+
## Licence
|
|
174
|
+
|
|
175
|
+
[MIT](https://github.com/TheCryptoDonkey/rendezvous-kit/blob/main/LICENSE)
|
|
176
|
+
|
|
177
|
+
## Support
|
|
178
|
+
|
|
179
|
+
For issues and feature requests, see [GitHub Issues](https://github.com/TheCryptoDonkey/rendezvous-kit/issues).
|
|
180
|
+
|
|
181
|
+
If you find rendezvous-kit useful, consider sending a tip:
|
|
182
|
+
|
|
183
|
+
- **Lightning:** `thedonkey@strike.me`
|
|
184
|
+
- **Nostr zaps:** `npub1mgvlrnf5hm9yf0n5mf9nqmvarhvxkc6remu5ec3vf8r0txqkuk7su0e7q2`
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RoutingEngine, Isochrone, RouteMatrix, TransportMode, LatLon } from '../types.js';
|
|
2
|
+
export declare class GraphHopperEngine implements RoutingEngine {
|
|
3
|
+
readonly name = "GraphHopper";
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
private readonly apiKey?;
|
|
6
|
+
constructor(config: {
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
});
|
|
10
|
+
private params;
|
|
11
|
+
computeIsochrone(origin: LatLon, mode: TransportMode, timeMinutes: number): Promise<Isochrone>;
|
|
12
|
+
computeRouteMatrix(origins: LatLon[], destinations: LatLon[], mode: TransportMode): Promise<RouteMatrix>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=graphhopper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphhopper.d.ts","sourceRoot":"","sources":["../../src/engines/graphhopper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAAE,SAAS,EAAE,WAAW,EACrC,aAAa,EAAE,MAAM,EACtB,MAAM,aAAa,CAAA;AASpB,qBAAa,iBAAkB,YAAW,aAAa;IACrD,QAAQ,CAAC,IAAI,iBAAgB;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAQ;gBAEpB,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;IAKxD,OAAO,CAAC,MAAM;IAMR,gBAAgB,CACpB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,aAAa,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,CAAC;IAmBf,kBAAkB,CACtB,OAAO,EAAE,MAAM,EAAE,EACjB,YAAY,EAAE,MAAM,EAAE,EACtB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,WAAW,CAAC;CAuCxB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const PROFILE = {
|
|
2
|
+
drive: 'car',
|
|
3
|
+
cycle: 'bike',
|
|
4
|
+
walk: 'foot',
|
|
5
|
+
public_transit: 'car',
|
|
6
|
+
};
|
|
7
|
+
export class GraphHopperEngine {
|
|
8
|
+
name = 'GraphHopper';
|
|
9
|
+
baseUrl;
|
|
10
|
+
apiKey;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
13
|
+
this.apiKey = config.apiKey;
|
|
14
|
+
}
|
|
15
|
+
params(extra) {
|
|
16
|
+
const p = new URLSearchParams(extra);
|
|
17
|
+
if (this.apiKey)
|
|
18
|
+
p.set('key', this.apiKey);
|
|
19
|
+
return p.toString();
|
|
20
|
+
}
|
|
21
|
+
async computeIsochrone(origin, mode, timeMinutes) {
|
|
22
|
+
const qs = this.params({
|
|
23
|
+
point: `${origin.lat},${origin.lon}`,
|
|
24
|
+
time_limit: String(timeMinutes * 60),
|
|
25
|
+
profile: PROFILE[mode],
|
|
26
|
+
});
|
|
27
|
+
const res = await fetch(`${this.baseUrl}/isochrone?${qs}`);
|
|
28
|
+
if (!res.ok) {
|
|
29
|
+
const text = await res.text().catch(() => '');
|
|
30
|
+
throw new Error(`GraphHopper isochrone error: ${res.status} — ${text}`);
|
|
31
|
+
}
|
|
32
|
+
const data = (await res.json());
|
|
33
|
+
if (!data.polygons?.length)
|
|
34
|
+
throw new Error('GraphHopper returned no polygons');
|
|
35
|
+
return { origin, mode, timeMinutes, polygon: data.polygons[0].geometry };
|
|
36
|
+
}
|
|
37
|
+
async computeRouteMatrix(origins, destinations, mode) {
|
|
38
|
+
const body = {
|
|
39
|
+
from_points: origins.map((c) => [c.lon, c.lat]),
|
|
40
|
+
to_points: destinations.map((c) => [c.lon, c.lat]),
|
|
41
|
+
profile: PROFILE[mode],
|
|
42
|
+
out_arrays: ['times', 'distances'],
|
|
43
|
+
};
|
|
44
|
+
const qs = this.params({});
|
|
45
|
+
const url = qs ? `${this.baseUrl}/matrix?${qs}` : `${this.baseUrl}/matrix`;
|
|
46
|
+
const res = await fetch(url, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: { 'Content-Type': 'application/json' },
|
|
49
|
+
body: JSON.stringify(body),
|
|
50
|
+
});
|
|
51
|
+
if (!res.ok) {
|
|
52
|
+
const text = await res.text().catch(() => '');
|
|
53
|
+
throw new Error(`GraphHopper matrix error: ${res.status} — ${text}`);
|
|
54
|
+
}
|
|
55
|
+
// GraphHopper returns times in seconds, distances in metres
|
|
56
|
+
const data = (await res.json());
|
|
57
|
+
const entries = [];
|
|
58
|
+
for (let oi = 0; oi < origins.length; oi++) {
|
|
59
|
+
for (let di = 0; di < destinations.length; di++) {
|
|
60
|
+
entries.push({
|
|
61
|
+
originIndex: oi,
|
|
62
|
+
destinationIndex: di,
|
|
63
|
+
durationMinutes: data.times[oi][di] < 0 ? -1 : data.times[oi][di] / 60,
|
|
64
|
+
// GraphHopper returns distances in metres
|
|
65
|
+
distanceKm: data.distances[oi][di] < 0 ? -1 : data.distances[oi][di] / 1000,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { origins, destinations, entries };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=graphhopper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphhopper.js","sourceRoot":"","sources":["../../src/engines/graphhopper.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,GAAkC;IAC7C,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,MAAM;IACZ,cAAc,EAAE,KAAK;CACtB,CAAA;AAED,MAAM,OAAO,iBAAiB;IACnB,IAAI,GAAG,aAAa,CAAA;IACZ,OAAO,CAAQ;IACf,MAAM,CAAS;IAEhC,YAAY,MAA4C;QACtD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;IAC7B,CAAC;IAEO,MAAM,CAAC,KAA6B;QAC1C,MAAM,CAAC,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,CAAA;QACpC,IAAI,IAAI,CAAC,MAAM;YAAE,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QAC1C,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAA;IACrB,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,MAAc,EAC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EAAE;oBACpB,eAAe,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE;oBACtE,0CAA0C;oBAC1C,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI;iBAC5E,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,CAAA;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RoutingEngine, Isochrone, RouteMatrix, LatLon, TransportMode } from '../types.js';
|
|
2
|
+
export interface OpenRouteServiceOptions {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class OpenRouteServiceEngine implements RoutingEngine {
|
|
7
|
+
readonly name = "OpenRouteService";
|
|
8
|
+
private readonly apiKey;
|
|
9
|
+
private readonly baseUrl;
|
|
10
|
+
constructor(options: OpenRouteServiceOptions);
|
|
11
|
+
computeIsochrone(origin: LatLon, mode: TransportMode, timeMinutes: number): Promise<Isochrone>;
|
|
12
|
+
computeRouteMatrix(origins: LatLon[], destinations: LatLon[], mode: TransportMode): Promise<RouteMatrix>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=openrouteservice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouteservice.d.ts","sourceRoot":"","sources":["../../src/engines/openrouteservice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAW/F,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,qBAAa,sBAAuB,YAAW,aAAa;IAC1D,QAAQ,CAAC,IAAI,sBAAqB;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;gBAEpB,OAAO,EAAE,uBAAuB;IAKtC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAkC9F,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC;CA2C/G"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const ORS_BASE = 'https://api.openrouteservice.org';
|
|
2
|
+
const MODE_MAP = {
|
|
3
|
+
drive: 'driving-car',
|
|
4
|
+
cycle: 'cycling-regular',
|
|
5
|
+
walk: 'foot-walking',
|
|
6
|
+
public_transit: 'driving-car', // ORS doesn't support public transit; fallback to driving
|
|
7
|
+
};
|
|
8
|
+
export class OpenRouteServiceEngine {
|
|
9
|
+
name = 'OpenRouteService';
|
|
10
|
+
apiKey;
|
|
11
|
+
baseUrl;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.apiKey = options.apiKey;
|
|
14
|
+
this.baseUrl = options.baseUrl ?? ORS_BASE;
|
|
15
|
+
}
|
|
16
|
+
async computeIsochrone(origin, mode, timeMinutes) {
|
|
17
|
+
const profile = MODE_MAP[mode];
|
|
18
|
+
const body = {
|
|
19
|
+
locations: [[origin.lon, origin.lat]],
|
|
20
|
+
range: [timeMinutes * 60],
|
|
21
|
+
range_type: 'time',
|
|
22
|
+
};
|
|
23
|
+
const response = await fetch(`${this.baseUrl}/v2/isochrones/${profile}`, {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
headers: {
|
|
26
|
+
'Authorization': this.apiKey,
|
|
27
|
+
'Content-Type': 'application/json',
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify(body),
|
|
30
|
+
});
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
const text = await response.text();
|
|
33
|
+
throw new Error(`ORS isochrone API error ${response.status}: ${text}`);
|
|
34
|
+
}
|
|
35
|
+
const data = await response.json();
|
|
36
|
+
return {
|
|
37
|
+
origin,
|
|
38
|
+
mode,
|
|
39
|
+
timeMinutes,
|
|
40
|
+
polygon: data.features[0].geometry,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async computeRouteMatrix(origins, destinations, mode) {
|
|
44
|
+
const profile = MODE_MAP[mode];
|
|
45
|
+
const allLocations = [...origins, ...destinations];
|
|
46
|
+
const body = {
|
|
47
|
+
locations: allLocations.map(p => [p.lon, p.lat]),
|
|
48
|
+
sources: origins.map((_, i) => i),
|
|
49
|
+
destinations: destinations.map((_, i) => i + origins.length),
|
|
50
|
+
metrics: ['duration', 'distance'],
|
|
51
|
+
};
|
|
52
|
+
const response = await fetch(`${this.baseUrl}/v2/matrix/${profile}`, {
|
|
53
|
+
method: 'POST',
|
|
54
|
+
headers: {
|
|
55
|
+
'Authorization': this.apiKey,
|
|
56
|
+
'Content-Type': 'application/json',
|
|
57
|
+
},
|
|
58
|
+
body: JSON.stringify(body),
|
|
59
|
+
});
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
const text = await response.text();
|
|
62
|
+
throw new Error(`ORS matrix API error ${response.status}: ${text}`);
|
|
63
|
+
}
|
|
64
|
+
const data = await response.json();
|
|
65
|
+
const entries = [];
|
|
66
|
+
for (let oi = 0; oi < origins.length; oi++) {
|
|
67
|
+
for (let di = 0; di < destinations.length; di++) {
|
|
68
|
+
entries.push({
|
|
69
|
+
originIndex: oi,
|
|
70
|
+
destinationIndex: di,
|
|
71
|
+
durationMinutes: data.durations[oi][di] / 60,
|
|
72
|
+
distanceKm: data.distances[oi][di] / 1000,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { origins, destinations, entries };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=openrouteservice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouteservice.js","sourceRoot":"","sources":["../../src/engines/openrouteservice.ts"],"names":[],"mappings":"AAEA,MAAM,QAAQ,GAAG,kCAAkC,CAAA;AAEnD,MAAM,QAAQ,GAAkC;IAC9C,KAAK,EAAE,aAAa;IACpB,KAAK,EAAE,iBAAiB;IACxB,IAAI,EAAE,cAAc;IACpB,cAAc,EAAE,aAAa,EAAE,0DAA0D;CAC1F,CAAA;AAOD,MAAM,OAAO,sBAAsB;IACxB,IAAI,GAAG,kBAAkB,CAAA;IACjB,MAAM,CAAQ;IACd,OAAO,CAAQ;IAEhC,YAAY,OAAgC;QAC1C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,QAAQ,CAAA;IAC5C,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,MAAc,EAAE,IAAmB,EAAE,WAAmB;QAC7E,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC9B,MAAM,IAAI,GAAG;YACX,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;YACrC,KAAK,EAAE,CAAC,WAAW,GAAG,EAAE,CAAC;YACzB,UAAU,EAAE,MAAM;SACnB,CAAA;QAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,kBAAkB,OAAO,EAAE,EAAE;YACvE,M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2
|
+
export declare class OsrmEngine implements RoutingEngine {
|
|
3
|
+
readonly name = "OSRM";
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
constructor(config: {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
});
|
|
8
|
+
computeIsochrone(_origin: LatLon, _mode: TransportMode, _timeMinutes: number): Promise<Isochrone>;
|
|
9
|
+
computeRouteMatrix(origins: LatLon[], destinations: LatLon[], mode: TransportMode): Promise<RouteMatrix>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=osrm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"osrm.d.ts","sourceRoot":"","sources":["../../src/engines/osrm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAAE,SAAS,EAAE,WAAW,EACrC,aAAa,EAAE,MAAM,EACtB,MAAM,aAAa,CAAA;AASpB,qBAAa,UAAW,YAAW,aAAa;IAC9C,QAAQ,CAAC,IAAI,UAAS;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;gBAEpB,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;IAIvC,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAM3F,kBAAkB,CACtB,OAAO,EAAE,MAAM,EAAE,EACjB,YAAY,EAAE,MAAM,EAAE,EACtB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,WAAW,CAAC;CAyCxB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const PROFILE = {
|
|
2
|
+
drive: 'car',
|
|
3
|
+
cycle: 'bike',
|
|
4
|
+
walk: 'foot',
|
|
5
|
+
public_transit: 'car', // OSRM does not support public transit; fallback to driving
|
|
6
|
+
};
|
|
7
|
+
export class OsrmEngine {
|
|
8
|
+
name = 'OSRM';
|
|
9
|
+
baseUrl;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
12
|
+
}
|
|
13
|
+
computeIsochrone(_origin, _mode, _timeMinutes) {
|
|
14
|
+
throw new Error('OSRM does not support isochrone computation. Use Valhalla, ORS, or GraphHopper instead.');
|
|
15
|
+
}
|
|
16
|
+
async computeRouteMatrix(origins, destinations, mode) {
|
|
17
|
+
const profile = PROFILE[mode];
|
|
18
|
+
const allCoords = [...origins, ...destinations]
|
|
19
|
+
.map((c) => `${c.lon},${c.lat}`)
|
|
20
|
+
.join(';');
|
|
21
|
+
const sources = origins.map((_, i) => i).join(';');
|
|
22
|
+
const dests = destinations.map((_, i) => origins.length + i).join(';');
|
|
23
|
+
const res = await fetch(`${this.baseUrl}/table/v1/${profile}/${allCoords}?sources=${sources}&destinations=${dests}&annotations=duration,distance`);
|
|
24
|
+
if (!res.ok) {
|
|
25
|
+
const text = await res.text().catch(() => '');
|
|
26
|
+
throw new Error(`OSRM matrix error: ${res.status} — ${text}`);
|
|
27
|
+
}
|
|
28
|
+
// OSRM returns durations in seconds, distances in metres
|
|
29
|
+
const data = (await res.json());
|
|
30
|
+
const entries = [];
|
|
31
|
+
for (let oi = 0; oi < origins.length; oi++) {
|
|
32
|
+
for (let di = 0; di < destinations.length; di++) {
|
|
33
|
+
const dur = data.durations[oi][di];
|
|
34
|
+
const dist = data.distances[oi][di];
|
|
35
|
+
entries.push({
|
|
36
|
+
originIndex: oi,
|
|
37
|
+
destinationIndex: di,
|
|
38
|
+
// OSRM returns seconds; convert to minutes
|
|
39
|
+
durationMinutes: dur == null || dur < 0 ? -1 : dur / 60,
|
|
40
|
+
// OSRM returns metres; convert to km
|
|
41
|
+
distanceKm: dist == null || dist < 0 ? -1 : dist / 1000,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { origins, destinations, entries };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=osrm.js.map
|
|
@@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CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,CAAA;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RoutingEngine, Isochrone, RouteMatrix, TransportMode, LatLon } from '../types.js';
|
|
2
|
+
export declare class ValhallaEngine implements RoutingEngine {
|
|
3
|
+
readonly name = "Valhalla";
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
constructor(config: {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
});
|
|
8
|
+
computeIsochrone(origin: LatLon, mode: TransportMode, timeMinutes: number): Promise<Isochrone>;
|
|
9
|
+
computeRouteMatrix(origins: LatLon[], destinations: LatLon[], mode: TransportMode): Promise<RouteMatrix>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=valhalla.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valhalla.d.ts","sourceRoot":"","sources":["../../src/engines/valhalla.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAAE,SAAS,EAAE,WAAW,EACrC,aAAa,EAAE,MAAM,EACtB,MAAM,aAAa,CAAA;AASpB,qBAAa,cAAe,YAAW,aAAa;IAClD,QAAQ,CAAC,IAAI,cAAa;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;gBAEpB,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;IAIjC,gBAAgB,CACpB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,aAAa,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,CAAC;IAmCf,kBAAkB,CACtB,OAAO,EAAE,MAAM,EAAE,EACjB,YAAY,EAAE,MAAM,EAAE,EACtB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,WAAW,CAAC;CAsCxB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const COSTING = {
|
|
2
|
+
drive: 'auto',
|
|
3
|
+
cycle: 'bicycle',
|
|
4
|
+
walk: 'pedestrian',
|
|
5
|
+
public_transit: 'multimodal',
|
|
6
|
+
};
|
|
7
|
+
export class ValhallaEngine {
|
|
8
|
+
name = 'Valhalla';
|
|
9
|
+
baseUrl;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
12
|
+
}
|
|
13
|
+
async computeIsochrone(origin, mode, timeMinutes) {
|
|
14
|
+
const body = {
|
|
15
|
+
locations: [{ lat: origin.lat, lon: origin.lon }],
|
|
16
|
+
costing: COSTING[mode],
|
|
17
|
+
contours: [{ time: timeMinutes }],
|
|
18
|
+
polygons: true,
|
|
19
|
+
};
|
|
20
|
+
const res = await fetch(`${this.baseUrl}/isochrone`, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers: { 'Content-Type': 'application/json' },
|
|
23
|
+
body: JSON.stringify(body),
|
|
24
|
+
});
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
const text = await res.text().catch(() => '');
|
|
27
|
+
throw new Error(`Valhalla isochrone error: ${res.status} ${res.statusText} — ${text}`);
|
|
28
|
+
}
|
|
29
|
+
const data = (await res.json());
|
|
30
|
+
if (!data.features?.length) {
|
|
31
|
+
throw new Error('Valhalla returned no isochrone features');
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
origin,
|
|
35
|
+
mode,
|
|
36
|
+
timeMinutes,
|
|
37
|
+
polygon: data.features[0].geometry,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async computeRouteMatrix(origins, destinations, mode) {
|
|
41
|
+
const body = {
|
|
42
|
+
sources: origins.map((c) => ({ lat: c.lat, lon: c.lon })),
|
|
43
|
+
targets: destinations.map((c) => ({ lat: c.lat, lon: c.lon })),
|
|
44
|
+
costing: COSTING[mode],
|
|
45
|
+
};
|
|
46
|
+
const res = await fetch(`${this.baseUrl}/sources_to_targets`, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: { 'Content-Type': 'application/json' },
|
|
49
|
+
body: JSON.stringify(body),
|
|
50
|
+
});
|
|
51
|
+
if (!res.ok) {
|
|
52
|
+
const text = await res.text().catch(() => '');
|
|
53
|
+
throw new Error(`Valhalla matrix error: ${res.status} ${res.statusText} — ${text}`);
|
|
54
|
+
}
|
|
55
|
+
const data = (await res.json());
|
|
56
|
+
const entries = [];
|
|
57
|
+
for (let oi = 0; oi < origins.length; oi++) {
|
|
58
|
+
for (let di = 0; di < destinations.length; di++) {
|
|
59
|
+
const cell = data.sources_to_targets[oi][di];
|
|
60
|
+
entries.push({
|
|
61
|
+
originIndex: oi,
|
|
62
|
+
destinationIndex: di,
|
|
63
|
+
durationMinutes: cell.time < 0 ? -1 : cell.time / 60,
|
|
64
|
+
// Valhalla returns distance in km (unlike ORS which returns metres)
|
|
65
|
+
distanceKm: cell.distance < 0 ? -1 : cell.distance,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { origins, destinations, entries };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=valhalla.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valhalla.js","sourceRoot":"","sources":["../../src/engines/valhalla.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,GAAkC;IAC7C,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,YAAY;IAClB,cAAc,EAAE,YAAY;CAC7B,CAAA;AAED,MAAM,OAAO,cAAc;IAChB,IAAI,GAAG,UAAU,CAAA;IACT,OAAO,CAAQ;IAEhC,YAAY,MAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IAClD,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,MAAc,EACd,IAAmB,EACnB,WAAmB;QAEnB,MAAM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,CAAC,EAAE,CAAC,CAAA;gBAC5C,OAAO,CAAC,IAAI,CAAC;oBACX,WAAW,EAAE,EAAE;oBACf,gBAAgB,EAAE,EAAE;oBACpB,eAAe,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE;oBACpD,oEAAoE;oBACpE,UAAU,EAAE,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ;iBACnD,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,CAAA;IAC3C,CAAC;CACF"}
|
package/dist/geo.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { GeoJSONPolygon } from './types.js';
|
|
2
|
+
export interface BBox {
|
|
3
|
+
minLon: number;
|
|
4
|
+
minLat: number;
|
|
5
|
+
maxLon: number;
|
|
6
|
+
maxLat: number;
|
|
7
|
+
}
|
|
8
|
+
export interface Coordinate {
|
|
9
|
+
lat: number;
|
|
10
|
+
lon: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function boundingBox(polygon: GeoJSONPolygon): BBox;
|
|
13
|
+
export declare function centroid(polygon: GeoJSONPolygon): Coordinate;
|
|
14
|
+
export declare function polygonArea(polygon: GeoJSONPolygon): number;
|
|
15
|
+
export declare function intersectPolygons(polygons: GeoJSONPolygon[]): GeoJSONPolygon | null;
|
|
16
|
+
//# sourceMappingURL=geo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geo.d.ts","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,MAAM,WAAW,IAAI;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAiBzD;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,UAAU,CAa5D;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAmB3D;AAED,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,cAAc,EAAE,GACzB,cAAc,GAAG,IAAI,CAkBvB"}
|