@geospatial-sdk/geocoding 0.0.3-alpha.0 → 0.0.3-alpha.7
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/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/model/index.d.ts +6 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +1 -0
- package/dist/providers/data-gouv-fr.provider.d.ts +49 -0
- package/dist/providers/data-gouv-fr.provider.d.ts.map +1 -0
- package/dist/providers/data-gouv-fr.provider.js +30 -0
- package/dist/providers/data-gouv-fr.provider.test.d.ts +2 -0
- package/dist/providers/data-gouv-fr.provider.test.d.ts.map +1 -0
- package/dist/providers/data-gouv-fr.provider.test.js +89 -0
- package/dist/providers/geoadmin.provider.d.ts +23 -0
- package/dist/providers/geoadmin.provider.d.ts.map +1 -0
- package/dist/providers/geoadmin.provider.js +59 -0
- package/dist/providers/geoadmin.provider.test.d.ts +2 -0
- package/dist/providers/geoadmin.provider.test.d.ts.map +1 -0
- package/dist/providers/geoadmin.provider.test.js +162 -0
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +2 -0
- package/lib/index.ts +1 -0
- package/lib/providers/geoadmin.provider.ts +7 -1
- package/lib/providers/index.ts +0 -1
- package/package.json +8 -5
- package/index.ts +0 -6
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./providers";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/model/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { GeocodingResult } from "../model";
|
|
2
|
+
import { Geometry } from "geojson";
|
|
3
|
+
interface DataGouvFrResponseItem {
|
|
4
|
+
type: "Feature";
|
|
5
|
+
geometry: Geometry;
|
|
6
|
+
properties: {
|
|
7
|
+
label: string;
|
|
8
|
+
score: number;
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
postcode: string;
|
|
12
|
+
citycode: string;
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
city: string;
|
|
16
|
+
district?: string;
|
|
17
|
+
context: string;
|
|
18
|
+
type: string;
|
|
19
|
+
importance: number;
|
|
20
|
+
street: string;
|
|
21
|
+
housenumber?: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface DataGouvFrResponse {
|
|
25
|
+
type: "FeatureCollection";
|
|
26
|
+
version: string;
|
|
27
|
+
features: Array<DataGouvFrResponseItem>;
|
|
28
|
+
attribution: string;
|
|
29
|
+
licence: string;
|
|
30
|
+
query: string;
|
|
31
|
+
filters?: Record<string, string>;
|
|
32
|
+
limit: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reference documentation: https://adresse.data.gouv.fr/api-doc/adresse
|
|
36
|
+
* @property type
|
|
37
|
+
* @property postCode
|
|
38
|
+
* @property cityCode
|
|
39
|
+
* @property limit Default value 15
|
|
40
|
+
*/
|
|
41
|
+
export interface DataGouvFrOptions {
|
|
42
|
+
type?: "housenumber" | "street" | "locality" | "municipality";
|
|
43
|
+
postCode?: string;
|
|
44
|
+
cityCode?: string;
|
|
45
|
+
limit?: number;
|
|
46
|
+
}
|
|
47
|
+
export declare function queryDataGouvFr(input: string, options?: DataGouvFrOptions): Promise<GeocodingResult[]>;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=data-gouv-fr.provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-gouv-fr.provider.d.ts","sourceRoot":"","sources":["../../lib/providers/data-gouv-fr.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,UAAU,sBAAsB;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE;QACV,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;CACf;AAID;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,aAAa,GAAG,QAAQ,GAAG,UAAU,GAAG,cAAc,CAAC;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,eAAe,EAAE,CAAC,CA8B5B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const baseUrl = "https://api-adresse.data.gouv.fr/search/";
|
|
2
|
+
export function queryDataGouvFr(input, options) {
|
|
3
|
+
const baseOptions = {};
|
|
4
|
+
const finalOptions = options ? Object.assign(Object.assign({}, baseOptions), options) : baseOptions;
|
|
5
|
+
const url = new URL(baseUrl);
|
|
6
|
+
url.searchParams.set("q", input);
|
|
7
|
+
if (finalOptions.limit) {
|
|
8
|
+
url.searchParams.set("limit", finalOptions.limit.toString());
|
|
9
|
+
}
|
|
10
|
+
if (finalOptions.type) {
|
|
11
|
+
url.searchParams.set("type", finalOptions.type);
|
|
12
|
+
}
|
|
13
|
+
if (finalOptions.postCode) {
|
|
14
|
+
url.searchParams.set("postcode", finalOptions.postCode);
|
|
15
|
+
}
|
|
16
|
+
if (finalOptions.cityCode) {
|
|
17
|
+
url.searchParams.set("citycode", finalOptions.cityCode);
|
|
18
|
+
}
|
|
19
|
+
return fetch(url.toString())
|
|
20
|
+
.then((response) => response.json())
|
|
21
|
+
.then((response) => response.features.map((feature) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const label = (_a = feature.properties) === null || _a === void 0 ? void 0 : _a.label.replace(/<[^>]*>?/gm, "");
|
|
24
|
+
const geom = feature.geometry;
|
|
25
|
+
return {
|
|
26
|
+
label,
|
|
27
|
+
geom,
|
|
28
|
+
};
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-gouv-fr.provider.test.d.ts","sourceRoot":"","sources":["../../lib/providers/data-gouv-fr.provider.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { queryDataGouvFr } from "./data-gouv-fr.provider";
|
|
11
|
+
const RESULTS_FIXTURE = {
|
|
12
|
+
type: "FeatureCollection",
|
|
13
|
+
version: "draft",
|
|
14
|
+
features: [
|
|
15
|
+
{
|
|
16
|
+
type: "Feature",
|
|
17
|
+
geometry: {
|
|
18
|
+
type: "Point",
|
|
19
|
+
coordinates: [2.290084, 49.897443],
|
|
20
|
+
},
|
|
21
|
+
properties: {
|
|
22
|
+
label: "8 Boulevard du Port 80000 Amiens",
|
|
23
|
+
score: 0.49159121588068583,
|
|
24
|
+
housenumber: "8",
|
|
25
|
+
id: "80021_6590_00008",
|
|
26
|
+
type: "housenumber",
|
|
27
|
+
name: "8 Boulevard du Port",
|
|
28
|
+
postcode: "80000",
|
|
29
|
+
citycode: "80021",
|
|
30
|
+
x: 648952.58,
|
|
31
|
+
y: 6977867.25,
|
|
32
|
+
city: "Amiens",
|
|
33
|
+
context: "80, Somme, Hauts-de-France",
|
|
34
|
+
importance: 0.6706612694243868,
|
|
35
|
+
street: "Boulevard du Port",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
attribution: "BAN",
|
|
40
|
+
licence: "ODbL 1.0",
|
|
41
|
+
query: "8 bd du port",
|
|
42
|
+
limit: 1,
|
|
43
|
+
};
|
|
44
|
+
global.fetch = vi.fn(() => Promise.resolve({
|
|
45
|
+
json: () => Promise.resolve(RESULTS_FIXTURE),
|
|
46
|
+
}));
|
|
47
|
+
describe("queryDataGouvFr", () => {
|
|
48
|
+
let results;
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
vi.clearAllMocks();
|
|
51
|
+
});
|
|
52
|
+
describe("results parsing", () => {
|
|
53
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
results = yield queryDataGouvFr("hello");
|
|
55
|
+
}));
|
|
56
|
+
it("produces geometries, removes html tags from labels", () => {
|
|
57
|
+
expect(results).toEqual([
|
|
58
|
+
{
|
|
59
|
+
geom: {
|
|
60
|
+
type: "Point",
|
|
61
|
+
coordinates: [2.290084, 49.897443],
|
|
62
|
+
},
|
|
63
|
+
label: "8 Boulevard du Port 80000 Amiens",
|
|
64
|
+
},
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe("default options", () => {
|
|
69
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
results = yield queryDataGouvFr("hello world");
|
|
71
|
+
}));
|
|
72
|
+
it("uses default options", () => {
|
|
73
|
+
expect(global.fetch).toHaveBeenCalledWith("https://api-adresse.data.gouv.fr/search/?q=hello+world");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe("custom options", () => {
|
|
77
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
results = yield queryDataGouvFr("hello world", {
|
|
79
|
+
type: "street",
|
|
80
|
+
limit: 32,
|
|
81
|
+
cityCode: "12345",
|
|
82
|
+
postCode: "00000",
|
|
83
|
+
});
|
|
84
|
+
}));
|
|
85
|
+
it("uses given options", () => {
|
|
86
|
+
expect(global.fetch).toHaveBeenCalledWith("https://api-adresse.data.gouv.fr/search/?q=hello+world&limit=32&type=street&postcode=00000&citycode=12345");
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GeocodingResult } from "../model";
|
|
2
|
+
import { FeatureCollection } from "geojson";
|
|
3
|
+
export type GeoadminResponse = FeatureCollection;
|
|
4
|
+
/**
|
|
5
|
+
* Reference documentation: https://api3.geo.admin.ch/services/sdiservices.html#search
|
|
6
|
+
* @property type Default is 'locations'
|
|
7
|
+
* @property sr Defaults to 4326
|
|
8
|
+
* @property limit Default value is 50 for 'locations', 20 for 'featuresearch', 30 for 'layers'
|
|
9
|
+
* @property lang Default is 'en'
|
|
10
|
+
* @property origins Defaults to 'zipcode,gg25'; only applies when type is 'locations'
|
|
11
|
+
* @property features A list of technical layer names; only applies when type is 'featuresearch'
|
|
12
|
+
*/
|
|
13
|
+
export interface GeoadminOptions {
|
|
14
|
+
type?: "locations" | "featuresearch" | "layers";
|
|
15
|
+
sr?: "21781" | "2056" | "4326" | "3857";
|
|
16
|
+
origins?: Array<"zipcode" | "gg25" | "district" | "kantone" | "gazetteer" | "address" | "parcel">;
|
|
17
|
+
limit?: number;
|
|
18
|
+
lang?: "de" | "fr" | "it" | "rm" | "en";
|
|
19
|
+
features?: string[];
|
|
20
|
+
}
|
|
21
|
+
export declare function queryGeoadmin(input: string, options?: GeoadminOptions): Promise<GeocodingResult[]>;
|
|
22
|
+
export declare function sayHello(): string;
|
|
23
|
+
//# sourceMappingURL=geoadmin.provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geoadmin.provider.d.ts","sourceRoot":"","sources":["../../lib/providers/geoadmin.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAQ,iBAAiB,EAAY,MAAM,SAAS,CAAC;AAK5D,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,WAAW,GAAG,eAAe,GAAG,QAAQ,CAAC;IAChD,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACxC,OAAO,CAAC,EAAE,KAAK,CACX,SAAS,GACT,MAAM,GACN,UAAU,GACV,SAAS,GACT,WAAW,GACX,SAAS,GACT,QAAQ,CACX,CAAC;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,eAAe,EAAE,CAAC,CAyC5B;AAED,wBAAgB,QAAQ,WAGvB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// from https://github.com/geoblocks/ga-search
|
|
2
|
+
const baseUrl = "https://api3.geo.admin.ch/rest/services/api/SearchServer";
|
|
3
|
+
export function queryGeoadmin(input, options) {
|
|
4
|
+
const baseOptions = {
|
|
5
|
+
type: "locations",
|
|
6
|
+
sr: "4326",
|
|
7
|
+
origins: ["zipcode", "gg25"],
|
|
8
|
+
lang: "en",
|
|
9
|
+
features: [],
|
|
10
|
+
};
|
|
11
|
+
const finalOptions = options ? Object.assign(Object.assign({}, baseOptions), options) : baseOptions;
|
|
12
|
+
const url = new URL(baseUrl);
|
|
13
|
+
url.searchParams.set("geometryFormat", "geojson");
|
|
14
|
+
url.searchParams.set("type", finalOptions.type);
|
|
15
|
+
url.searchParams.set("searchText", input);
|
|
16
|
+
url.searchParams.set("lang", finalOptions.lang);
|
|
17
|
+
url.searchParams.set("sr", finalOptions.sr);
|
|
18
|
+
if (finalOptions.limit !== undefined) {
|
|
19
|
+
url.searchParams.set("limit", finalOptions.limit.toString());
|
|
20
|
+
}
|
|
21
|
+
switch (finalOptions.type) {
|
|
22
|
+
case "locations":
|
|
23
|
+
url.searchParams.set("origins", finalOptions.origins.join(","));
|
|
24
|
+
break;
|
|
25
|
+
case "featuresearch":
|
|
26
|
+
url.searchParams.set("features", finalOptions.features.join(","));
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
return fetch(url.toString())
|
|
30
|
+
.then((response) => response.json())
|
|
31
|
+
.then((response) => response.features.map((feature) => {
|
|
32
|
+
var _a;
|
|
33
|
+
const label = (_a = feature.properties) === null || _a === void 0 ? void 0 : _a.label.replace(/<[^>]*>?/gm, "");
|
|
34
|
+
const geom = feature.bbox ? bboxToGeometry(feature.bbox) : null;
|
|
35
|
+
return {
|
|
36
|
+
label,
|
|
37
|
+
geom,
|
|
38
|
+
};
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
export function sayHello() {
|
|
42
|
+
console.log("hello");
|
|
43
|
+
return "hello";
|
|
44
|
+
}
|
|
45
|
+
function bboxToGeometry(extent) {
|
|
46
|
+
const [minX, minY, maxX, maxY] = extent;
|
|
47
|
+
return {
|
|
48
|
+
type: "Polygon",
|
|
49
|
+
coordinates: [
|
|
50
|
+
[
|
|
51
|
+
[minX, minY],
|
|
52
|
+
[minX, maxY],
|
|
53
|
+
[maxX, maxY],
|
|
54
|
+
[maxX, minY],
|
|
55
|
+
[minX, minY],
|
|
56
|
+
],
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geoadmin.provider.test.d.ts","sourceRoot":"","sources":["../../lib/providers/geoadmin.provider.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { queryGeoadmin } from "./geoadmin.provider";
|
|
11
|
+
const RESULTS_FIXTURE = {
|
|
12
|
+
type: "FeatureCollection",
|
|
13
|
+
bbox: [8.446892, 47.319034, 8.627209, 47.43514],
|
|
14
|
+
features: [
|
|
15
|
+
{
|
|
16
|
+
geometry: {
|
|
17
|
+
type: "Point",
|
|
18
|
+
coordinates: [8.446892, 47.319034],
|
|
19
|
+
},
|
|
20
|
+
properties: {
|
|
21
|
+
origin: "gazetteer",
|
|
22
|
+
geom_quadindex: "021300220330313020221",
|
|
23
|
+
weight: 1,
|
|
24
|
+
zoomlevel: 10,
|
|
25
|
+
lon: 7.459799289703369,
|
|
26
|
+
detail: "wabern koeniz",
|
|
27
|
+
rank: 5,
|
|
28
|
+
lat: 46.925777435302734,
|
|
29
|
+
num: 1,
|
|
30
|
+
y: 601612.0625,
|
|
31
|
+
x: 197186.8125,
|
|
32
|
+
label: "<i>Populated Place</i> <b>Wabern</b> (BE) - Köniz",
|
|
33
|
+
id: 215754,
|
|
34
|
+
},
|
|
35
|
+
type: "Feature",
|
|
36
|
+
id: 215754,
|
|
37
|
+
bbox: [8.446892, 47.319034, 8.627209, 47.43514],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
geometry: {
|
|
41
|
+
type: "Point",
|
|
42
|
+
coordinates: [8.446892, 47.319034],
|
|
43
|
+
},
|
|
44
|
+
properties: {
|
|
45
|
+
origin: "gg25",
|
|
46
|
+
geom_quadindex: "030003",
|
|
47
|
+
weight: 6,
|
|
48
|
+
zoomlevel: 4294967295,
|
|
49
|
+
lon: 8.527311325073242,
|
|
50
|
+
detail: "zurigo zh",
|
|
51
|
+
rank: 2,
|
|
52
|
+
lat: 47.37721252441406,
|
|
53
|
+
num: 1,
|
|
54
|
+
x: 8.527311325073242,
|
|
55
|
+
y: 47.37721252441406,
|
|
56
|
+
label: "<b>Zurigo (ZH)</b>",
|
|
57
|
+
id: 153,
|
|
58
|
+
featureId: "261",
|
|
59
|
+
},
|
|
60
|
+
type: "Feature",
|
|
61
|
+
id: 153,
|
|
62
|
+
bbox: [8.446892, 47.319034, 8.627209, 47.43514],
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
global.fetch = vi.fn(() => Promise.resolve({
|
|
67
|
+
json: () => Promise.resolve(RESULTS_FIXTURE),
|
|
68
|
+
}));
|
|
69
|
+
describe("queryGeoadmin", () => {
|
|
70
|
+
let results;
|
|
71
|
+
beforeEach(() => {
|
|
72
|
+
vi.clearAllMocks();
|
|
73
|
+
});
|
|
74
|
+
describe("results parsing", () => {
|
|
75
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
+
results = yield queryGeoadmin("hello");
|
|
77
|
+
}));
|
|
78
|
+
it("produces geometries, removes html tags from labels", () => {
|
|
79
|
+
expect(results).toEqual([
|
|
80
|
+
{
|
|
81
|
+
geom: {
|
|
82
|
+
coordinates: [
|
|
83
|
+
[
|
|
84
|
+
[8.446892, 47.319034],
|
|
85
|
+
[8.446892, 47.43514],
|
|
86
|
+
[8.627209, 47.43514],
|
|
87
|
+
[8.627209, 47.319034],
|
|
88
|
+
[8.446892, 47.319034],
|
|
89
|
+
],
|
|
90
|
+
],
|
|
91
|
+
type: "Polygon",
|
|
92
|
+
},
|
|
93
|
+
label: "Populated Place Wabern (BE) - Köniz",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
geom: {
|
|
97
|
+
coordinates: [
|
|
98
|
+
[
|
|
99
|
+
[8.446892, 47.319034],
|
|
100
|
+
[8.446892, 47.43514],
|
|
101
|
+
[8.627209, 47.43514],
|
|
102
|
+
[8.627209, 47.319034],
|
|
103
|
+
[8.446892, 47.319034],
|
|
104
|
+
],
|
|
105
|
+
],
|
|
106
|
+
type: "Polygon",
|
|
107
|
+
},
|
|
108
|
+
label: "Zurigo (ZH)",
|
|
109
|
+
},
|
|
110
|
+
]);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe("default options", () => {
|
|
114
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
115
|
+
results = yield queryGeoadmin("hello world");
|
|
116
|
+
}));
|
|
117
|
+
it("uses default options", () => {
|
|
118
|
+
expect(global.fetch).toHaveBeenCalledWith("https://api3.geo.admin.ch/rest/services/api/SearchServer?geometryFormat=geojson&type=locations&searchText=hello+world&lang=en&sr=4326&origins=zipcode%2Cgg25");
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
describe("locations search", () => {
|
|
122
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
+
results = yield queryGeoadmin("hello world", {
|
|
124
|
+
type: "locations",
|
|
125
|
+
lang: "de",
|
|
126
|
+
origins: ["district", "address"],
|
|
127
|
+
limit: 32,
|
|
128
|
+
sr: "21781",
|
|
129
|
+
});
|
|
130
|
+
}));
|
|
131
|
+
it("uses given options", () => {
|
|
132
|
+
expect(global.fetch).toHaveBeenCalledWith("https://api3.geo.admin.ch/rest/services/api/SearchServer?geometryFormat=geojson&type=locations&searchText=hello+world&lang=de&sr=21781&limit=32&origins=district%2Caddress");
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
describe("feature search", () => {
|
|
136
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
137
|
+
results = yield queryGeoadmin("hello world", {
|
|
138
|
+
type: "featuresearch",
|
|
139
|
+
lang: "de",
|
|
140
|
+
features: ["abc", "def"],
|
|
141
|
+
limit: 32,
|
|
142
|
+
sr: "21781",
|
|
143
|
+
});
|
|
144
|
+
}));
|
|
145
|
+
it("uses given options", () => {
|
|
146
|
+
expect(global.fetch).toHaveBeenCalledWith("https://api3.geo.admin.ch/rest/services/api/SearchServer?geometryFormat=geojson&type=featuresearch&searchText=hello+world&lang=de&sr=21781&limit=32&features=abc%2Cdef");
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
describe("layers search", () => {
|
|
150
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
|
+
results = yield queryGeoadmin("hello world", {
|
|
152
|
+
type: "layers",
|
|
153
|
+
lang: "de",
|
|
154
|
+
limit: 32,
|
|
155
|
+
sr: "21781",
|
|
156
|
+
});
|
|
157
|
+
}));
|
|
158
|
+
it("uses given options", () => {
|
|
159
|
+
expect(global.fetch).toHaveBeenCalledWith("https://api3.geo.admin.ch/rest/services/api/SearchServer?geometryFormat=geojson&type=layers&searchText=hello+world&lang=de&sr=21781&limit=32");
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC"}
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./providers";
|
|
@@ -45,7 +45,7 @@ export function queryGeoadmin(
|
|
|
45
45
|
};
|
|
46
46
|
const finalOptions = options ? { ...baseOptions, ...options } : baseOptions;
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
const url = new URL(baseUrl);
|
|
49
49
|
url.searchParams.set("geometryFormat", "geojson");
|
|
50
50
|
url.searchParams.set("type", finalOptions.type!);
|
|
51
51
|
url.searchParams.set("searchText", input);
|
|
@@ -78,6 +78,12 @@ export function queryGeoadmin(
|
|
|
78
78
|
);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
export function sayHello() {
|
|
82
|
+
console.log("hello")
|
|
83
|
+
return "hello";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
81
87
|
function bboxToGeometry(extent: BBox): Geometry {
|
|
82
88
|
const [minX, minY, maxX, maxY] = extent;
|
|
83
89
|
return {
|
package/lib/providers/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geospatial-sdk/geocoding",
|
|
3
|
-
"version": "0.0.3-alpha.
|
|
3
|
+
"version": "0.0.3-alpha.7+1709061",
|
|
4
4
|
"description": "Geocoding-related components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"geocoding"
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"author": "Olivia <olivia.guyot@camptocamp.com>",
|
|
9
9
|
"homepage": "https://github.com/jahow/geospatial-sdk#readme",
|
|
10
10
|
"license": "BSD-3-Clause",
|
|
11
|
-
"main": "index.
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"typings": "dist/index.d.ts",
|
|
12
13
|
"type": "module",
|
|
13
14
|
"publishConfig": {
|
|
14
15
|
"access": "public"
|
|
@@ -17,17 +18,19 @@
|
|
|
17
18
|
"lib": "lib"
|
|
18
19
|
},
|
|
19
20
|
"files": [
|
|
20
|
-
"lib"
|
|
21
|
+
"lib",
|
|
22
|
+
"dist"
|
|
21
23
|
],
|
|
22
24
|
"repository": {
|
|
23
25
|
"type": "git",
|
|
24
26
|
"url": "git+https://github.com/jahow/geospatial-sdk.git"
|
|
25
27
|
},
|
|
26
28
|
"scripts": {
|
|
27
|
-
"test": "vitest"
|
|
29
|
+
"test": "vitest",
|
|
30
|
+
"build": "tsc"
|
|
28
31
|
},
|
|
29
32
|
"bugs": {
|
|
30
33
|
"url": "https://github.com/jahow/geospatial-sdk/issues"
|
|
31
34
|
},
|
|
32
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "1709061540a7fda4b8bf013524df7d373f0cd0a0"
|
|
33
36
|
}
|