@mailwoman/photon 5.4.0 → 5.6.0
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/README.md +4 -0
- package/out/cli.js +43 -14
- package/out/cli.js.map +1 -1
- package/out/index.d.ts +61 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +94 -1
- package/out/index.js.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -32,6 +32,10 @@ const engine: PhotonEngine = {
|
|
|
32
32
|
express().use(createPhotonRouter(engine)).listen(2322)
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
## CORS
|
|
36
|
+
|
|
37
|
+
Map widgets (`leaflet-control-geocoder`, `@openrunner/photon-geocoder`) call this cross-origin from the browser, so the server sends permissive CORS by default — `Access-Control-Allow-Origin: *` and a `204` answer to preflight `OPTIONS`, matching upstream Photon. Behind a reverse proxy that already sets the headers, turn it off with `--no-cors` (or `createPhotonRouter(engine, { cors: false })`).
|
|
38
|
+
|
|
35
39
|
## Status
|
|
36
40
|
|
|
37
41
|
Shipped. `/api` and `/reverse` resolve over the live engine and return Photon GeoJSON. `/api` runs the
|
package/out/cli.js
CHANGED
|
@@ -16,11 +16,12 @@
|
|
|
16
16
|
import { existsSync } from "node:fs";
|
|
17
17
|
import { join } from "node:path";
|
|
18
18
|
import { parseArgs } from "node:util";
|
|
19
|
+
import { matchCountry } from "@mailwoman/codex/country";
|
|
19
20
|
import { NeuralAddressClassifier } from "@mailwoman/neural";
|
|
20
21
|
import { createWOFResolver } from "@mailwoman/resolver";
|
|
21
22
|
import { geocodeAddress, ShardProvider } from "mailwoman/geocode-core";
|
|
22
23
|
import { createResolverBackend, mailwomanDataRoot, resolveCandidateDBPath, wofShardPaths, } from "mailwoman/resolver-backend";
|
|
23
|
-
import { createPhotonRouter, photonCollection, photonFeature, } from "./index.js";
|
|
24
|
+
import { createPhotonRouter, photonCollection, photonFeature, photonForwardCollection, photonOSMTags, } from "./index.js";
|
|
24
25
|
/** WOF placetype → Photon property key. */
|
|
25
26
|
const PLACETYPE_TO_KEY = {
|
|
26
27
|
street: "street",
|
|
@@ -38,7 +39,11 @@ async function serve() {
|
|
|
38
39
|
port: { type: "string", default: "2322" },
|
|
39
40
|
host: { type: "string", default: "0.0.0.0" },
|
|
40
41
|
"candidate-db": { type: "string" },
|
|
42
|
+
// Permissive CORS is on by default (upstream Photon parity — browser widgets need it). `--no-cors`
|
|
43
|
+
// turns it off for deployments where a reverse proxy already sets the headers.
|
|
44
|
+
cors: { type: "boolean", default: true },
|
|
41
45
|
},
|
|
46
|
+
allowNegative: true,
|
|
42
47
|
allowPositionals: true,
|
|
43
48
|
});
|
|
44
49
|
const port = Number(values.port) || 2322;
|
|
@@ -62,22 +67,39 @@ async function serve() {
|
|
|
62
67
|
const query = params.q?.trim();
|
|
63
68
|
if (!query || query.length > MAX_QUERY_LEN)
|
|
64
69
|
return photonCollection([]);
|
|
70
|
+
// #1016: forward the client's viewport/user location as a proximity bias — a SOFT re-rank the resolver
|
|
71
|
+
// folds into candidate scoring (Springfield near the map center wins). Only when both coords are present.
|
|
72
|
+
const bias = params.lat != null && params.lon != null ? [{ lat: params.lat, lon: params.lon }] : undefined;
|
|
65
73
|
// No country constraint: the default-on #244 placer routes the query's country (Berlin→DE,
|
|
66
74
|
// Boston→US). Forcing "US" here is a HARD override (geocode-core.ts:102) that resolved every
|
|
67
75
|
// non-US query to its US namesake — wrong for a global autocomplete front.
|
|
68
|
-
const result = await geocodeAddress(query, { classifier, resolver, shards: shards.for });
|
|
76
|
+
const result = await geocodeAddress(query, { classifier, resolver, shards: shards.for, bias });
|
|
69
77
|
if (result.lat == null || result.lon == null)
|
|
70
78
|
return photonCollection([]);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
// #1014: decorate from the RESOLVED gazetteer place — proper-cased ancestry names (`hierarchy[].name`,
|
|
80
|
+
// not the parsed span) + the resolved country (ISO2 → canonical name via codex) + osm_key/value/type so
|
|
81
|
+
// Photon clients don't TypeError. The candidate backend fills only the locality (no ancestors() table),
|
|
82
|
+
// so state/county come through only on an ancestry-capable backend — country still lands from the code.
|
|
83
|
+
const country = matchCountry(result.countryCode);
|
|
84
|
+
const primary = {
|
|
85
|
+
lat: result.lat,
|
|
86
|
+
lon: result.lon,
|
|
87
|
+
postcode: result.postcode,
|
|
88
|
+
country: country ? { name: country.canonical, code: country.iso2 } : undefined,
|
|
89
|
+
places: result.hierarchy.map((h) => ({ tag: h.tag, name: h.name })),
|
|
76
90
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
// #1016: candidates[0] is the primary itself; its ranked alternatives (Springfield MA/IL/…) become the
|
|
92
|
+
// extra features, up to the requested `limit`. Each alternative is a single resolved place.
|
|
93
|
+
const alternatives = result.candidates.slice(1).map((c) => {
|
|
94
|
+
const cc = matchCountry(c.countryCode);
|
|
95
|
+
return {
|
|
96
|
+
lat: c.lat,
|
|
97
|
+
lon: c.lon,
|
|
98
|
+
country: cc ? { name: cc.canonical, code: cc.iso2 } : undefined,
|
|
99
|
+
places: [{ tag: c.tag, name: c.name }],
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
return photonForwardCollection({ primary, alternatives }, params.limit);
|
|
81
103
|
},
|
|
82
104
|
async reverse(params) {
|
|
83
105
|
if (!reverseGeo)
|
|
@@ -86,7 +108,13 @@ async function serve() {
|
|
|
86
108
|
if (hierarchy.length === 0)
|
|
87
109
|
return photonCollection([]);
|
|
88
110
|
const deepest = hierarchy[0];
|
|
89
|
-
|
|
111
|
+
// #1014: carry osm_key/osm_value/type (from the deepest placetype) so /reverse matches /api's schema —
|
|
112
|
+
// no Photon client should dereference an undefined osm_key on a reverse result either.
|
|
113
|
+
const properties = {
|
|
114
|
+
name: deepest.name,
|
|
115
|
+
countrycode: deepest.country?.toLowerCase(),
|
|
116
|
+
...photonOSMTags(deepest.placetype),
|
|
117
|
+
};
|
|
90
118
|
for (const place of hierarchy) {
|
|
91
119
|
const key = PLACETYPE_TO_KEY[place.placetype];
|
|
92
120
|
if (key && properties[key] == null)
|
|
@@ -97,13 +125,14 @@ async function serve() {
|
|
|
97
125
|
};
|
|
98
126
|
const express = (await import("express")).default;
|
|
99
127
|
express()
|
|
100
|
-
.use(createPhotonRouter(engine))
|
|
128
|
+
.use(createPhotonRouter(engine, { cors: values.cors }))
|
|
101
129
|
.listen(port, host, () => {
|
|
102
130
|
console.error(`[@mailwoman/photon] listening on http://${host}:${port}`);
|
|
103
131
|
console.error(` wof: ${adminDBPath ?? "(none found — set MAILWOMAN_WOF_DB)"}`);
|
|
104
132
|
console.error(candidateDb
|
|
105
133
|
? ` resolver: candidate gazetteer (worldwide) — ${candidateDb}`
|
|
106
134
|
: ` resolver: admin-only (US-optimized) — point --candidate-db / $MAILWOMAN_CANDIDATE_DB at a candidate gazetteer for worldwide`);
|
|
135
|
+
console.error(` cors: ${values.cors ? "enabled (Access-Control-Allow-Origin: *)" : "disabled (--no-cors)"}`);
|
|
107
136
|
console.error(` endpoints: GET /api GET /reverse`);
|
|
108
137
|
});
|
|
109
138
|
}
|
|
@@ -113,7 +142,7 @@ switch (command) {
|
|
|
113
142
|
await serve();
|
|
114
143
|
break;
|
|
115
144
|
default:
|
|
116
|
-
console.error("Usage: mailwoman-photon serve [--port 2322] [--host 0.0.0.0] [--candidate-db <path>]");
|
|
145
|
+
console.error("Usage: mailwoman-photon serve [--port 2322] [--host 0.0.0.0] [--candidate-db <path>] [--no-cors]");
|
|
117
146
|
process.exit(command ? 1 : 0);
|
|
118
147
|
}
|
|
119
148
|
//# sourceMappingURL=cli.js.map
|
package/out/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA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AAM,KAAK,EAAE,CAAA;QACb,MAAK;IACN;QACC,OAAO,CAAC,KAAK,CAAC,kGAAkG,CAAC,CAAA;QACjH,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAC/B,CAAC"}
|
package/out/index.d.ts
CHANGED
|
@@ -79,13 +79,73 @@ export interface PhotonEngine {
|
|
|
79
79
|
search?(params: PhotonSearchParams): Promise<PhotonFeatureCollection>;
|
|
80
80
|
reverse?(params: PhotonReverseParams): Promise<PhotonFeatureCollection>;
|
|
81
81
|
}
|
|
82
|
+
/** Options for {@link createPhotonRouter}. */
|
|
83
|
+
export interface PhotonRouterOptions {
|
|
84
|
+
/**
|
|
85
|
+
* Emit permissive CORS headers (`Access-Control-Allow-Origin: *`) on every response and answer preflight `OPTIONS`
|
|
86
|
+
* with `204`. Default `true` — upstream komoot/photon serves permissive CORS, and the map-widget use case
|
|
87
|
+
* (leaflet-control-geocoder, @openrunner/photon-geocoder, …) needs it: a browser's cross-origin XHR is blocked
|
|
88
|
+
* without it (#1017). Set `false` when a reverse proxy already owns the CORS headers.
|
|
89
|
+
*/
|
|
90
|
+
cors?: boolean;
|
|
91
|
+
}
|
|
82
92
|
/**
|
|
83
93
|
* Build the Photon-compatible router around an injected {@link PhotonEngine}. Param parsing lives here; the feature
|
|
84
94
|
* _projection_ (resolved place → {@link PhotonProperties}) is the staged work.
|
|
85
95
|
*/
|
|
86
|
-
export declare function createPhotonRouter(engine: PhotonEngine): Router;
|
|
96
|
+
export declare function createPhotonRouter(engine: PhotonEngine, options?: PhotonRouterOptions): Router;
|
|
87
97
|
/** Build a Photon `Feature` from a coordinate + properties. */
|
|
88
98
|
export declare function photonFeature(lon: number, lat: number, properties: PhotonProperties): PhotonFeature;
|
|
89
99
|
/** Wrap features in a Photon `FeatureCollection`. */
|
|
90
100
|
export declare function photonCollection(features: PhotonFeature[]): PhotonFeatureCollection;
|
|
101
|
+
/**
|
|
102
|
+
* The resolved-place info a forward `/api` result carries: the admin ladder (MOST-SPECIFIC first) with GAZETTEER names,
|
|
103
|
+
* the coordinate, the resolved country, and the postcode. {@link photonForwardProperties} projects it onto Photon's
|
|
104
|
+
* schema. #1014 — decorate from the resolved place, not the parsed input span.
|
|
105
|
+
*/
|
|
106
|
+
export interface PhotonForwardInput {
|
|
107
|
+
lat: number;
|
|
108
|
+
lon: number;
|
|
109
|
+
postcode?: string | null;
|
|
110
|
+
/** The resolved country, mapped by the caller (ISO2 → canonical name via `@mailwoman/codex`). */
|
|
111
|
+
country?: {
|
|
112
|
+
name?: string;
|
|
113
|
+
code?: string;
|
|
114
|
+
} | null;
|
|
115
|
+
/** Resolved admin ancestry, most-specific first, each carrying the gazetteer's canonical name (not the parsed span). */
|
|
116
|
+
places: ReadonlyArray<{
|
|
117
|
+
tag: string;
|
|
118
|
+
name: string;
|
|
119
|
+
}>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The Photon `osm_key`/`osm_value`/`type` for a resolved tag or WOF placetype (`locality`, `region`, `country`, …),
|
|
123
|
+
* falling back to a safe default so the fields are always present. Shared by the forward projection and `/reverse` so
|
|
124
|
+
* the two endpoints report a place the SAME way. #1014.
|
|
125
|
+
*/
|
|
126
|
+
export declare function photonOSMTags(tagOrPlacetype: string): {
|
|
127
|
+
osm_key: string;
|
|
128
|
+
osm_value: string;
|
|
129
|
+
type: string;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Project a resolved forward result into Photon properties — decorating from the RESOLVED gazetteer place (proper-cased
|
|
133
|
+
* names + ancestry + country), NOT the parsed input span, and ALWAYS emitting `osm_key`/`osm_value`/`type` so Photon
|
|
134
|
+
* client libraries (leaflet-control-geocoder, @openrunner/photon-geocoder) never dereference undefined. #1014.
|
|
135
|
+
*/
|
|
136
|
+
export declare function photonForwardProperties(input: PhotonForwardInput): PhotonProperties;
|
|
137
|
+
/** {@link photonForwardProperties}, wrapped as a Photon Point `Feature` at the resolved coordinate. #1014. */
|
|
138
|
+
export declare function photonForwardFeature(input: PhotonForwardInput): PhotonFeature;
|
|
139
|
+
/** The winning place plus its ranked alternatives — the input to {@link photonForwardCollection}. #1016. */
|
|
140
|
+
export interface PhotonForwardResult {
|
|
141
|
+
/** The winning place, with full admin ancestry (from the resolved hierarchy). */
|
|
142
|
+
primary: PhotonForwardInput;
|
|
143
|
+
/** Ranked alternative places (Springfield MA / IL / …), each a single-place input; excludes the primary. */
|
|
144
|
+
alternatives: PhotonForwardInput[];
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Assemble a Photon `FeatureCollection` honoring `limit` (#1016): the primary feature first, then ranked alternatives,
|
|
148
|
+
* capped at `limit`. `limit` floors to 1 (Photon always returns at least the best match).
|
|
149
|
+
*/
|
|
150
|
+
export declare function photonForwardCollection(result: PhotonForwardResult, limit: number): PhotonFeatureCollection;
|
|
91
151
|
//# sourceMappingURL=index.d.ts.map
|
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAuB,MAAM,EAAE,MAAM,SAAS,CAAA;AAErD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAChC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,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GAAG,uBAAuB,CAU3G"}
|
package/out/index.js
CHANGED
|
@@ -25,12 +25,30 @@ function asStringArray(raw) {
|
|
|
25
25
|
return s ? [s] : undefined;
|
|
26
26
|
}
|
|
27
27
|
const EMPTY = { type: "FeatureCollection", features: [] };
|
|
28
|
+
/**
|
|
29
|
+
* Permissive CORS, matching upstream Photon: `Access-Control-Allow-Origin: *` on every response, plus a `204` answer to
|
|
30
|
+
* preflight `OPTIONS`. `ACAO: *` is anonymous (no credentials), so a wildcard `Allow-Headers` is valid.
|
|
31
|
+
*/
|
|
32
|
+
const applyCors = (req, res, next) => {
|
|
33
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
34
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
35
|
+
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
36
|
+
if (req.method === "OPTIONS") {
|
|
37
|
+
res.setHeader("Access-Control-Max-Age", "86400");
|
|
38
|
+
res.status(204).end();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
next();
|
|
42
|
+
};
|
|
28
43
|
/**
|
|
29
44
|
* Build the Photon-compatible router around an injected {@link PhotonEngine}. Param parsing lives here; the feature
|
|
30
45
|
* _projection_ (resolved place → {@link PhotonProperties}) is the staged work.
|
|
31
46
|
*/
|
|
32
|
-
export function createPhotonRouter(engine) {
|
|
47
|
+
export function createPhotonRouter(engine, options = {}) {
|
|
33
48
|
const router = Router();
|
|
49
|
+
// Browser-embedded widgets need CORS or their cross-origin XHR is blocked before the request completes (#1017).
|
|
50
|
+
if (options.cors !== false)
|
|
51
|
+
router.use(applyCors);
|
|
34
52
|
const search = async (req, res) => {
|
|
35
53
|
if (!engine.search) {
|
|
36
54
|
res.status(501).json({ ...EMPTY, message: "search not implemented" });
|
|
@@ -100,4 +118,79 @@ export function photonFeature(lon, lat, properties) {
|
|
|
100
118
|
export function photonCollection(features) {
|
|
101
119
|
return { type: "FeatureCollection", features };
|
|
102
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* How a resolved tag projects onto Photon's schema: the property key that holds its name, plus the OSM `key`/`value`/
|
|
123
|
+
* `type` a Photon client reads. Kept close to komoot Photon's own values so client label-builders behave.
|
|
124
|
+
*/
|
|
125
|
+
const FORWARD_TAG_PROJECTION = {
|
|
126
|
+
venue: { key: "name", osmKey: "amenity", osmValue: "yes", type: "house" },
|
|
127
|
+
house: { key: "name", osmKey: "building", osmValue: "yes", type: "house" },
|
|
128
|
+
street: { key: "street", osmKey: "highway", osmValue: "residential", type: "street" },
|
|
129
|
+
neighbourhood: { key: "district", osmKey: "place", osmValue: "suburb", type: "district" },
|
|
130
|
+
dependent_locality: { key: "district", osmKey: "place", osmValue: "suburb", type: "district" },
|
|
131
|
+
borough: { key: "district", osmKey: "place", osmValue: "borough", type: "district" },
|
|
132
|
+
locality: { key: "city", osmKey: "place", osmValue: "city", type: "city" },
|
|
133
|
+
// WOF placetypes the /reverse hierarchy uses (so both endpoints derive osm tags from ONE table).
|
|
134
|
+
localadmin: { key: "city", osmKey: "place", osmValue: "city", type: "city" },
|
|
135
|
+
subregion: { key: "county", osmKey: "place", osmValue: "county", type: "county" },
|
|
136
|
+
county: { key: "county", osmKey: "place", osmValue: "county", type: "county" },
|
|
137
|
+
region: { key: "state", osmKey: "place", osmValue: "state", type: "state" },
|
|
138
|
+
macroregion: { key: "state", osmKey: "place", osmValue: "state", type: "state" },
|
|
139
|
+
country: { key: "country", osmKey: "place", osmValue: "country", type: "country" },
|
|
140
|
+
};
|
|
141
|
+
/** Fallback OSM tags — a Photon client reads `osm_key`/`osm_value`/`type` unconditionally, so they must never be absent. */
|
|
142
|
+
const DEFAULT_OSM_TAGS = { osm_key: "place", osm_value: "yes", type: "other" };
|
|
143
|
+
/**
|
|
144
|
+
* The Photon `osm_key`/`osm_value`/`type` for a resolved tag or WOF placetype (`locality`, `region`, `country`, …),
|
|
145
|
+
* falling back to a safe default so the fields are always present. Shared by the forward projection and `/reverse` so
|
|
146
|
+
* the two endpoints report a place the SAME way. #1014.
|
|
147
|
+
*/
|
|
148
|
+
export function photonOSMTags(tagOrPlacetype) {
|
|
149
|
+
const proj = FORWARD_TAG_PROJECTION[tagOrPlacetype];
|
|
150
|
+
return proj ? { osm_key: proj.osmKey, osm_value: proj.osmValue, type: proj.type } : { ...DEFAULT_OSM_TAGS };
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Project a resolved forward result into Photon properties — decorating from the RESOLVED gazetteer place (proper-cased
|
|
154
|
+
* names + ancestry + country), NOT the parsed input span, and ALWAYS emitting `osm_key`/`osm_value`/`type` so Photon
|
|
155
|
+
* client libraries (leaflet-control-geocoder, @openrunner/photon-geocoder) never dereference undefined. #1014.
|
|
156
|
+
*/
|
|
157
|
+
export function photonForwardProperties(input) {
|
|
158
|
+
// Safe defaults: a Photon client reads osm_key/osm_value/type unconditionally, so they must never be undefined.
|
|
159
|
+
const props = { ...DEFAULT_OSM_TAGS };
|
|
160
|
+
const [primary] = input.places;
|
|
161
|
+
if (primary) {
|
|
162
|
+
props.name = primary.name;
|
|
163
|
+
Object.assign(props, photonOSMTags(primary.tag));
|
|
164
|
+
}
|
|
165
|
+
for (const place of input.places) {
|
|
166
|
+
const proj = FORWARD_TAG_PROJECTION[place.tag];
|
|
167
|
+
if (proj && props[proj.key] == null)
|
|
168
|
+
props[proj.key] = place.name;
|
|
169
|
+
}
|
|
170
|
+
if (input.postcode)
|
|
171
|
+
props.postcode = input.postcode;
|
|
172
|
+
if (input.country?.name && props.country == null)
|
|
173
|
+
props.country = input.country.name;
|
|
174
|
+
if (input.country?.code)
|
|
175
|
+
props.countrycode = input.country.code.toLowerCase();
|
|
176
|
+
return props;
|
|
177
|
+
}
|
|
178
|
+
/** {@link photonForwardProperties}, wrapped as a Photon Point `Feature` at the resolved coordinate. #1014. */
|
|
179
|
+
export function photonForwardFeature(input) {
|
|
180
|
+
return photonFeature(input.lon, input.lat, photonForwardProperties(input));
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Assemble a Photon `FeatureCollection` honoring `limit` (#1016): the primary feature first, then ranked alternatives,
|
|
184
|
+
* capped at `limit`. `limit` floors to 1 (Photon always returns at least the best match).
|
|
185
|
+
*/
|
|
186
|
+
export function photonForwardCollection(result, limit) {
|
|
187
|
+
const cap = Math.max(1, Math.floor(limit) || 1);
|
|
188
|
+
const features = [photonForwardFeature(result.primary)];
|
|
189
|
+
for (const alt of result.alternatives) {
|
|
190
|
+
if (features.length >= cap)
|
|
191
|
+
break;
|
|
192
|
+
features.push(photonForwardFeature(alt));
|
|
193
|
+
}
|
|
194
|
+
return photonCollection(features);
|
|
195
|
+
}
|
|
103
196
|
//# sourceMappingURL=index.js.map
|
package/out/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAuB,MAAM,EAAE,MAAM,SAAS,CAAA;AAyErD,MAAM,aAAa,GAAG,EAAE,CAAA;AAExB,SAAS,QAAQ,CAAC,GAAY;IAC7B,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAA;AACnE,CAAC;AAED,SAAS,aAAa,CAAC,GAAY;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAA;IACpF,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;IAEvB,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAC3B,CAAC;AAED,MAAM,KAAK,GAA4B,EAAE,IAAI,EAAE,mBAAmB,EAAE,QAAQ,EAA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AuB,CAAC,MAA2B,EAAE,KAAa;IACjF,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IAC/C,MAAM,QAAQ,GAAG,CAAC,oBAAoB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;IAEvD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;QACvC,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG;YAAE,MAAK;QACjC,QAAQ,CAAC,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAA;IACzC,CAAC;IAED,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAA;AAClC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mailwoman/photon",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "Photon drop-in — a Photon-compatible autocomplete/type-ahead geocoding API (GeoJSON FeatureCollection over /api + /reverse) on the Mailwoman engine. Run it with `npx @mailwoman/photon serve`.",
|
|
5
5
|
"license": "AGPL-3.0-only OR LicenseRef-Commercial",
|
|
6
6
|
"repository": {
|
|
@@ -25,10 +25,11 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@mailwoman/
|
|
29
|
-
"@mailwoman/
|
|
30
|
-
"@mailwoman/resolver
|
|
28
|
+
"@mailwoman/codex": "5.6.0",
|
|
29
|
+
"@mailwoman/neural": "5.6.0",
|
|
30
|
+
"@mailwoman/resolver": "5.6.0",
|
|
31
|
+
"@mailwoman/resolver-wof-sqlite": "5.6.0",
|
|
31
32
|
"express": "^5.2.1",
|
|
32
|
-
"mailwoman": "5.
|
|
33
|
+
"mailwoman": "5.6.0"
|
|
33
34
|
}
|
|
34
35
|
}
|