@dacostafilipe/react-geoportail 0.1.4 → 0.1.6
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 +6 -2
- package/dist/components/GeoportailMap.d.ts +2 -2
- package/dist/hooks/useGeocode.d.ts +1 -1
- package/dist/hooks/useLuxApi.d.ts +3 -3
- package/dist/hooks/useReverseGeocode.d.ts +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/react-geoportail.js +253 -208
- package/dist/react-geoportail.js.map +1 -1
- package/dist/react-geoportail.umd.cjs +2 -2
- package/dist/react-geoportail.umd.cjs.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/lux.d.ts +89 -0
- package/dist/utils/loader.d.ts +2 -2
- package/package.json +2 -1
package/dist/react-geoportail.js
CHANGED
|
@@ -1,178 +1,223 @@
|
|
|
1
|
-
import { jsx as T, jsxs as
|
|
2
|
-
import { useState as F, useEffect as S, forwardRef as
|
|
3
|
-
const
|
|
4
|
-
let
|
|
5
|
-
function
|
|
6
|
-
return
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if (typeof document > "u") {
|
|
12
|
-
t(new Error("loadLuxApi must run in a browser environment"));
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (document.getElementById(j)) {
|
|
16
|
-
V(c, t);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const n = document.createElement("script");
|
|
20
|
-
n.id = j, n.src = B, n.async = !0, n.onload = () => V(c, t), n.onerror = () => {
|
|
21
|
-
R = null, t(new Error(`Failed to load Geoportail API from ${B}`));
|
|
22
|
-
}, document.head.appendChild(n);
|
|
23
|
-
}), R);
|
|
1
|
+
import { jsx as T, jsxs as z } from "react/jsx-runtime";
|
|
2
|
+
import { useState as F, useEffect as S, forwardRef as et, useRef as R, useImperativeHandle as ot, useCallback as I } from "react";
|
|
3
|
+
const st = "https://apiv3.geoportail.lu/", rt = "https", at = "https://apiv3.geoportail.lu/static-ngeo/build/fr.json", ct = "https://apiv3.geoportail.lu/static-ngeo/build/apiv3.css", it = "https://apiv3.geoportail.lu/static-ngeo/build/vendor.js", lt = "https://apiv3.geoportail.lu/static-ngeo/build/apiv3.js", ut = "geoportail-apiv3-css", dt = "geoportail-apiv3-vendor", ft = "geoportail-apiv3-script", _ = "data-geoportail-status";
|
|
4
|
+
let A = null;
|
|
5
|
+
function ht() {
|
|
6
|
+
return A || (typeof window > "u" || typeof document > "u" ? Promise.reject(new Error("loadLuxApi must be called in a browser environment")) : (A = gt().catch((n) => {
|
|
7
|
+
throw A = null, n instanceof Error ? n : new Error(String(n));
|
|
8
|
+
}), A));
|
|
24
9
|
}
|
|
25
|
-
function
|
|
10
|
+
function pt(n, e) {
|
|
26
11
|
let i = 0;
|
|
27
|
-
const
|
|
12
|
+
const s = () => {
|
|
28
13
|
if (window.lux) {
|
|
29
|
-
|
|
14
|
+
n();
|
|
30
15
|
return;
|
|
31
16
|
}
|
|
32
17
|
if (i++ >= 100) {
|
|
33
|
-
|
|
18
|
+
A = null, e(new Error("Timed out waiting for window.lux to be defined"));
|
|
34
19
|
return;
|
|
35
20
|
}
|
|
36
|
-
setTimeout(
|
|
21
|
+
setTimeout(s, 50);
|
|
22
|
+
};
|
|
23
|
+
s();
|
|
24
|
+
}
|
|
25
|
+
async function gt() {
|
|
26
|
+
if (window.lux) {
|
|
27
|
+
W(window.lux);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
await Lt(ut, ct), await V(dt, it), await V(ft, lt), await wt(), W(window.lux);
|
|
31
|
+
}
|
|
32
|
+
function wt() {
|
|
33
|
+
return new Promise((n, e) => {
|
|
34
|
+
pt(n, e);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function W(n) {
|
|
38
|
+
n.setBaseUrl(st, rt), n.setI18nUrl(at);
|
|
39
|
+
}
|
|
40
|
+
function V(n, e) {
|
|
41
|
+
const o = document.getElementById(n);
|
|
42
|
+
return o ? Y(o, e, "script") : new Promise((i, s) => {
|
|
43
|
+
const t = document.createElement("script");
|
|
44
|
+
t.id = n, t.src = e, t.async = !1, t.setAttribute(_, "loading"), X(
|
|
45
|
+
t,
|
|
46
|
+
() => i(),
|
|
47
|
+
() => s(new Error(`Failed to load Geoportail script from ${e}`)),
|
|
48
|
+
"script"
|
|
49
|
+
), document.head.appendChild(t);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function Lt(n, e) {
|
|
53
|
+
const o = document.getElementById(n);
|
|
54
|
+
return o ? Y(o, e, "stylesheet") : new Promise((i, s) => {
|
|
55
|
+
const t = document.createElement("link");
|
|
56
|
+
t.id = n, t.rel = "stylesheet", t.href = e, t.setAttribute(_, "loading"), X(
|
|
57
|
+
t,
|
|
58
|
+
() => i(),
|
|
59
|
+
() => s(new Error(`Failed to load Geoportail stylesheet from ${e}`)),
|
|
60
|
+
"stylesheet"
|
|
61
|
+
), document.head.appendChild(t);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function Y(n, e, o) {
|
|
65
|
+
const i = n.getAttribute(_);
|
|
66
|
+
return i === "loaded" ? Promise.resolve() : i === "error" ? (n.remove(), Promise.reject(new Error(`Failed to load Geoportail ${o} from ${e}`))) : new Promise((s, t) => {
|
|
67
|
+
X(
|
|
68
|
+
n,
|
|
69
|
+
() => s(),
|
|
70
|
+
() => t(new Error(`Failed to load Geoportail ${o} from ${e}`)),
|
|
71
|
+
o
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function X(n, e, o, i) {
|
|
76
|
+
const s = () => {
|
|
77
|
+
n.setAttribute(_, "loaded"), f(), e();
|
|
78
|
+
}, t = () => {
|
|
79
|
+
n.setAttribute(_, "error"), f(), n.remove(), o();
|
|
80
|
+
}, f = () => {
|
|
81
|
+
n.removeEventListener("load", s), n.removeEventListener("error", t);
|
|
37
82
|
};
|
|
38
|
-
|
|
83
|
+
return n.addEventListener("load", s, { once: !0 }), n.addEventListener("error", t, { once: !0 }), i === "stylesheet" ? n.sheet && s() : n.dataset.geoportailStatus === "loaded" && s(), f;
|
|
39
84
|
}
|
|
40
|
-
function
|
|
41
|
-
const [
|
|
85
|
+
function Et() {
|
|
86
|
+
const [n, e] = F({
|
|
42
87
|
status: "loading",
|
|
43
88
|
lux: null,
|
|
44
89
|
error: null
|
|
45
90
|
});
|
|
46
91
|
return S(() => {
|
|
47
|
-
let
|
|
48
|
-
return
|
|
49
|
-
|
|
92
|
+
let o = !1;
|
|
93
|
+
return ht().then(() => {
|
|
94
|
+
o || e({ status: "ready", lux: window.lux, error: null });
|
|
50
95
|
}).catch((i) => {
|
|
51
|
-
|
|
96
|
+
o || e({
|
|
52
97
|
status: "error",
|
|
53
98
|
lux: null,
|
|
54
99
|
error: i instanceof Error ? i : new Error(String(i))
|
|
55
100
|
});
|
|
56
101
|
}), () => {
|
|
57
|
-
|
|
102
|
+
o = !0;
|
|
58
103
|
};
|
|
59
|
-
}, []),
|
|
104
|
+
}, []), n;
|
|
60
105
|
}
|
|
61
|
-
const
|
|
62
|
-
function
|
|
63
|
-
return
|
|
106
|
+
const k = 8e4, Z = 1e5, q = 6.16666666666667, J = 49.8333333333333, U = 1, v = 6378388, j = 1 / 297, O = v * (1 - j), E = 1 - O * O / (v * v), C = -87, D = -98, K = -121;
|
|
107
|
+
function M(n) {
|
|
108
|
+
return n * Math.PI / 180;
|
|
64
109
|
}
|
|
65
|
-
function
|
|
66
|
-
return
|
|
110
|
+
function y(n) {
|
|
111
|
+
return n * 180 / Math.PI;
|
|
67
112
|
}
|
|
68
|
-
function
|
|
69
|
-
const
|
|
113
|
+
function mt(n, e) {
|
|
114
|
+
const o = M(n), i = M(e), s = Math.sin(o), t = Math.cos(o), f = Math.sin(i), h = Math.cos(i), r = 6378137, c = 1 / 298.257223563, p = r * (1 - c), l = 1 - p * p / (r * r), d = v - r, a = j - c, g = r / Math.sqrt(1 - l * s * s), w = 1 / (r * (1 - l) / Math.pow(1 - l * s * s, 1.5)) * (g * (l / (1 - l)) * s * t * (d / r) + (g / r + 1) * s * t * a * (r / p) - (C * s * h + D * s * f - K * t)), L = 1 / (g * t) * (-C * f + D * h);
|
|
70
115
|
return {
|
|
71
|
-
lat:
|
|
72
|
-
lon:
|
|
116
|
+
lat: n + y(w),
|
|
117
|
+
lon: e + y(L)
|
|
73
118
|
};
|
|
74
119
|
}
|
|
75
|
-
function
|
|
76
|
-
const
|
|
120
|
+
function vt(n, e) {
|
|
121
|
+
const o = M(n), i = M(e), s = Math.sin(o), t = Math.cos(o), f = Math.sin(i), h = Math.cos(i), r = v / Math.sqrt(1 - E * s * s), c = v * (1 - E) / Math.pow(1 - E * s * s, 1.5), p = 6378137 - v, d = 1 / 298.257223563 - j, a = 1 / c * (r * (E / (1 - E)) * s * t * (p / v) + (r / v + 1) * s * t * d * (v / O) + (C * s * h + D * s * f - K * t)), g = 1 / (r * t) * (C * f - D * h);
|
|
77
122
|
return {
|
|
78
|
-
lat:
|
|
79
|
-
lon:
|
|
123
|
+
lat: n + y(a),
|
|
124
|
+
lon: e + y(g)
|
|
80
125
|
};
|
|
81
126
|
}
|
|
82
|
-
function
|
|
83
|
-
const
|
|
84
|
-
return { easting: w, northing:
|
|
127
|
+
function Mt(n, e) {
|
|
128
|
+
const o = M(n), i = M(e), s = M(q), t = M(J), f = Math.sin(o), h = Math.cos(o), r = Math.tan(o), c = v / Math.sqrt(1 - E * f * f), p = r * r, l = E / (1 - E) * h * h, d = i - s, a = h * d, g = G(o), m = G(t), w = k + U * c * (a + a * a * a * (1 - p + l) / 6 + a * a * a * a * a * (5 - 18 * p + p * p + 72 * l) / 120), L = Z + U * (g - m + c * r * (a * a / 2 + a * a * a * a * (5 - p + 9 * l + 4 * l * l) / 24 + a * a * a * a * a * a * (61 - 58 * p + p * p + 600 * l) / 720));
|
|
129
|
+
return { easting: w, northing: L };
|
|
85
130
|
}
|
|
86
|
-
function
|
|
87
|
-
const
|
|
88
|
-
return { lat:
|
|
131
|
+
function xt(n, e) {
|
|
132
|
+
const o = n - k, i = e - Z, s = M(J), t = M(q), r = (G(s) + i / U) / (v * (1 - E / 4 - 3 * E * E / 64)), c = (1 - Math.sqrt(1 - E)) / (1 + Math.sqrt(1 - E)), p = r + (3 * c / 2 - 27 * c * c * c / 32) * Math.sin(2 * r) + (21 * c * c / 16 - 55 * c * c * c * c / 32) * Math.sin(4 * r) + 151 * c * c * c / 96 * Math.sin(6 * r), l = Math.sin(p), d = Math.cos(p), a = Math.tan(p), g = v / Math.sqrt(1 - E * l * l), m = a * a, w = E / (1 - E) * d * d, L = v * (1 - E) / Math.pow(1 - E * l * l, 1.5), u = o / (g * U), x = p - g * a / L * (u * u / 2 - u * u * u * u * (5 + 3 * m + 10 * w - 4 * w * w) / 24 + u * u * u * u * u * u * (61 + 90 * m + 298 * w + 45 * m * m) / 720), b = t + (u - u * u * u * (1 + 2 * m + w) / 6 + u * u * u * u * u * (5 - 2 * w + 28 * m - 3 * w * w) / 120) / d;
|
|
133
|
+
return { lat: y(x), lon: y(b) };
|
|
89
134
|
}
|
|
90
|
-
function
|
|
91
|
-
const
|
|
92
|
-
return
|
|
135
|
+
function G(n) {
|
|
136
|
+
const e = E, o = e * e, i = o * e;
|
|
137
|
+
return v * ((1 - e / 4 - 3 * o / 64 - 5 * i / 256) * n - (3 * e / 8 + 3 * o / 32 + 45 * i / 1024) * Math.sin(2 * n) + (15 * o / 256 + 45 * i / 1024) * Math.sin(4 * n) - 35 * i / 3072 * Math.sin(6 * n));
|
|
93
138
|
}
|
|
94
|
-
function
|
|
95
|
-
const
|
|
96
|
-
return
|
|
139
|
+
function P(n, e) {
|
|
140
|
+
const o = mt(n, e);
|
|
141
|
+
return Mt(o.lat, o.lon);
|
|
97
142
|
}
|
|
98
|
-
function
|
|
99
|
-
const
|
|
100
|
-
return
|
|
143
|
+
function Q(n, e) {
|
|
144
|
+
const o = xt(n, e);
|
|
145
|
+
return vt(o.lat, o.lon);
|
|
101
146
|
}
|
|
102
|
-
const
|
|
147
|
+
const bt = { lat: 49.6116, lon: 6.1319 }, Rt = "basemap_2015_global", Ut = et(
|
|
103
148
|
function({
|
|
104
|
-
center:
|
|
105
|
-
zoom:
|
|
106
|
-
bgLayer: i =
|
|
107
|
-
markerMode:
|
|
108
|
-
markerPosition:
|
|
109
|
-
onMarkerPlace:
|
|
110
|
-
className:
|
|
111
|
-
style:
|
|
112
|
-
layers:
|
|
113
|
-
},
|
|
114
|
-
const
|
|
115
|
-
return
|
|
116
|
-
if (
|
|
117
|
-
const
|
|
118
|
-
target:
|
|
149
|
+
center: e = bt,
|
|
150
|
+
zoom: o = 12,
|
|
151
|
+
bgLayer: i = Rt,
|
|
152
|
+
markerMode: s = "none",
|
|
153
|
+
markerPosition: t,
|
|
154
|
+
onMarkerPlace: f,
|
|
155
|
+
className: h,
|
|
156
|
+
style: r,
|
|
157
|
+
layers: c
|
|
158
|
+
}, p) {
|
|
159
|
+
const l = Et(), d = R(null), a = R(null), g = R(null), m = R(null), w = R(f);
|
|
160
|
+
return w.current = f, S(() => {
|
|
161
|
+
if (l.status !== "ready" || !d.current) return;
|
|
162
|
+
const L = l.lux, { easting: u, northing: x } = P(e.lat, e.lon), b = new L.Map({
|
|
163
|
+
target: d.current,
|
|
119
164
|
bgLayer: i,
|
|
120
|
-
zoom:
|
|
121
|
-
position: [
|
|
122
|
-
...
|
|
165
|
+
zoom: o,
|
|
166
|
+
position: [u, x],
|
|
167
|
+
...c && c.length > 0 ? { layers: c, layerOpacities: c.map(() => 1) } : {}
|
|
123
168
|
});
|
|
124
|
-
return
|
|
125
|
-
|
|
169
|
+
return a.current = b, () => {
|
|
170
|
+
a.current = null, g.current = null, m.current = null;
|
|
126
171
|
};
|
|
127
|
-
}, [
|
|
128
|
-
const
|
|
129
|
-
if (!
|
|
130
|
-
if (
|
|
131
|
-
|
|
172
|
+
}, [l.status]), S(() => {
|
|
173
|
+
const L = a.current;
|
|
174
|
+
if (!L || l.status !== "ready") return;
|
|
175
|
+
if (m.current && (L.un("singleclick", m.current), m.current = null), s === "none") {
|
|
176
|
+
At(L, g);
|
|
132
177
|
return;
|
|
133
178
|
}
|
|
134
|
-
const
|
|
135
|
-
if (
|
|
136
|
-
const
|
|
137
|
-
var
|
|
138
|
-
const N =
|
|
179
|
+
const u = t ?? (s === "fixed" ? e : void 0);
|
|
180
|
+
if (u && H(L, u, g), s === "click") {
|
|
181
|
+
const x = (...b) => {
|
|
182
|
+
var B;
|
|
183
|
+
const N = b[0];
|
|
139
184
|
if (!N.coordinate) return;
|
|
140
|
-
const [
|
|
141
|
-
|
|
185
|
+
const [tt, nt] = N.coordinate, $ = Q(tt, nt);
|
|
186
|
+
H(L, $, g), (B = w.current) == null || B.call(w, $);
|
|
142
187
|
};
|
|
143
|
-
|
|
188
|
+
m.current = x, L.on("singleclick", x);
|
|
144
189
|
}
|
|
145
190
|
}, [
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
]), ot(
|
|
153
|
-
getLuxMap: () =>
|
|
154
|
-
setCenter(
|
|
155
|
-
const
|
|
156
|
-
if (!
|
|
157
|
-
const { easting:
|
|
158
|
-
|
|
191
|
+
l.status,
|
|
192
|
+
s,
|
|
193
|
+
t == null ? void 0 : t.lat,
|
|
194
|
+
t == null ? void 0 : t.lon,
|
|
195
|
+
e.lat,
|
|
196
|
+
e.lon
|
|
197
|
+
]), ot(p, () => ({
|
|
198
|
+
getLuxMap: () => a.current,
|
|
199
|
+
setCenter(L) {
|
|
200
|
+
const u = a.current;
|
|
201
|
+
if (!u) return;
|
|
202
|
+
const { easting: x, northing: b } = P(L.lat, L.lon);
|
|
203
|
+
u.getView().setCenter([x, b]);
|
|
159
204
|
},
|
|
160
|
-
setZoom(
|
|
161
|
-
var
|
|
162
|
-
(
|
|
205
|
+
setZoom(L) {
|
|
206
|
+
var u;
|
|
207
|
+
(u = a.current) == null || u.getView().setZoom(L);
|
|
163
208
|
}
|
|
164
|
-
})),
|
|
209
|
+
})), l.status === "error" ? /* @__PURE__ */ T(
|
|
165
210
|
"div",
|
|
166
211
|
{
|
|
167
|
-
className:
|
|
168
|
-
style: { display: "flex", alignItems: "center", justifyContent: "center", background: "#f5f5f5", ...
|
|
169
|
-
children: /* @__PURE__ */
|
|
212
|
+
className: h,
|
|
213
|
+
style: { display: "flex", alignItems: "center", justifyContent: "center", background: "#f5f5f5", ...r },
|
|
214
|
+
children: /* @__PURE__ */ z("span", { style: { color: "#c00" }, children: [
|
|
170
215
|
"Failed to load Geoportail API: ",
|
|
171
|
-
|
|
216
|
+
l.error.message
|
|
172
217
|
] })
|
|
173
218
|
}
|
|
174
|
-
) : /* @__PURE__ */
|
|
175
|
-
|
|
219
|
+
) : /* @__PURE__ */ z("div", { style: { position: "relative", ...r }, className: h, children: [
|
|
220
|
+
l.status === "loading" && /* @__PURE__ */ T(
|
|
176
221
|
"div",
|
|
177
222
|
{
|
|
178
223
|
style: {
|
|
@@ -190,143 +235,143 @@ const ut = { lat: 49.6116, lon: 6.1319 }, dt = "basemap_2015_global", Mt = nt(
|
|
|
190
235
|
/* @__PURE__ */ T(
|
|
191
236
|
"div",
|
|
192
237
|
{
|
|
193
|
-
|
|
238
|
+
ref: d,
|
|
194
239
|
style: { width: "100%", height: "100%" }
|
|
195
240
|
}
|
|
196
241
|
)
|
|
197
242
|
] });
|
|
198
243
|
}
|
|
199
244
|
);
|
|
200
|
-
function
|
|
245
|
+
function H(n, e, o) {
|
|
201
246
|
const i = window.ol;
|
|
202
247
|
if (!i) return;
|
|
203
|
-
const { easting:
|
|
204
|
-
if (
|
|
205
|
-
|
|
248
|
+
const { easting: s, northing: t } = P(e.lat, e.lon);
|
|
249
|
+
if (o.current) {
|
|
250
|
+
o.current.setPosition([s, t]);
|
|
206
251
|
return;
|
|
207
252
|
}
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
element:
|
|
253
|
+
const f = document.createElement("div");
|
|
254
|
+
f.innerHTML = yt, f.style.cssText = "cursor:pointer;transform:translate(-50%,-100%);line-height:0;";
|
|
255
|
+
const h = new i.Overlay({
|
|
256
|
+
element: f,
|
|
212
257
|
positioning: "bottom-center",
|
|
213
258
|
stopEvent: !1
|
|
214
259
|
});
|
|
215
|
-
|
|
260
|
+
h.setPosition([s, t]), n.addOverlay(h), o.current = h;
|
|
216
261
|
}
|
|
217
|
-
function
|
|
218
|
-
!
|
|
262
|
+
function At(n, e) {
|
|
263
|
+
!e.current || !window.ol || (e.current.setPosition(void 0), e.current = null);
|
|
219
264
|
}
|
|
220
|
-
const
|
|
265
|
+
const yt = `<svg xmlns="http://www.w3.org/2000/svg" width="30" height="40" viewBox="0 0 30 40">
|
|
221
266
|
<path d="M15 0C7.268 0 1 6.268 1 14c0 10.5 14 26 14 26S29 24.5 29 14C29 6.268 22.732 0 15 0z"
|
|
222
267
|
fill="#e53935" stroke="#b71c1c" stroke-width="1.5"/>
|
|
223
268
|
<circle cx="15" cy="14" r="5" fill="white"/>
|
|
224
|
-
</svg>`,
|
|
225
|
-
function
|
|
226
|
-
const [
|
|
269
|
+
</svg>`, St = "https://api.geoportail.lu/geocoder/reverseGeocode";
|
|
270
|
+
function Ct() {
|
|
271
|
+
const [n, e] = F({
|
|
227
272
|
status: "idle",
|
|
228
273
|
address: null,
|
|
229
274
|
error: null
|
|
230
|
-
}),
|
|
275
|
+
}), o = R(null);
|
|
231
276
|
S(() => () => {
|
|
232
|
-
var
|
|
233
|
-
(
|
|
277
|
+
var t;
|
|
278
|
+
(t = o.current) == null || t.abort();
|
|
234
279
|
}, []);
|
|
235
|
-
const i =
|
|
236
|
-
var
|
|
237
|
-
(
|
|
238
|
-
const
|
|
239
|
-
|
|
280
|
+
const i = I(async (t) => {
|
|
281
|
+
var h, r;
|
|
282
|
+
(h = o.current) == null || h.abort();
|
|
283
|
+
const f = new AbortController();
|
|
284
|
+
o.current = f, e({ status: "loading", address: null, error: null });
|
|
240
285
|
try {
|
|
241
|
-
const { easting:
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
if (!
|
|
245
|
-
throw new Error(`Reverse geocode request failed: ${
|
|
246
|
-
const
|
|
247
|
-
if (!
|
|
286
|
+
const { easting: c, northing: p } = P(t.lat, t.lon), l = new URL(St);
|
|
287
|
+
l.searchParams.set("easting", String(c)), l.searchParams.set("northing", String(p));
|
|
288
|
+
const d = await fetch(l.toString(), { signal: f.signal });
|
|
289
|
+
if (!d.ok)
|
|
290
|
+
throw new Error(`Reverse geocode request failed: ${d.status} ${d.statusText}`);
|
|
291
|
+
const g = (r = (await d.json()).results) == null ? void 0 : r[0];
|
|
292
|
+
if (!g)
|
|
248
293
|
throw new Error("No results returned for this position");
|
|
249
|
-
|
|
294
|
+
e({
|
|
250
295
|
status: "success",
|
|
251
296
|
address: {
|
|
252
|
-
label:
|
|
253
|
-
distance:
|
|
254
|
-
easting:
|
|
255
|
-
northing:
|
|
297
|
+
label: g.name ?? "",
|
|
298
|
+
distance: g.distance ?? 0,
|
|
299
|
+
easting: g.easting,
|
|
300
|
+
northing: g.northing
|
|
256
301
|
},
|
|
257
302
|
error: null
|
|
258
303
|
});
|
|
259
|
-
} catch (
|
|
260
|
-
if (
|
|
261
|
-
|
|
304
|
+
} catch (c) {
|
|
305
|
+
if (c instanceof DOMException && c.name === "AbortError") return;
|
|
306
|
+
e({
|
|
262
307
|
status: "error",
|
|
263
308
|
address: null,
|
|
264
|
-
error:
|
|
309
|
+
error: c instanceof Error ? c : new Error(String(c))
|
|
265
310
|
});
|
|
266
311
|
}
|
|
267
|
-
}, []),
|
|
268
|
-
var
|
|
269
|
-
(
|
|
312
|
+
}, []), s = I(() => {
|
|
313
|
+
var t;
|
|
314
|
+
(t = o.current) == null || t.abort(), e({ status: "idle", address: null, error: null });
|
|
270
315
|
}, []);
|
|
271
|
-
return { state:
|
|
316
|
+
return { state: n, lookup: i, reset: s };
|
|
272
317
|
}
|
|
273
|
-
const
|
|
274
|
-
function
|
|
275
|
-
const [
|
|
318
|
+
const _t = "https://apiv3.geoportail.lu/geocode/search";
|
|
319
|
+
function Dt() {
|
|
320
|
+
const [n, e] = F({
|
|
276
321
|
status: "idle",
|
|
277
322
|
results: null,
|
|
278
323
|
error: null
|
|
279
|
-
}),
|
|
324
|
+
}), o = R(null);
|
|
280
325
|
S(() => () => {
|
|
281
|
-
var
|
|
282
|
-
(
|
|
326
|
+
var t;
|
|
327
|
+
(t = o.current) == null || t.abort();
|
|
283
328
|
}, []);
|
|
284
|
-
const i =
|
|
285
|
-
var
|
|
286
|
-
(
|
|
287
|
-
const
|
|
288
|
-
|
|
329
|
+
const i = I(async (t) => {
|
|
330
|
+
var h;
|
|
331
|
+
(h = o.current) == null || h.abort();
|
|
332
|
+
const f = new AbortController();
|
|
333
|
+
o.current = f, e({ status: "loading", results: null, error: null });
|
|
289
334
|
try {
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
if (!
|
|
294
|
-
throw new Error(`Geocode request failed: ${
|
|
295
|
-
const
|
|
296
|
-
var
|
|
335
|
+
const r = new URL(_t);
|
|
336
|
+
t.queryString ? r.searchParams.set("queryString", t.queryString) : (t.num && r.searchParams.set("num", t.num), t.street && r.searchParams.set("street", t.street), t.zip && r.searchParams.set("zip", t.zip), t.locality && r.searchParams.set("locality", t.locality));
|
|
337
|
+
const c = await fetch(r.toString(), { signal: f.signal });
|
|
338
|
+
if (!c.ok)
|
|
339
|
+
throw new Error(`Geocode request failed: ${c.status} ${c.statusText}`);
|
|
340
|
+
const l = ((await c.json()).results ?? []).map((d) => {
|
|
341
|
+
var a, g, m, w;
|
|
297
342
|
return {
|
|
298
|
-
latLon:
|
|
299
|
-
easting:
|
|
300
|
-
northing:
|
|
301
|
-
accuracy:
|
|
302
|
-
street: (
|
|
303
|
-
num: (
|
|
304
|
-
zip: (
|
|
305
|
-
locality: (w =
|
|
343
|
+
latLon: Q(d.easting, d.northing),
|
|
344
|
+
easting: d.easting,
|
|
345
|
+
northing: d.northing,
|
|
346
|
+
accuracy: d.accuracy ?? 0,
|
|
347
|
+
street: (a = d.AddressDetails) == null ? void 0 : a.street,
|
|
348
|
+
num: (g = d.AddressDetails) == null ? void 0 : g.number,
|
|
349
|
+
zip: (m = d.AddressDetails) == null ? void 0 : m.zip,
|
|
350
|
+
locality: (w = d.AddressDetails) == null ? void 0 : w.locality
|
|
306
351
|
};
|
|
307
352
|
});
|
|
308
|
-
|
|
309
|
-
} catch (
|
|
310
|
-
if (
|
|
311
|
-
|
|
353
|
+
e({ status: "success", results: l, error: null });
|
|
354
|
+
} catch (r) {
|
|
355
|
+
if (r instanceof DOMException && r.name === "AbortError") return;
|
|
356
|
+
e({
|
|
312
357
|
status: "error",
|
|
313
358
|
results: null,
|
|
314
|
-
error:
|
|
359
|
+
error: r instanceof Error ? r : new Error(String(r))
|
|
315
360
|
});
|
|
316
361
|
}
|
|
317
|
-
}, []),
|
|
318
|
-
var
|
|
319
|
-
(
|
|
362
|
+
}, []), s = I(() => {
|
|
363
|
+
var t;
|
|
364
|
+
(t = o.current) == null || t.abort(), e({ status: "idle", results: null, error: null });
|
|
320
365
|
}, []);
|
|
321
|
-
return { state:
|
|
366
|
+
return { state: n, search: i, reset: s };
|
|
322
367
|
}
|
|
323
368
|
export {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
369
|
+
Ut as GeoportailMap,
|
|
370
|
+
P as latLonToLuref,
|
|
371
|
+
ht as loadLuxApi,
|
|
372
|
+
Q as lurefToLatLon,
|
|
373
|
+
Dt as useGeocode,
|
|
374
|
+
Et as useLuxApi,
|
|
375
|
+
Ct as useReverseGeocode
|
|
331
376
|
};
|
|
332
377
|
//# sourceMappingURL=react-geoportail.js.map
|