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