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