@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.
@@ -1,178 +1,223 @@
1
- import { jsx as T, jsxs as $ } from "react/jsx-runtime";
2
- import { useState as F, useEffect as S, forwardRef as nt, useId as st, useRef as y, useImperativeHandle as ot, useCallback as C } from "react";
3
- const B = "https://apiv3.geoportail.lu/apiv3loader.js", j = "geoportail-apiv3-loader";
4
- let R = null;
5
- function et() {
6
- return R || (R = new Promise((c, t) => {
7
- if (typeof window < "u" && window.lux) {
8
- c();
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 V(c, t) {
10
+ function pt(n, e) {
26
11
  let i = 0;
27
- const a = () => {
12
+ const s = () => {
28
13
  if (window.lux) {
29
- c();
14
+ n();
30
15
  return;
31
16
  }
32
17
  if (i++ >= 100) {
33
- R = null, t(new Error("Timed out waiting for window.lux to be defined"));
18
+ A = null, e(new Error("Timed out waiting for window.lux to be defined"));
34
19
  return;
35
20
  }
36
- setTimeout(a, 50);
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
- a();
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 rt() {
41
- const [c, t] = F({
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 n = !1;
48
- return et().then(() => {
49
- n || t({ status: "ready", lux: window.lux, error: null });
92
+ let o = !1;
93
+ return ht().then(() => {
94
+ o || e({ status: "ready", lux: window.lux, error: null });
50
95
  }).catch((i) => {
51
- n || t({
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
- n = !0;
102
+ o = !0;
58
103
  };
59
- }, []), c;
104
+ }, []), n;
60
105
  }
61
- const Z = 8e4, q = 1e5, H = 6.16666666666667, k = 49.8333333333333, D = 1, L = 6378388, z = 1 / 297, P = L * (1 - z), m = 1 - P * P / (L * L), _ = -87, G = -98, J = -121;
62
- function v(c) {
63
- return c * Math.PI / 180;
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 A(c) {
66
- return c * 180 / Math.PI;
110
+ function y(n) {
111
+ return n * 180 / Math.PI;
67
112
  }
68
- function ct(c, t) {
69
- const n = v(c), i = v(t), a = Math.sin(n), s = Math.cos(n), p = Math.sin(i), g = Math.cos(i), o = 6378137, r = 1 / 298.257223563, h = o * (1 - r), f = 1 - h * h / (o * o), u = L - o, e = z - r, d = o / Math.sqrt(1 - f * a * a), w = 1 / (o * (1 - f) / Math.pow(1 - f * a * a, 1.5)) * (d * (f / (1 - f)) * a * s * (u / o) + (d / o + 1) * a * s * e * (o / h) - (_ * a * g + G * a * p - J * s)), x = 1 / (d * s) * (-_ * p + G * g);
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: c + A(w),
72
- lon: t + A(x)
116
+ lat: n + y(w),
117
+ lon: e + y(L)
73
118
  };
74
119
  }
75
- function at(c, t) {
76
- const n = v(c), i = v(t), a = Math.sin(n), s = Math.cos(n), p = Math.sin(i), g = Math.cos(i), o = L / Math.sqrt(1 - m * a * a), r = L * (1 - m) / Math.pow(1 - m * a * a, 1.5), h = 6378137 - L, u = 1 / 298.257223563 - z, e = 1 / r * (o * (m / (1 - m)) * a * s * (h / L) + (o / L + 1) * a * s * u * (L / P) + (_ * a * g + G * a * p - J * s)), d = 1 / (o * s) * (_ * p - G * g);
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: c + A(e),
79
- lon: t + A(d)
123
+ lat: n + y(a),
124
+ lon: e + y(g)
80
125
  };
81
126
  }
82
- function lt(c, t) {
83
- const n = v(c), i = v(t), a = v(H), s = v(k), p = Math.sin(n), g = Math.cos(n), o = Math.tan(n), r = L / Math.sqrt(1 - m * p * p), h = o * o, f = m / (1 - m) * g * g, u = i - a, e = g * u, d = U(n), M = U(s), w = Z + D * r * (e + e * e * e * (1 - h + f) / 6 + e * e * e * e * e * (5 - 18 * h + h * h + 72 * f) / 120), x = q + D * (d - M + r * o * (e * e / 2 + e * e * e * e * (5 - h + 9 * f + 4 * f * f) / 24 + e * e * e * e * e * e * (61 - 58 * h + h * h + 600 * f) / 720));
84
- return { easting: w, northing: x };
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 it(c, t) {
87
- const n = c - Z, i = t - q, a = v(k), s = v(H), o = (U(a) + i / D) / (L * (1 - m / 4 - 3 * m * m / 64)), r = (1 - Math.sqrt(1 - m)) / (1 + Math.sqrt(1 - m)), h = o + (3 * r / 2 - 27 * r * r * r / 32) * Math.sin(2 * o) + (21 * r * r / 16 - 55 * r * r * r * r / 32) * Math.sin(4 * o) + 151 * r * r * r / 96 * Math.sin(6 * o), f = Math.sin(h), u = Math.cos(h), e = Math.tan(h), d = L / Math.sqrt(1 - m * f * f), M = e * e, w = m / (1 - m) * u * u, x = L * (1 - m) / Math.pow(1 - m * f * f, 1.5), l = n / (d * D), E = h - d * e / x * (l * l / 2 - l * l * l * l * (5 + 3 * M + 10 * w - 4 * w * w) / 24 + l * l * l * l * l * l * (61 + 90 * M + 298 * w + 45 * M * M) / 720), b = s + (l - l * l * l * (1 + 2 * M + w) / 6 + l * l * l * l * l * (5 - 2 * w + 28 * M - 3 * w * w) / 120) / u;
88
- return { lat: A(E), lon: A(b) };
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 U(c) {
91
- const t = m, n = t * t, i = n * t;
92
- return L * ((1 - t / 4 - 3 * n / 64 - 5 * i / 256) * c - (3 * t / 8 + 3 * n / 32 + 45 * i / 1024) * Math.sin(2 * c) + (15 * n / 256 + 45 * i / 1024) * Math.sin(4 * c) - 35 * i / 3072 * Math.sin(6 * c));
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 O(c, t) {
95
- const n = ct(c, t);
96
- return lt(n.lat, n.lon);
139
+ function P(n, e) {
140
+ const o = mt(n, e);
141
+ return Mt(o.lat, o.lon);
97
142
  }
98
- function K(c, t) {
99
- const n = it(c, t);
100
- return at(n.lat, n.lon);
143
+ function Q(n, e) {
144
+ const o = xt(n, e);
145
+ return vt(o.lat, o.lon);
101
146
  }
102
- const ut = { lat: 49.6116, lon: 6.1319 }, dt = "basemap_2015_global", Mt = nt(
147
+ const bt = { lat: 49.6116, lon: 6.1319 }, Rt = "basemap_2015_global", Ut = et(
103
148
  function({
104
- center: t = ut,
105
- zoom: n = 12,
106
- bgLayer: i = dt,
107
- markerMode: a = "none",
108
- markerPosition: s,
109
- onMarkerPlace: p,
110
- className: g,
111
- style: o,
112
- layers: r
113
- }, h) {
114
- const u = `gp-map-${st().replace(/:/g, "")}`, e = rt(), d = y(null), M = y(null), w = y(null), x = y(p);
115
- return x.current = p, S(() => {
116
- if (e.status !== "ready") return;
117
- const l = e.lux, { easting: E, northing: b } = O(t.lat, t.lon), I = new l.Map({
118
- target: u,
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: n,
121
- position: [E, b],
122
- ...r && r.length > 0 ? { layers: r, layerOpacities: r.map(() => 1) } : {}
165
+ zoom: o,
166
+ position: [u, x],
167
+ ...c && c.length > 0 ? { layers: c, layerOpacities: c.map(() => 1) } : {}
123
168
  });
124
- return d.current = I, () => {
125
- d.current = null, M.current = null, w.current = null;
169
+ return a.current = b, () => {
170
+ a.current = null, g.current = null, m.current = null;
126
171
  };
127
- }, [e.status, u]), S(() => {
128
- const l = d.current;
129
- if (!l || e.status !== "ready") return;
130
- if (w.current && (l.un("singleclick", w.current), w.current = null), a === "none") {
131
- ft(l, M);
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 E = s ?? (a === "fixed" ? t : void 0);
135
- if (E && Y(l, E, M), a === "click") {
136
- const b = (...I) => {
137
- var X;
138
- const N = I[0];
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 [Q, tt] = N.coordinate, W = K(Q, tt);
141
- Y(l, W, M), (X = x.current) == null || X.call(x, W);
185
+ const [tt, nt] = N.coordinate, $ = Q(tt, nt);
186
+ H(L, $, g), (B = w.current) == null || B.call(w, $);
142
187
  };
143
- w.current = b, l.on("singleclick", b);
188
+ m.current = x, L.on("singleclick", x);
144
189
  }
145
190
  }, [
146
- e.status,
147
- a,
148
- s == null ? void 0 : s.lat,
149
- s == null ? void 0 : s.lon,
150
- t.lat,
151
- t.lon
152
- ]), ot(h, () => ({
153
- getLuxMap: () => d.current,
154
- setCenter(l) {
155
- const E = d.current;
156
- if (!E) return;
157
- const { easting: b, northing: I } = O(l.lat, l.lon);
158
- E.getView().setCenter([b, I]);
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(l) {
161
- var E;
162
- (E = d.current) == null || E.getView().setZoom(l);
205
+ setZoom(L) {
206
+ var u;
207
+ (u = a.current) == null || u.getView().setZoom(L);
163
208
  }
164
- })), e.status === "error" ? /* @__PURE__ */ T(
209
+ })), l.status === "error" ? /* @__PURE__ */ T(
165
210
  "div",
166
211
  {
167
- className: g,
168
- style: { display: "flex", alignItems: "center", justifyContent: "center", background: "#f5f5f5", ...o },
169
- children: /* @__PURE__ */ $("span", { style: { color: "#c00" }, children: [
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
- e.error.message
216
+ l.error.message
172
217
  ] })
173
218
  }
174
- ) : /* @__PURE__ */ $("div", { style: { position: "relative", ...o }, className: g, children: [
175
- e.status === "loading" && /* @__PURE__ */ T(
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
- id: u,
238
+ ref: d,
194
239
  style: { width: "100%", height: "100%" }
195
240
  }
196
241
  )
197
242
  ] });
198
243
  }
199
244
  );
200
- function Y(c, t, n) {
245
+ function H(n, e, o) {
201
246
  const i = window.ol;
202
247
  if (!i) return;
203
- const { easting: a, northing: s } = O(t.lat, t.lon);
204
- if (n.current) {
205
- n.current.setPosition([a, s]);
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 p = document.createElement("div");
209
- p.innerHTML = ht, p.style.cssText = "cursor:pointer;transform:translate(-50%,-100%);line-height:0;";
210
- const g = new i.Overlay({
211
- element: p,
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
- g.setPosition([a, s]), c.addOverlay(g), n.current = g;
260
+ h.setPosition([s, t]), n.addOverlay(h), o.current = h;
216
261
  }
217
- function ft(c, t) {
218
- !t.current || !window.ol || (t.current.setPosition(void 0), t.current = null);
262
+ function At(n, e) {
263
+ !e.current || !window.ol || (e.current.setPosition(void 0), e.current = null);
219
264
  }
220
- const ht = `<svg xmlns="http://www.w3.org/2000/svg" width="30" height="40" viewBox="0 0 30 40">
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>`, gt = "https://api.geoportail.lu/geocoder/reverseGeocode";
225
- function Lt() {
226
- const [c, t] = F({
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
- }), n = y(null);
275
+ }), o = R(null);
231
276
  S(() => () => {
232
- var s;
233
- (s = n.current) == null || s.abort();
277
+ var t;
278
+ (t = o.current) == null || t.abort();
234
279
  }, []);
235
- const i = C(async (s) => {
236
- var g, o;
237
- (g = n.current) == null || g.abort();
238
- const p = new AbortController();
239
- n.current = p, t({ status: "loading", address: null, error: null });
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: r, northing: h } = O(s.lat, s.lon), f = new URL(gt);
242
- f.searchParams.set("easting", String(r)), f.searchParams.set("northing", String(h));
243
- const u = await fetch(f.toString(), { signal: p.signal });
244
- if (!u.ok)
245
- throw new Error(`Reverse geocode request failed: ${u.status} ${u.statusText}`);
246
- const d = (o = (await u.json()).results) == null ? void 0 : o[0];
247
- if (!d)
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
- t({
294
+ e({
250
295
  status: "success",
251
296
  address: {
252
- label: d.name ?? "",
253
- distance: d.distance ?? 0,
254
- easting: d.easting,
255
- northing: d.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 (r) {
260
- if (r instanceof DOMException && r.name === "AbortError") return;
261
- t({
304
+ } catch (c) {
305
+ if (c instanceof DOMException && c.name === "AbortError") return;
306
+ e({
262
307
  status: "error",
263
308
  address: null,
264
- error: r instanceof Error ? r : new Error(String(r))
309
+ error: c instanceof Error ? c : new Error(String(c))
265
310
  });
266
311
  }
267
- }, []), a = C(() => {
268
- var s;
269
- (s = n.current) == null || s.abort(), t({ status: "idle", address: null, error: null });
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: c, lookup: i, reset: a };
316
+ return { state: n, lookup: i, reset: s };
272
317
  }
273
- const pt = "https://apiv3.geoportail.lu/geocode/search";
274
- function Et() {
275
- const [c, t] = F({
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
- }), n = y(null);
324
+ }), o = R(null);
280
325
  S(() => () => {
281
- var s;
282
- (s = n.current) == null || s.abort();
326
+ var t;
327
+ (t = o.current) == null || t.abort();
283
328
  }, []);
284
- const i = C(async (s) => {
285
- var g;
286
- (g = n.current) == null || g.abort();
287
- const p = new AbortController();
288
- n.current = p, t({ status: "loading", results: null, error: null });
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 o = new URL(pt);
291
- s.queryString ? o.searchParams.set("queryString", s.queryString) : (s.num && o.searchParams.set("num", s.num), s.street && o.searchParams.set("street", s.street), s.zip && o.searchParams.set("zip", s.zip), s.locality && o.searchParams.set("locality", s.locality));
292
- const r = await fetch(o.toString(), { signal: p.signal });
293
- if (!r.ok)
294
- throw new Error(`Geocode request failed: ${r.status} ${r.statusText}`);
295
- const f = ((await r.json()).results ?? []).map((u) => {
296
- var e, d, M, w;
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: K(u.easting, u.northing),
299
- easting: u.easting,
300
- northing: u.northing,
301
- accuracy: u.accuracy ?? 0,
302
- street: (e = u.AddressDetails) == null ? void 0 : e.street,
303
- num: (d = u.AddressDetails) == null ? void 0 : d.number,
304
- zip: (M = u.AddressDetails) == null ? void 0 : M.zip,
305
- locality: (w = u.AddressDetails) == null ? void 0 : w.locality
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
- t({ status: "success", results: f, error: null });
309
- } catch (o) {
310
- if (o instanceof DOMException && o.name === "AbortError") return;
311
- t({
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: o instanceof Error ? o : new Error(String(o))
359
+ error: r instanceof Error ? r : new Error(String(r))
315
360
  });
316
361
  }
317
- }, []), a = C(() => {
318
- var s;
319
- (s = n.current) == null || s.abort(), t({ status: "idle", results: null, error: null });
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: c, search: i, reset: a };
366
+ return { state: n, search: i, reset: s };
322
367
  }
323
368
  export {
324
- Mt as GeoportailMap,
325
- O as latLonToLuref,
326
- et as loadLuxApi,
327
- K as lurefToLatLon,
328
- Et as useGeocode,
329
- rt as useLuxApi,
330
- Lt as useReverseGeocode
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