@dacostafilipe/react-geoportail 0.1.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,223 +1,252 @@
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));
1
+ import { jsx as A, jsxs as Y } from "react/jsx-runtime";
2
+ import { useState as X, useEffect as x, forwardRef as it, useRef as C, useImperativeHandle as ct, useCallback as j } from "react";
3
+ const lt = "https://apiv4.geoportail.lu/", ut = "https", dt = "https://apiv4.geoportail.lu/static-ngeo/build/fr.json", ft = "https://apiv4.geoportail.lu/static-ngeo/build/apiv4.css", pt = "https://apiv4.geoportail.lu/static-ngeo/build/ol.js", gt = "https://apiv4.geoportail.lu/static-ngeo/build/proj4.js", ht = "https://apiv4.geoportail.lu/static-ngeo/build/auto-complete.min.js", Lt = "https://apiv4.geoportail.lu/static-ngeo/build/apiv4.js", wt = "geoportail-apiv4-css", Et = "geoportail-apiv4-ol", mt = "geoportail-apiv4-proj4", vt = "geoportail-apiv4-autocomplete", _t = "geoportail-apiv4-script", H = "EPSG:2169", Mt = "+proj=tmerc +lat_0=49.83333333333334 +lon_0=6.166666666666667 +k=1 +x_0=80000 +y_0=100000 +ellps=intl +towgs84=-189.681,18.3463,-42.7695,-0.33746,-3.09264,2.53861,0.4598 +units=m +no_defs", O = "data-geoportail-status";
4
+ let b = null;
5
+ function Rt() {
6
+ return b || (typeof window > "u" || typeof document > "u" ? Promise.reject(new Error("loadLuxApi must be called in a browser environment")) : (b = Tt().catch((t) => {
7
+ throw b = null, t instanceof Error ? t : new Error(String(t));
8
+ }), b));
9
9
  }
10
- function ft(n, o) {
11
- let i = 0;
12
- const s = () => {
10
+ function yt(t, n) {
11
+ let s = 0;
12
+ const r = () => {
13
13
  if (window.lux) {
14
- n();
14
+ t();
15
15
  return;
16
16
  }
17
- if (i++ >= 100) {
18
- S = null, o(new Error("Timed out waiting for window.lux to be defined"));
17
+ if (s++ >= 100) {
18
+ b = null, n(new Error("Timed out waiting for window.lux to be defined"));
19
19
  return;
20
20
  }
21
- setTimeout(s, 50);
21
+ setTimeout(r, 50);
22
22
  };
23
- s();
23
+ r();
24
24
  }
25
- async function ht() {
25
+ async function Tt() {
26
26
  if (window.lux) {
27
- z(window.lux);
27
+ V(window.lux);
28
28
  return;
29
29
  }
30
- await gt(it, rt), await V(lt, ct), await V(ut, at), await pt(), z(window.lux);
30
+ await xt(wt, ft), await I(Et, pt), await I(mt, gt), Ct(), await I(vt, ht), await I(_t, Lt), await bt(), V(window.lux);
31
31
  }
32
- function pt() {
33
- return new Promise((n, o) => {
34
- ft(n, o);
32
+ function Ct() {
33
+ var o, s;
34
+ const t = window.proj4, n = window.ol;
35
+ !t || !((s = (o = n == null ? void 0 : n.proj) == null ? void 0 : o.proj4) != null && s.register) || (t.defs(H) || t.defs(H, Mt), n.proj.proj4.register(t));
36
+ }
37
+ function bt() {
38
+ return new Promise((t, n) => {
39
+ yt(t, n);
35
40
  });
36
41
  }
37
- function z(n) {
38
- n.setBaseUrl(ot, et), n.setI18nUrl(st);
42
+ function V(t) {
43
+ t.setBaseUrl(lt, ut), t.setI18nUrl(dt);
39
44
  }
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}`)),
45
+ function I(t, n) {
46
+ const o = document.getElementById(t);
47
+ return o ? Z(o, n, "script") : new Promise((s, r) => {
48
+ const e = document.createElement("script");
49
+ e.id = t, e.src = n, e.async = !1, e.setAttribute(O, "loading"), W(
50
+ e,
51
+ () => s(),
52
+ () => r(new Error(`Failed to load Geoportail script from ${n}`)),
48
53
  "script"
49
- ), document.head.appendChild(t);
54
+ ), document.head.appendChild(e);
50
55
  });
51
56
  }
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}`)),
57
+ function xt(t, n) {
58
+ const o = document.getElementById(t);
59
+ return o ? Z(o, n, "stylesheet") : new Promise((s, r) => {
60
+ const e = document.createElement("link");
61
+ e.id = t, e.rel = "stylesheet", e.href = n, e.setAttribute(O, "loading"), W(
62
+ e,
63
+ () => s(),
64
+ () => r(new Error(`Failed to load Geoportail stylesheet from ${n}`)),
60
65
  "stylesheet"
61
- ), document.head.appendChild(t);
66
+ ), document.head.appendChild(e);
62
67
  });
63
68
  }
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
69
+ function Z(t, n, o) {
70
+ const s = t.getAttribute(O);
71
+ return s === "loaded" ? Promise.resolve() : s === "error" ? (t.remove(), Promise.reject(new Error(`Failed to load Geoportail ${o} from ${n}`))) : new Promise((r, e) => {
72
+ W(
73
+ t,
74
+ () => r(),
75
+ () => e(new Error(`Failed to load Geoportail ${o} from ${n}`)),
76
+ o
72
77
  );
73
78
  });
74
79
  }
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);
80
+ function W(t, n, o, s) {
81
+ const r = () => {
82
+ t.setAttribute(O, "loaded"), f(), n();
83
+ }, e = () => {
84
+ t.setAttribute(O, "error"), f(), t.remove(), o();
85
+ }, f = () => {
86
+ t.removeEventListener("load", r), t.removeEventListener("error", e);
82
87
  };
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;
88
+ return t.addEventListener("load", r, { once: !0 }), t.addEventListener("error", e, { once: !0 }), s === "stylesheet" ? t.sheet && r() : t.dataset.geoportailStatus === "loaded" && r(), f;
84
89
  }
85
- function wt() {
86
- const [n, o] = j({
90
+ function Pt() {
91
+ const [t, n] = X({
87
92
  status: "loading",
88
93
  lux: null,
89
94
  error: null
90
95
  });
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({
96
+ return x(() => {
97
+ let o = !1;
98
+ return Rt().then(() => {
99
+ o || n({ status: "ready", lux: window.lux, error: null });
100
+ }).catch((s) => {
101
+ o || n({
97
102
  status: "error",
98
103
  lux: null,
99
- error: i instanceof Error ? i : new Error(String(i))
104
+ error: s instanceof Error ? s : new Error(String(s))
100
105
  });
101
106
  }), () => {
102
- e = !0;
107
+ o = !0;
103
108
  };
104
- }, []), n;
109
+ }, []), t;
105
110
  }
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;
111
+ const q = 8e4, K = 1e5, Q = 6.16666666666667, tt = 49.8333333333333, D = 1, _ = 6378388, z = 1 / 297, B = _ * (1 - z), m = 1 - B * B / (_ * _), G = -87, F = -98, nt = -121;
112
+ function R(t) {
113
+ return t * Math.PI / 180;
109
114
  }
110
- function _(n) {
111
- return n * 180 / Math.PI;
115
+ function P(t) {
116
+ return t * 180 / Math.PI;
112
117
  }
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);
118
+ function St(t, n) {
119
+ const o = R(t), s = R(n), r = Math.sin(o), e = Math.cos(o), f = Math.sin(s), g = Math.cos(s), i = 6378137, l = 1 / 298.257223563, u = i * (1 - l), c = 1 - u * u / (i * i), p = _ - i, a = z - l, w = i / Math.sqrt(1 - c * r * r), L = 1 / (i * (1 - c) / Math.pow(1 - c * r * r, 1.5)) * (w * (c / (1 - c)) * r * e * (p / i) + (w / i + 1) * r * e * a * (i / u) - (G * r * g + F * r * f - nt * e)), M = 1 / (w * e) * (-G * f + F * g);
115
120
  return {
116
- lat: n + _(w),
117
- lon: o + _(L)
121
+ lat: t + P(L),
122
+ lon: n + P(M)
118
123
  };
119
124
  }
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);
125
+ function Ot(t, n) {
126
+ const o = R(t), s = R(n), r = Math.sin(o), e = Math.cos(o), f = Math.sin(s), g = Math.cos(s), i = _ / Math.sqrt(1 - m * r * r), l = _ * (1 - m) / Math.pow(1 - m * r * r, 1.5), u = 6378137 - _, p = 1 / 298.257223563 - z, a = 1 / l * (i * (m / (1 - m)) * r * e * (u / _) + (i / _ + 1) * r * e * p * (_ / B) + (G * r * g + F * r * f - nt * e)), w = 1 / (i * e) * (G * f - F * g);
122
127
  return {
123
- lat: n + _(a),
124
- lon: o + _(g)
128
+ lat: t + P(a),
129
+ lon: n + P(w)
125
130
  };
126
131
  }
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 };
132
+ function Ut(t, n) {
133
+ const o = R(t), s = R(n), r = R(Q), e = R(tt), f = Math.sin(o), g = Math.cos(o), i = Math.tan(o), l = _ / Math.sqrt(1 - m * f * f), u = i * i, c = m / (1 - m) * g * g, p = s - r, a = g * p, w = $(o), h = $(e), L = q + D * l * (a + a * a * a * (1 - u + c) / 6 + a * a * a * a * a * (5 - 18 * u + u * u + 72 * c) / 120), M = K + D * (w - h + l * i * (a * a / 2 + a * a * a * a * (5 - u + 9 * c + 4 * c * c) / 24 + a * a * a * a * a * a * (61 - 58 * u + u * u + 600 * c) / 720));
134
+ return { easting: L, northing: M };
130
135
  }
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) };
136
+ function At(t, n) {
137
+ const o = t - q, s = n - K, r = R(tt), e = R(Q), i = ($(r) + s / D) / (_ * (1 - m / 4 - 3 * m * m / 64)), l = (1 - Math.sqrt(1 - m)) / (1 + Math.sqrt(1 - m)), u = i + (3 * l / 2 - 27 * l * l * l / 32) * Math.sin(2 * i) + (21 * l * l / 16 - 55 * l * l * l * l / 32) * Math.sin(4 * i) + 151 * l * l * l / 96 * Math.sin(6 * i), c = Math.sin(u), p = Math.cos(u), a = Math.tan(u), w = _ / Math.sqrt(1 - m * c * c), h = a * a, L = m / (1 - m) * p * p, M = _ * (1 - m) / Math.pow(1 - m * c * c, 1.5), d = o / (w * D), U = u - w * a / M * (d * d / 2 - d * d * d * d * (5 + 3 * h + 10 * L - 4 * L * L) / 24 + d * d * d * d * d * d * (61 + 90 * h + 298 * L + 45 * h * h) / 720), E = e + (d - d * d * d * (1 + 2 * h + L) / 6 + d * d * d * d * d * (5 - 2 * L + 28 * h - 3 * L * L) / 120) / p;
138
+ return { lat: P(U), lon: P(E) };
134
139
  }
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));
140
+ function $(t) {
141
+ const n = m, o = n * n, s = o * n;
142
+ return _ * ((1 - n / 4 - 3 * o / 64 - 5 * s / 256) * t - (3 * n / 8 + 3 * o / 32 + 45 * s / 1024) * Math.sin(2 * t) + (15 * o / 256 + 45 * s / 1024) * Math.sin(4 * t) - 35 * s / 3072 * Math.sin(6 * t));
138
143
  }
139
- function O(n, o) {
140
- const e = Lt(n, o);
141
- return mt(e.lat, e.lon);
144
+ function J(t, n) {
145
+ const o = St(t, n);
146
+ return Ut(o.lat, o.lon);
142
147
  }
143
- function Q(n, o) {
144
- const e = vt(n, o);
145
- return Et(e.lat, e.lon);
148
+ function ot(t, n) {
149
+ const o = At(t, n);
150
+ return Ot(o.lat, o.lon);
146
151
  }
147
- const Mt = "EPSG:3857", xt = "EPSG:4326", bt = { lat: 49.6116, lon: 6.1319 }, Rt = "basemap_2015_global", Ut = tt(
152
+ const It = "EPSG:3857", jt = "EPSG:3857", et = "EPSG:4326", Dt = "EPSG:2169", rt = { lat: 49.6116, lon: 6.1319 }, Gt = "basemap_2015_global", Zt = it(
148
153
  function({
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
158
- }, f) {
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(() => {
161
- if (l.status !== "ready" || !d.current) return;
162
- const L = l.lux, { easting: u, northing: x } = O(o.lat, o.lon), b = new L.Map({
163
- target: d.current,
164
- bgLayer: i,
165
- zoom: e,
166
- position: [u, x],
167
- ...c && c.length > 0 ? { layers: c, layerOpacities: c.map(() => 1) } : {}
154
+ center: n,
155
+ zoom: o = 12,
156
+ bgLayer: s = Gt,
157
+ markerMode: r = "none",
158
+ markerPosition: e,
159
+ onMarkerPlace: f,
160
+ className: g,
161
+ style: i,
162
+ layers: l
163
+ }, u) {
164
+ const c = Pt(), p = C(null), a = C(null), w = C(null), h = C(null), [L, M] = X(!1), d = C(f);
165
+ d.current = f;
166
+ const U = $t(n, r, e);
167
+ return x(() => {
168
+ var k;
169
+ if (c.status !== "ready" || !p.current) return;
170
+ let E = !1;
171
+ const v = c.lux, { easting: S, northing: y } = J(U.lat, U.lon), T = new v.Map({
172
+ target: p.current,
173
+ bgLayer: s,
174
+ zoom: o,
175
+ position: [S, y],
176
+ ...l && l.length > 0 ? { layers: l, layerOpacities: l.map(() => 1) } : {}
168
177
  });
169
- return a.current = b, () => {
170
- a.current = null, g.current = null, m.current = null;
178
+ return a.current = T, M(!1), (((k = T.getMapReadyPromise) == null ? void 0 : k.call(T)) ?? Promise.resolve()).then(() => {
179
+ E || M(!0);
180
+ }), () => {
181
+ E = !0, a.current = null, w.current = null, h.current = null, M(!1);
171
182
  };
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);
183
+ }, [c.status]), x(() => {
184
+ const E = a.current;
185
+ if (!E || c.status !== "ready" || !L) return;
186
+ const v = Bt(
187
+ r,
188
+ e,
189
+ n ?? rt
190
+ );
191
+ if (!v) {
192
+ Nt(w);
177
193
  return;
178
194
  }
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, $);
187
- };
188
- m.current = x, L.on("singleclick", x);
189
- }
195
+ Ft(E, v, w);
196
+ }, [
197
+ L,
198
+ c.status,
199
+ r,
200
+ e == null ? void 0 : e.lat,
201
+ e == null ? void 0 : e.lon,
202
+ n == null ? void 0 : n.lat,
203
+ n == null ? void 0 : n.lon
204
+ ]), x(() => {
205
+ const E = a.current;
206
+ if (!E || c.status !== "ready" || !L || (h.current && (E.un("singleclick", h.current), h.current = null), r !== "click"))
207
+ return;
208
+ const v = (...S) => {
209
+ var N;
210
+ const y = S[0];
211
+ if (!y.coordinate) return;
212
+ const T = Wt(E, y.coordinate);
213
+ Xt(E, y.coordinate, T, w), (N = d.current) == null || N.call(d, T);
214
+ };
215
+ return h.current = v, E.on("singleclick", v), () => {
216
+ h.current && (E.un("singleclick", h.current), h.current = null);
217
+ };
190
218
  }, [
191
- l.status,
192
- s,
193
- t == null ? void 0 : t.lat,
194
- t == null ? void 0 : t.lon,
195
- o.lat,
196
- o.lon
197
- ]), nt(f, () => ({
219
+ L,
220
+ c.status,
221
+ r
222
+ ]), ct(u, () => ({
198
223
  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]);
224
+ setCenter(E) {
225
+ const v = a.current;
226
+ if (!v) return;
227
+ const { easting: S, northing: y } = J(E.lat, E.lon);
228
+ if (v.setCenter) {
229
+ v.setCenter([S, y], void 0, Dt);
230
+ return;
231
+ }
232
+ v.getView().setCenter(at(E));
204
233
  },
205
- setZoom(L) {
206
- var u;
207
- (u = a.current) == null || u.getView().setZoom(L);
234
+ setZoom(E) {
235
+ var v;
236
+ (v = a.current) == null || v.getView().setZoom(E);
208
237
  }
209
- })), l.status === "error" ? /* @__PURE__ */ y(
238
+ })), c.status === "error" ? /* @__PURE__ */ A(
210
239
  "div",
211
240
  {
212
- className: p,
213
- style: { display: "flex", alignItems: "center", justifyContent: "center", background: "#f5f5f5", ...r },
214
- children: /* @__PURE__ */ W("span", { style: { color: "#c00" }, children: [
241
+ className: g,
242
+ style: { display: "flex", alignItems: "center", justifyContent: "center", background: "#f5f5f5", ...i },
243
+ children: /* @__PURE__ */ Y("span", { style: { color: "#c00" }, children: [
215
244
  "Failed to load Geoportail API: ",
216
- l.error.message
245
+ c.error.message
217
246
  ] })
218
247
  }
219
- ) : /* @__PURE__ */ W("div", { style: { position: "relative", ...r }, className: p, children: [
220
- l.status === "loading" && /* @__PURE__ */ y(
248
+ ) : /* @__PURE__ */ Y("div", { style: { position: "relative", ...i }, className: g, children: [
249
+ c.status === "loading" && /* @__PURE__ */ A(
221
250
  "div",
222
251
  {
223
252
  style: {
@@ -229,160 +258,192 @@ const Mt = "EPSG:3857", xt = "EPSG:4326", bt = { lat: 49.6116, lon: 6.1319 }, Rt
229
258
  background: "rgba(255,255,255,0.7)",
230
259
  zIndex: 10
231
260
  },
232
- children: /* @__PURE__ */ y("span", { children: "Loading map…" })
261
+ children: /* @__PURE__ */ A("span", { children: "Loading map…" })
233
262
  }
234
263
  ),
235
- /* @__PURE__ */ y(
264
+ /* @__PURE__ */ A(
236
265
  "div",
237
266
  {
238
- ref: d,
267
+ ref: p,
239
268
  style: { width: "100%", height: "100%" }
240
269
  }
241
270
  )
242
271
  ] });
243
272
  }
244
273
  );
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]);
251
- return;
252
- }
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,
274
+ function Ft(t, n, o) {
275
+ const s = st(t, n, o);
276
+ s && s.setPosition(at(n));
277
+ }
278
+ function Xt(t, n, o, s) {
279
+ const r = st(t, o, s);
280
+ r && r.setPosition(n);
281
+ }
282
+ function Nt(t) {
283
+ t.current && t.current.setPosition(void 0);
284
+ }
285
+ function st(t, n, o) {
286
+ if (o.current)
287
+ return o.current;
288
+ const s = window.ol;
289
+ if (!s) return null;
290
+ const r = document.createElement("div");
291
+ r.innerHTML = Jt, r.style.cssText = "cursor:pointer;line-height:0;display:block;";
292
+ const e = new s.Overlay({
293
+ element: r,
257
294
  positioning: "bottom-center",
258
295
  stopEvent: !1
259
296
  });
260
- p.setPosition([s, t]), n.addOverlay(p), e.current = p;
297
+ return t.addOverlay(e), o.current = e, e;
298
+ }
299
+ function at(t) {
300
+ var s;
301
+ const n = window.ol, o = (s = n == null ? void 0 : n.proj) == null ? void 0 : s.transform;
302
+ if (!o) {
303
+ const { easting: r, northing: e } = J(t.lat, t.lon);
304
+ return [r, e];
305
+ }
306
+ return o([t.lon, t.lat], et, jt);
261
307
  }
262
- function St(n, o) {
263
- !o.current || !window.ol || (o.current.setPosition(void 0), o.current = null);
308
+ function Bt(t, n, o) {
309
+ if (t !== "none")
310
+ return n || (t === "fixed" ? o : void 0);
264
311
  }
265
- const _t = `<svg xmlns="http://www.w3.org/2000/svg" width="30" height="40" viewBox="0 0 30 40">
312
+ function $t(t, n, o) {
313
+ return o && n !== "none" ? o : t ?? rt;
314
+ }
315
+ const Jt = `<svg xmlns="http://www.w3.org/2000/svg" width="30" height="40" viewBox="0 0 30 40">
266
316
  <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"
267
317
  fill="#e53935" stroke="#b71c1c" stroke-width="1.5"/>
268
318
  <circle cx="15" cy="14" r="5" fill="white"/>
269
319
  </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);
320
+ function Wt(t, n) {
321
+ var f;
322
+ const o = window.ol, s = (f = o == null ? void 0 : o.proj) == null ? void 0 : f.transform;
323
+ if (!s) {
324
+ const [g, i] = n;
325
+ return ot(g, i);
276
326
  }
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 };
327
+ const [r, e] = s(n, It, et);
328
+ return { lat: e, lon: r };
279
329
  }
280
- const At = "https://api.geoportail.lu/geocoder/reverseGeocode";
281
- function Pt() {
282
- const [n, o] = j({
330
+ const zt = "https://apiv4.geoportail.lu/geocode/reverse";
331
+ function qt() {
332
+ const [t, n] = X({
283
333
  status: "idle",
284
334
  address: null,
285
335
  error: null
286
- }), e = R(null);
287
- T(() => () => {
288
- var t;
289
- (t = e.current) == null || t.abort();
336
+ }), o = C(null);
337
+ x(() => () => {
338
+ var e;
339
+ (e = o.current) == null || e.abort();
290
340
  }, []);
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 });
341
+ const s = j(async (e) => {
342
+ var g, i, l;
343
+ (g = o.current) == null || g.abort();
344
+ const f = new AbortController();
345
+ o.current = f, n({ status: "loading", address: null, error: null });
296
346
  try {
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 });
300
- if (!d.ok)
301
- throw new Error(`Reverse geocode request failed: ${d.status} ${d.statusText}`);
302
- const g = (r = (await d.json()).results) == null ? void 0 : r[0];
303
- if (!g)
347
+ const u = new URL(zt);
348
+ u.searchParams.set("lat", String(e.lat)), u.searchParams.set("lon", String(e.lon));
349
+ const c = await fetch(u.toString(), { signal: f.signal });
350
+ if (!c.ok)
351
+ throw new Error(`Reverse geocode request failed: ${c.status} ${c.statusText}`);
352
+ const a = (i = (await c.json()).results) == null ? void 0 : i[0];
353
+ if (!a)
304
354
  throw new Error("No results returned for this position");
305
- o({
355
+ const w = [
356
+ [a.number, a.street].filter(Boolean).join(" ").trim(),
357
+ [a.postal_code, a.locality].filter(Boolean).join(" ").trim()
358
+ ].filter(Boolean).join(", "), [h, L] = ((l = a.geom) == null ? void 0 : l.coordinates) ?? [0, 0];
359
+ n({
306
360
  status: "success",
307
361
  address: {
308
- label: g.name ?? "",
309
- distance: g.distance ?? 0,
310
- easting: g.easting,
311
- northing: g.northing
362
+ label: w,
363
+ distance: a.distance ?? 0,
364
+ easting: h,
365
+ northing: L
312
366
  },
313
367
  error: null
314
368
  });
315
- } catch (c) {
316
- if (c instanceof DOMException && c.name === "AbortError") return;
317
- o({
369
+ } catch (u) {
370
+ if (u instanceof DOMException && u.name === "AbortError") return;
371
+ n({
318
372
  status: "error",
319
373
  address: null,
320
- error: c instanceof Error ? c : new Error(String(c))
374
+ error: u instanceof Error ? u : new Error(String(u))
321
375
  });
322
376
  }
323
- }, []), s = C(() => {
324
- var t;
325
- (t = e.current) == null || t.abort(), o({ status: "idle", address: null, error: null });
377
+ }, []), r = j(() => {
378
+ var e;
379
+ (e = o.current) == null || e.abort(), n({ status: "idle", address: null, error: null });
326
380
  }, []);
327
- return { state: n, lookup: i, reset: s };
381
+ return { state: t, lookup: s, reset: r };
328
382
  }
329
- const yt = "https://apiv3.geoportail.lu/geocode/search";
330
- function Ot() {
331
- const [n, o] = j({
383
+ const kt = "https://apiv4.geoportail.lu/geocode/search";
384
+ function Yt(t, n, o) {
385
+ if (t) {
386
+ const [s, r] = t;
387
+ return { lat: r, lon: s };
388
+ }
389
+ return ot(n, o);
390
+ }
391
+ function Kt() {
392
+ const [t, n] = X({
332
393
  status: "idle",
333
394
  results: null,
334
395
  error: null
335
- }), e = R(null);
336
- T(() => () => {
337
- var t;
338
- (t = e.current) == null || t.abort();
396
+ }), o = C(null);
397
+ x(() => () => {
398
+ var e;
399
+ (e = o.current) == null || e.abort();
339
400
  }, []);
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 });
401
+ const s = j(async (e) => {
402
+ var g;
403
+ (g = o.current) == null || g.abort();
404
+ const f = new AbortController();
405
+ o.current = f, n({ status: "loading", results: null, error: null });
345
406
  try {
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;
407
+ const i = new URL(kt);
408
+ e.queryString ? i.searchParams.set("queryString", e.queryString) : (e.num && i.searchParams.set("num", e.num), e.street && i.searchParams.set("street", e.street), e.zip && i.searchParams.set("zip", e.zip), e.locality && i.searchParams.set("locality", e.locality));
409
+ const l = await fetch(i.toString(), { signal: f.signal });
410
+ if (!l.ok)
411
+ throw new Error(`Geocode request failed: ${l.status} ${l.statusText}`);
412
+ const c = ((await l.json()).results ?? []).map((p) => {
413
+ var a, w, h, L, M;
353
414
  return {
354
- latLon: Q(d.easting, d.northing),
355
- easting: d.easting,
356
- northing: d.northing,
357
- accuracy: d.accuracy ?? 0,
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,
361
- locality: (w = d.AddressDetails) == null ? void 0 : w.locality
415
+ latLon: Yt((a = p.geomlonlat) == null ? void 0 : a.coordinates, p.easting, p.northing),
416
+ easting: p.easting,
417
+ northing: p.northing,
418
+ accuracy: p.accuracy ?? 0,
419
+ street: (w = p.AddressDetails) == null ? void 0 : w.street,
420
+ num: (h = p.AddressDetails) == null ? void 0 : h.postnumber,
421
+ zip: (L = p.AddressDetails) == null ? void 0 : L.zip,
422
+ locality: (M = p.AddressDetails) == null ? void 0 : M.locality
362
423
  };
363
424
  });
364
- o({ status: "success", results: l, error: null });
365
- } catch (r) {
366
- if (r instanceof DOMException && r.name === "AbortError") return;
367
- o({
425
+ n({ status: "success", results: c, error: null });
426
+ } catch (i) {
427
+ if (i instanceof DOMException && i.name === "AbortError") return;
428
+ n({
368
429
  status: "error",
369
430
  results: null,
370
- error: r instanceof Error ? r : new Error(String(r))
431
+ error: i instanceof Error ? i : new Error(String(i))
371
432
  });
372
433
  }
373
- }, []), s = C(() => {
374
- var t;
375
- (t = e.current) == null || t.abort(), o({ status: "idle", results: null, error: null });
434
+ }, []), r = j(() => {
435
+ var e;
436
+ (e = o.current) == null || e.abort(), n({ status: "idle", results: null, error: null });
376
437
  }, []);
377
- return { state: n, search: i, reset: s };
438
+ return { state: t, search: s, reset: r };
378
439
  }
379
440
  export {
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
441
+ Zt as GeoportailMap,
442
+ J as latLonToLuref,
443
+ Rt as loadLuxApi,
444
+ ot as lurefToLatLon,
445
+ Kt as useGeocode,
446
+ Pt as useLuxApi,
447
+ qt as useReverseGeocode
387
448
  };
388
449
  //# sourceMappingURL=react-geoportail.js.map