@dacostafilipe/react-geoportail 0.1.6 → 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 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));
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
+ let S = null;
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
+ }), S));
9
9
  }
10
- function pt(n, e) {
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
- A = null, e(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 gt() {
25
+ async function mt() {
26
26
  if (window.lux) {
27
- W(window.lux);
27
+ k(window.lux);
28
28
  return;
29
29
  }
30
- await Lt(ut, ct), await V(dt, it), await V(ft, lt), await wt(), W(window.lux);
30
+ await Mt(ht, dt), await H(gt, ft), await H(wt, pt), await vt(), k(window.lux);
31
31
  }
32
- function wt() {
33
- return new Promise((n, e) => {
34
- pt(n, e);
32
+ function vt() {
33
+ return new Promise((t, n) => {
34
+ Et(t, n);
35
35
  });
36
36
  }
37
- function W(n) {
38
- n.setBaseUrl(st, rt), n.setI18nUrl(at);
37
+ function k(t) {
38
+ t.setBaseUrl(it, lt), t.setI18nUrl(ut);
39
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}`)),
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 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}`)),
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, 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}`)),
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
71
  o
72
72
  );
73
73
  });
74
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();
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
80
  }, f = () => {
81
- n.removeEventListener("load", s), n.removeEventListener("error", t);
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(), f;
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 Et() {
86
- const [n, e] = F({
85
+ function Rt() {
86
+ const [t, n] = F({
87
87
  status: "loading",
88
88
  lux: null,
89
89
  error: null
90
90
  });
91
- return S(() => {
91
+ return T(() => {
92
92
  let o = !1;
93
- return ht().then(() => {
94
- o || e({ status: "ready", lux: window.lux, error: null });
95
- }).catch((i) => {
96
- o || e({
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
102
  o = !0;
103
103
  };
104
- }, []), n;
104
+ }, []), t;
105
105
  }
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;
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 y(n) {
111
- return n * 180 / Math.PI;
110
+ function C(t) {
111
+ return t * 180 / Math.PI;
112
112
  }
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);
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 + y(w),
117
- lon: e + y(L)
116
+ lat: t + C(w),
117
+ lon: n + C(y)
118
118
  };
119
119
  }
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);
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 + y(a),
124
- lon: e + y(g)
123
+ lat: t + C(a),
124
+ lon: n + C(L)
125
125
  };
126
126
  }
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 };
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 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) };
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 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));
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 P(n, e) {
140
- const o = mt(n, e);
141
- return Mt(o.lat, o.lon);
139
+ function $(t, n) {
140
+ const o = yt(t, n);
141
+ return _t(o.lat, o.lon);
142
142
  }
143
- function Q(n, e) {
144
- const o = xt(n, e);
145
- return vt(o.lat, o.lon);
143
+ function nt(t, n) {
144
+ const o = bt(t, n);
145
+ return xt(o.lat, o.lon);
146
146
  }
147
- const bt = { lat: 49.6116, lon: 6.1319 }, Rt = "basemap_2015_global", Ut = et(
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: e = bt,
149
+ center: n,
150
150
  zoom: o = 12,
151
- bgLayer: i = Rt,
152
- markerMode: s = "none",
153
- markerPosition: t,
151
+ bgLayer: s = At,
152
+ markerMode: r = "none",
153
+ markerPosition: e,
154
154
  onMarkerPlace: f,
155
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,
164
- bgLayer: i,
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,
165
169
  zoom: o,
166
- position: [u, x],
167
- ...c && c.length > 0 ? { layers: c, layerOpacities: c.map(() => 1) } : {}
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]), 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);
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" ? e : void 0);
180
- if (u && H(L, u, g), s === "click") {
181
- const x = (...b) => {
182
- var B;
183
- const N = b[0];
184
- if (!N.coordinate) return;
185
- const [tt, nt] = N.coordinate, $ = Q(tt, nt);
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
- e.lat,
196
- e.lon
197
- ]), ot(p, () => ({
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 } = P(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__ */ T(
233
+ })), i.status === "error" ? /* @__PURE__ */ O(
210
234
  "div",
211
235
  {
212
236
  className: h,
213
- style: { display: "flex", alignItems: "center", justifyContent: "center", background: "#f5f5f5", ...r },
214
- children: /* @__PURE__ */ z("span", { style: { color: "#c00" }, children: [
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__ */ z("div", { style: { position: "relative", ...r }, className: h, children: [
220
- l.status === "loading" && /* @__PURE__ */ T(
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,149 +253,185 @@ const bt = { lat: 49.6116, lon: 6.1319 }, Rt = "basemap_2015_global", Ut = et(
229
253
  background: "rgba(255,255,255,0.7)",
230
254
  zIndex: 10
231
255
  },
232
- children: /* @__PURE__ */ T("span", { children: "Loading map…" })
256
+ children: /* @__PURE__ */ O("span", { children: "Loading map…" })
233
257
  }
234
258
  ),
235
- /* @__PURE__ */ T(
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, e, o) {
246
- const i = window.ol;
247
- if (!i) return;
248
- const { easting: s, northing: t } = P(e.lat, e.lon);
249
- if (o.current) {
250
- o.current.setPosition([s, t]);
251
- return;
252
- }
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,
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
- h.setPosition([s, t]), n.addOverlay(h), o.current = h;
292
+ return t.addOverlay(e), o.current = e, e;
261
293
  }
262
- function At(n, e) {
263
- !e.current || !window.ol || (e.current.setPosition(void 0), e.current = null);
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);
264
302
  }
265
- const yt = `<svg xmlns="http://www.w3.org/2000/svg" width="30" height="40" viewBox="0 0 30 40">
303
+ function Ut(t, n, o) {
304
+ if (t !== "none")
305
+ return n || (t === "fixed" ? o : void 0);
306
+ }
307
+ function Dt(t, n, o) {
308
+ return o && n !== "none" ? o : t ?? ot;
309
+ }
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
- </svg>`, St = "https://api.geoportail.lu/geocoder/reverseGeocode";
270
- function Ct() {
271
- const [n, e] = F({
314
+ </svg>`;
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);
321
+ }
322
+ const [r, e] = s(n, St, et);
323
+ return { lat: e, lon: r };
324
+ }
325
+ const Ft = "https://apiv3.geoportail.lu/geocode/reverse";
326
+ function Wt() {
327
+ const [t, n] = F({
272
328
  status: "idle",
273
329
  address: null,
274
330
  error: null
275
- }), o = R(null);
276
- S(() => () => {
277
- var t;
278
- (t = o.current) == null || t.abort();
331
+ }), o = b(null);
332
+ T(() => () => {
333
+ var e;
334
+ (e = o.current) == null || e.abort();
279
335
  }, []);
280
- const i = I(async (t) => {
281
- var h, r;
336
+ const s = U(async (e) => {
337
+ var h, c, l;
282
338
  (h = o.current) == null || h.abort();
283
339
  const f = new AbortController();
284
- o.current = f, e({ status: "loading", address: null, error: null });
340
+ o.current = f, n({ status: "loading", address: null, error: null });
285
341
  try {
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)
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)
293
349
  throw new Error("No results returned for this position");
294
- e({
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({
295
355
  status: "success",
296
356
  address: {
297
- label: g.name ?? "",
298
- distance: g.distance ?? 0,
299
- easting: g.easting,
300
- northing: g.northing
357
+ label: L,
358
+ distance: a.distance ?? 0,
359
+ easting: g,
360
+ northing: w
301
361
  },
302
362
  error: null
303
363
  });
304
- } catch (c) {
305
- if (c instanceof DOMException && c.name === "AbortError") return;
306
- e({
364
+ } catch (u) {
365
+ if (u instanceof DOMException && u.name === "AbortError") return;
366
+ n({
307
367
  status: "error",
308
368
  address: null,
309
- error: c instanceof Error ? c : new Error(String(c))
369
+ error: u instanceof Error ? u : new Error(String(u))
310
370
  });
311
371
  }
312
- }, []), s = I(() => {
313
- var t;
314
- (t = o.current) == null || t.abort(), e({ 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 });
315
375
  }, []);
316
- return { state: n, lookup: i, reset: s };
376
+ return { state: t, lookup: s, reset: r };
317
377
  }
318
- const _t = "https://apiv3.geoportail.lu/geocode/search";
319
- function Dt() {
320
- const [n, e] = F({
378
+ const Nt = "https://apiv3.geoportail.lu/geocode/search";
379
+ function zt() {
380
+ const [t, n] = F({
321
381
  status: "idle",
322
382
  results: null,
323
383
  error: null
324
- }), o = R(null);
325
- S(() => () => {
326
- var t;
327
- (t = o.current) == null || t.abort();
384
+ }), o = b(null);
385
+ T(() => () => {
386
+ var e;
387
+ (e = o.current) == null || e.abort();
328
388
  }, []);
329
- const i = I(async (t) => {
389
+ const s = U(async (e) => {
330
390
  var h;
331
391
  (h = o.current) == null || h.abort();
332
392
  const f = new AbortController();
333
- o.current = f, e({ status: "loading", results: null, error: null });
393
+ o.current = f, n({ status: "loading", results: null, error: null });
334
394
  try {
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;
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;
342
402
  return {
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
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
351
411
  };
352
412
  });
353
- e({ status: "success", results: l, error: null });
354
- } catch (r) {
355
- if (r instanceof DOMException && r.name === "AbortError") return;
356
- e({
413
+ n({ status: "success", results: i, error: null });
414
+ } catch (c) {
415
+ if (c instanceof DOMException && c.name === "AbortError") return;
416
+ n({
357
417
  status: "error",
358
418
  results: null,
359
- error: r instanceof Error ? r : new Error(String(r))
419
+ error: c instanceof Error ? c : new Error(String(c))
360
420
  });
361
421
  }
362
- }, []), s = I(() => {
363
- var t;
364
- (t = o.current) == null || t.abort(), e({ 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 });
365
425
  }, []);
366
- return { state: n, search: i, reset: s };
426
+ return { state: t, search: s, reset: r };
367
427
  }
368
428
  export {
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
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
376
436
  };
377
437
  //# sourceMappingURL=react-geoportail.js.map