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