@meridian-ts/pelias 0.0.0-stage → 1.0.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/CHANGELOG.md +22 -0
- package/LICENSE.md +21 -0
- package/NOTICE +9 -0
- package/README.md +22 -2
- package/dist/index.d.ts +52 -0
- package/dist/index.js +102 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# @meridian-ts/pelias
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 21c5e38: Meridian 1.0: maps and locations for Ember.
|
|
8
|
+
|
|
9
|
+
- `@meridian-ts/ember`: a declarative MapLibre map, a port of `@vis.gl/react-maplibre`. Sources,
|
|
10
|
+
layers, markers, popups, all the controls, clusters, place autocomplete, a geocoder control
|
|
11
|
+
and directions.
|
|
12
|
+
- `@meridian-ts/core`: the provider interfaces for geocoding, places, routing, elevation, time
|
|
13
|
+
zone, static maps and IP location, and `defineMeridian`.
|
|
14
|
+
- Eleven provider adapters: Nominatim, Photon, Pelias, Valhalla, Stadia Maps, MapTiler, Mapbox,
|
|
15
|
+
Google, HERE, Esri and AWS.
|
|
16
|
+
- `@meridian-ts/draw`: draw and edit tools on terra-draw.
|
|
17
|
+
- `@meridian-ts/deck`: deck.gl layers and H3 hexagon clusters.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [21c5e38]
|
|
22
|
+
- @meridian-ts/core@1.0.0
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joe Gaudet
|
|
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/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Meridian
|
|
2
|
+
Copyright (c) 2026 Joe Gaudet. MIT licensed; see LICENSE.md.
|
|
3
|
+
|
|
4
|
+
Meridian is a port of the component API of @vis.gl/react-maplibre (vis.gl contributors, MIT) to
|
|
5
|
+
Ember. It copies the names and the behaviour of that API, and no code.
|
|
6
|
+
|
|
7
|
+
Meridian renders maps with MapLibre GL JS (BSD-3-Clause), which the application installs.
|
|
8
|
+
Each provider adapter calls the public HTTP API of its provider. Meridian depends on no provider
|
|
9
|
+
SDK. The terms of each provider apply to the data that its API returns.
|
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @meridian-ts/pelias
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Meridian adapter for Pelias. See the [guide](https://joegaudet.com/meridian/).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { defineMeridian } from '@meridian-ts/core'
|
|
7
|
+
import { pelias } from '@meridian-ts/pelias'
|
|
8
|
+
|
|
9
|
+
const provider = pelias({ apiKey: 'YOUR_KEY' })
|
|
10
|
+
export const meridian = defineMeridian({ geocoding: provider, places: provider })
|
|
11
|
+
|
|
12
|
+
const places = await meridian.geocoding.forward('Stanley Park, Vancouver')
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The default server is the hosted Pelias of Geocode Earth, which needs a key. To use your own
|
|
16
|
+
Pelias server, pass its root URL as `url`: `pelias({ url: 'https://pelias.example.com' })`.
|
|
17
|
+
To use a proxy that adds the key, pass `baseUrl`.
|
|
18
|
+
|
|
19
|
+
The place functions search the `venue` layer. Pelias has no documented category filter, so
|
|
20
|
+
they ignore `categories`. `places.nearby` uses `/v1/reverse`, which permits a radius of 5 km
|
|
21
|
+
at most.
|
|
22
|
+
|
|
23
|
+
A proxy must send the path without change. It must not decode `%2F` in a path.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type AdapterOptions, type Geocoding, type Http, type Place, type Places, type Provider } from '@meridian-ts/core';
|
|
2
|
+
export interface PeliasOptions extends AdapterOptions {
|
|
3
|
+
/** The root URL of the Pelias server. The default is the hosted server of Geocode Earth. */
|
|
4
|
+
url?: string;
|
|
5
|
+
/** The key of a hosted server. Your own server needs no key. */
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
}
|
|
8
|
+
/** One GeoJSON feature of a Pelias response. */
|
|
9
|
+
export interface PeliasFeature {
|
|
10
|
+
geometry: {
|
|
11
|
+
coordinates: number[];
|
|
12
|
+
};
|
|
13
|
+
/** `[west, south, east, north]` */
|
|
14
|
+
bbox?: number[];
|
|
15
|
+
properties: {
|
|
16
|
+
gid: string;
|
|
17
|
+
name?: string;
|
|
18
|
+
label?: string;
|
|
19
|
+
housenumber?: string;
|
|
20
|
+
street?: string;
|
|
21
|
+
neighbourhood?: string;
|
|
22
|
+
borough?: string;
|
|
23
|
+
locality?: string;
|
|
24
|
+
county?: string;
|
|
25
|
+
region?: string;
|
|
26
|
+
region_a?: string;
|
|
27
|
+
postalcode?: string;
|
|
28
|
+
country?: string;
|
|
29
|
+
/** ISO alpha-2. The Stadia Maps documentation has it; the Pelias documentation does not. */
|
|
30
|
+
country_code?: string;
|
|
31
|
+
/** Kilometers from the query point. Only `/reverse` gives it. */
|
|
32
|
+
distance?: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Changes one Pelias feature into a Meridian `Place`. */
|
|
36
|
+
export declare function toPlace(feature: PeliasFeature): Place;
|
|
37
|
+
/**
|
|
38
|
+
* The geocoding and place functions of a Pelias server. `prefix` is the path of the API on the
|
|
39
|
+
* server: Stadia Maps hosts Pelias at `/geocoding/v1`.
|
|
40
|
+
*
|
|
41
|
+
* The documentation has no category filter, so the place functions ignore `categories`. They
|
|
42
|
+
* search only the `venue` layer.
|
|
43
|
+
*/
|
|
44
|
+
export declare function peliasGeocoding(http: Http, prefix?: string): {
|
|
45
|
+
geocoding: Geocoding;
|
|
46
|
+
places: Places;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The Pelias adapter: forward geocoding, reverse geocoding, autocomplete, and the search and
|
|
50
|
+
* lookup of places (the `venue` layer).
|
|
51
|
+
*/
|
|
52
|
+
export declare function pelias(options?: PeliasOptions): Provider;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { MeridianError, toLngLat, createHttp } from '@meridian-ts/core';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
function toPlace(feature) {
|
|
5
|
+
const p = feature.properties;
|
|
6
|
+
const [lng, lat] = feature.geometry.coordinates;
|
|
7
|
+
const place = {
|
|
8
|
+
id: p.gid,
|
|
9
|
+
name: p.name ?? p.label ?? "",
|
|
10
|
+
label: p.label ?? p.name ?? "",
|
|
11
|
+
location: { lat, lng },
|
|
12
|
+
address: {
|
|
13
|
+
houseNumber: p.housenumber,
|
|
14
|
+
street: p.street,
|
|
15
|
+
district: p.neighbourhood ?? p.borough,
|
|
16
|
+
city: p.locality,
|
|
17
|
+
county: p.county,
|
|
18
|
+
region: p.region,
|
|
19
|
+
regionCode: p.region_a,
|
|
20
|
+
postcode: p.postalcode,
|
|
21
|
+
country: p.country,
|
|
22
|
+
countryCode: p.country_code?.toUpperCase()
|
|
23
|
+
},
|
|
24
|
+
raw: feature
|
|
25
|
+
};
|
|
26
|
+
if (feature.bbox?.length === 4) place.bbox = feature.bbox;
|
|
27
|
+
if (p.distance !== void 0) place.distance = Math.round(p.distance * 1e3);
|
|
28
|
+
return place;
|
|
29
|
+
}
|
|
30
|
+
function peliasGeocoding(http, prefix = "/v1") {
|
|
31
|
+
const list = async (path, query, signal) => {
|
|
32
|
+
const body = await http.get(prefix + path, query, { signal });
|
|
33
|
+
return body.features.map(toPlace);
|
|
34
|
+
};
|
|
35
|
+
const textQuery = (text, o) => {
|
|
36
|
+
const [lon, lat] = o.proximity ? toLngLat(o.proximity) : [];
|
|
37
|
+
const [west, south, east, north] = o.bbox ?? [];
|
|
38
|
+
return {
|
|
39
|
+
text,
|
|
40
|
+
size: o.limit,
|
|
41
|
+
lang: o.language,
|
|
42
|
+
"focus.point.lat": lat,
|
|
43
|
+
"focus.point.lon": lon,
|
|
44
|
+
"boundary.rect.min_lon": west,
|
|
45
|
+
"boundary.rect.min_lat": south,
|
|
46
|
+
"boundary.rect.max_lon": east,
|
|
47
|
+
"boundary.rect.max_lat": north,
|
|
48
|
+
"boundary.country": o.countries?.join(",")
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
geocoding: {
|
|
53
|
+
forward: (query, o = {}) => list("/search", textQuery(query, o), o.signal),
|
|
54
|
+
autocomplete: (text, o = {}) => list("/autocomplete", textQuery(text, o), o.signal),
|
|
55
|
+
reverse: (lngLat, o = {}) => {
|
|
56
|
+
const [lon, lat] = toLngLat(lngLat);
|
|
57
|
+
return list(
|
|
58
|
+
"/reverse",
|
|
59
|
+
{ "point.lat": lat, "point.lon": lon, size: o.limit, lang: o.language },
|
|
60
|
+
o.signal
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
places: {
|
|
65
|
+
search: (text, o = {}) => list("/search", { ...textQuery(text, o), layers: "venue" }, o.signal),
|
|
66
|
+
nearby: (lngLat, o = {}) => {
|
|
67
|
+
const [lon, lat] = toLngLat(lngLat);
|
|
68
|
+
return list(
|
|
69
|
+
"/reverse",
|
|
70
|
+
{
|
|
71
|
+
"point.lat": lat,
|
|
72
|
+
"point.lon": lon,
|
|
73
|
+
// Kilometers. The documentation says that the server permits 5 km at most.
|
|
74
|
+
"boundary.circle.radius": o.radius === void 0 ? void 0 : o.radius / 1e3,
|
|
75
|
+
layers: "venue",
|
|
76
|
+
size: o.limit,
|
|
77
|
+
lang: o.language
|
|
78
|
+
},
|
|
79
|
+
o.signal
|
|
80
|
+
);
|
|
81
|
+
},
|
|
82
|
+
details: async (id, o = {}) => {
|
|
83
|
+
const [place] = await list("/place", { ids: id, lang: o.language }, o.signal);
|
|
84
|
+
if (!place) throw new MeridianError(`no place has the id ${id}`);
|
|
85
|
+
return place;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function pelias(options = {}) {
|
|
91
|
+
const http = createHttp({
|
|
92
|
+
provider: "pelias",
|
|
93
|
+
defaultBaseUrl: options.url ?? "https://api.geocode.earth",
|
|
94
|
+
key: { param: "api_key", value: options.apiKey },
|
|
95
|
+
options
|
|
96
|
+
});
|
|
97
|
+
return { name: "pelias", ...peliasGeocoding(http) };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { pelias, peliasGeocoding, toPlace };
|
|
101
|
+
//# sourceMappingURL=index.js.map
|
|
102
|
+
//# sourceMappingURL=index.js.map
|
|
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EAAI,CAAA,GAAI,EAAC,KAAM;AAC7B,QAAA,MAAM,CAAC,KAAK,CAAA,GAAI,MAAM,KAAK,QAAA,EAAU,EAAE,GAAA,EAAK,EAAA,EAAI,IAAA,EAAM,CAAA,CAAE,QAAA,EAAS,EAAG,EAAE,MAAM,CAAA;AAE5E,QAAA,IAAI,CAAC,KAAA,EAAO,MAAM,IAAI,aAAA,CAAc,CAAA,oBAAA,EAAuB,EAAE,CAAA,CAAE,CAAA;AAC/D,QAAA,OAAO,KAAA;AAAA,MACT;AAAA;AACF,GACF;AACF;AAMO,SAAS,MAAA,CAAO,OAAA,GAAyB,EAAC,EAAa;AAC5D,EAAA,MAAM,OAAO,UAAA,CAAW;AAAA,IACtB,QAAA,EAAU,QAAA;AAAA,IACV,cAAA,EAAgB,QAAQ,GAAA,IAAO,2BAAA;AAAA,IAC/B,KAAK,EAAE,KAAA,EAAO,SAAA,EAAW,KAAA,EAAO,QAAQ,MAAA,EAAO;AAAA,IAC/C;AAAA,GACD,CAAA;AACD,EAAA,OAAO,EAAE,IAAA,EAAM,QAAA,EAAU,GAAG,eAAA,CAAgB,IAAI,CAAA,EAAE;AACpD","file":"index.js","sourcesContent":["// Pelias API: https://github.com/pelias/documentation\n// Endpoints: …/search.md, …/autocomplete.md, …/reverse.md, …/place.md\n// Response: …/response.md. Language: …/language-codes.md\nimport {\n createHttp,\n MeridianError,\n toLngLat,\n type AdapterOptions,\n type GeocodeOptions,\n type Geocoding,\n type Http,\n type Place,\n type Places,\n type Provider,\n type Query,\n} from '@meridian-ts/core'\n\nexport interface PeliasOptions extends AdapterOptions {\n /** The root URL of the Pelias server. The default is the hosted server of Geocode Earth. */\n url?: string\n /** The key of a hosted server. Your own server needs no key. */\n apiKey?: string\n}\n\n/** One GeoJSON feature of a Pelias response. */\nexport interface PeliasFeature {\n geometry: { coordinates: number[] }\n /** `[west, south, east, north]` */\n bbox?: number[]\n properties: {\n gid: string\n name?: string\n label?: string\n housenumber?: string\n street?: string\n neighbourhood?: string\n borough?: string\n locality?: string\n county?: string\n region?: string\n region_a?: string\n postalcode?: string\n country?: string\n /** ISO alpha-2. The Stadia Maps documentation has it; the Pelias documentation does not. */\n country_code?: string\n /** Kilometers from the query point. Only `/reverse` gives it. */\n distance?: number\n }\n}\n\ninterface PeliasResponse {\n features: PeliasFeature[]\n}\n\n/** Changes one Pelias feature into a Meridian `Place`. */\nexport function toPlace(feature: PeliasFeature): Place {\n const p = feature.properties\n const [lng, lat] = feature.geometry.coordinates as [number, number]\n const place: Place = {\n id: p.gid,\n name: p.name ?? p.label ?? '',\n label: p.label ?? p.name ?? '',\n location: { lat, lng },\n address: {\n houseNumber: p.housenumber,\n street: p.street,\n district: p.neighbourhood ?? p.borough,\n city: p.locality,\n county: p.county,\n region: p.region,\n regionCode: p.region_a,\n postcode: p.postalcode,\n country: p.country,\n countryCode: p.country_code?.toUpperCase(),\n },\n raw: feature,\n }\n if (feature.bbox?.length === 4) place.bbox = feature.bbox as [number, number, number, number]\n if (p.distance !== undefined) place.distance = Math.round(p.distance * 1000)\n return place\n}\n\n/**\n * The geocoding and place functions of a Pelias server. `prefix` is the path of the API on the\n * server: Stadia Maps hosts Pelias at `/geocoding/v1`.\n *\n * The documentation has no category filter, so the place functions ignore `categories`. They\n * search only the `venue` layer.\n */\nexport function peliasGeocoding(\n http: Http,\n prefix = '/v1',\n): { geocoding: Geocoding; places: Places } {\n const list = async (path: string, query: Query, signal?: AbortSignal): Promise<Place[]> => {\n const body = await http.get<PeliasResponse>(prefix + path, query, { signal })\n return body.features.map(toPlace)\n }\n\n const textQuery = (text: string, o: GeocodeOptions): Query => {\n const [lon, lat] = o.proximity ? toLngLat(o.proximity) : []\n const [west, south, east, north] = o.bbox ?? []\n return {\n text,\n size: o.limit,\n lang: o.language,\n 'focus.point.lat': lat,\n 'focus.point.lon': lon,\n 'boundary.rect.min_lon': west,\n 'boundary.rect.min_lat': south,\n 'boundary.rect.max_lon': east,\n 'boundary.rect.max_lat': north,\n 'boundary.country': o.countries?.join(','),\n }\n }\n\n return {\n geocoding: {\n forward: (query, o = {}) => list('/search', textQuery(query, o), o.signal),\n autocomplete: (text, o = {}) => list('/autocomplete', textQuery(text, o), o.signal),\n reverse: (lngLat, o = {}) => {\n const [lon, lat] = toLngLat(lngLat)\n return list(\n '/reverse',\n { 'point.lat': lat, 'point.lon': lon, size: o.limit, lang: o.language },\n o.signal,\n )\n },\n },\n places: {\n search: (text, o = {}) =>\n list('/search', { ...textQuery(text, o), layers: 'venue' }, o.signal),\n nearby: (lngLat, o = {}) => {\n const [lon, lat] = toLngLat(lngLat)\n return list(\n '/reverse',\n {\n 'point.lat': lat,\n 'point.lon': lon,\n // Kilometers. The documentation says that the server permits 5 km at most.\n 'boundary.circle.radius': o.radius === undefined ? undefined : o.radius / 1000,\n layers: 'venue',\n size: o.limit,\n lang: o.language,\n },\n o.signal,\n )\n },\n details: async (id, o = {}) => {\n const [place] = await list('/place', { ids: id, lang: o.language }, o.signal)\n // The server gives an empty list, not an error, for an id that it cannot find.\n if (!place) throw new MeridianError(`no place has the id ${id}`)\n return place\n },\n },\n }\n}\n\n/**\n * The Pelias adapter: forward geocoding, reverse geocoding, autocomplete, and the search and\n * lookup of places (the `venue` layer).\n */\nexport function pelias(options: PeliasOptions = {}): Provider {\n const http = createHttp({\n provider: 'pelias',\n defaultBaseUrl: options.url ?? 'https://api.geocode.earth',\n key: { param: 'api_key', value: options.apiKey },\n options,\n })\n return { name: 'pelias', ...peliasGeocoding(http) }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meridian-ts/pelias",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Meridian adapter for Pelias: geocoding, autocomplete and place lookup.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"meridian",
|
|
7
|
+
"pelias",
|
|
8
|
+
"geocoding autocomplete places",
|
|
9
|
+
"gis"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "Joe Gaudet joe@joegaudet.com",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/joegaudet/meridian.git",
|
|
16
|
+
"directory": "packages/pelias"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://joegaudet.com/meridian/",
|
|
19
|
+
"bugs": "https://github.com/joegaudet/meridian/issues",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"CHANGELOG.md",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE.md",
|
|
34
|
+
"NOTICE"
|
|
35
|
+
],
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@meridian-ts/core": "^1.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@meridian-ts/conformance": "0.0.0"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=22.12.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsup"
|
|
51
|
+
}
|
|
6
52
|
}
|