@dacostafilipe/react-geoportail 0.1.7 → 0.1.8

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