@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.
- package/README.md +15 -8
- package/dist/hooks/useReverseGeocode.d.ts +3 -1
- package/dist/react-geoportail.js +179 -167
- 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 +16 -1
- package/dist/utils/loader.d.ts +5 -1
- package/package.json +2 -2
package/dist/react-geoportail.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
const
|
|
4
|
-
let
|
|
5
|
-
function
|
|
6
|
-
return
|
|
7
|
-
throw
|
|
8
|
-
}),
|
|
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
|
|
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
|
-
|
|
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
|
|
25
|
+
async function Tt() {
|
|
26
26
|
if (window.lux) {
|
|
27
|
-
|
|
27
|
+
V(window.lux);
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
await
|
|
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
|
|
37
|
+
function bt() {
|
|
33
38
|
return new Promise((t, n) => {
|
|
34
|
-
|
|
39
|
+
yt(t, n);
|
|
35
40
|
});
|
|
36
41
|
}
|
|
37
|
-
function
|
|
38
|
-
t.setBaseUrl(
|
|
42
|
+
function V(t) {
|
|
43
|
+
t.setBaseUrl(lt, ut), t.setI18nUrl(dt);
|
|
39
44
|
}
|
|
40
|
-
function
|
|
45
|
+
function I(t, n) {
|
|
41
46
|
const o = document.getElementById(t);
|
|
42
|
-
return o ?
|
|
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(
|
|
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
|
|
57
|
+
function xt(t, n) {
|
|
53
58
|
const o = document.getElementById(t);
|
|
54
|
-
return o ?
|
|
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(
|
|
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
|
|
65
|
-
const s = t.getAttribute(
|
|
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(
|
|
82
|
+
t.setAttribute(O, "loaded"), f(), n();
|
|
78
83
|
}, e = () => {
|
|
79
|
-
t.setAttribute(
|
|
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
|
|
86
|
-
const [t, n] =
|
|
90
|
+
function Pt() {
|
|
91
|
+
const [t, n] = X({
|
|
87
92
|
status: "loading",
|
|
88
93
|
lux: null,
|
|
89
94
|
error: null
|
|
90
95
|
});
|
|
91
|
-
return
|
|
96
|
+
return x(() => {
|
|
92
97
|
let o = !1;
|
|
93
|
-
return
|
|
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
|
|
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
|
|
115
|
+
function P(t) {
|
|
111
116
|
return t * 180 / Math.PI;
|
|
112
117
|
}
|
|
113
|
-
function
|
|
114
|
-
const o = R(t), s = R(n), r = Math.sin(o), e = Math.cos(o), f = Math.sin(s),
|
|
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 +
|
|
117
|
-
lon: n +
|
|
121
|
+
lat: t + P(L),
|
|
122
|
+
lon: n + P(M)
|
|
118
123
|
};
|
|
119
124
|
}
|
|
120
|
-
function
|
|
121
|
-
const o = R(t), s = R(n), r = Math.sin(o), e = Math.cos(o), f = Math.sin(s),
|
|
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 +
|
|
124
|
-
lon: n +
|
|
128
|
+
lat: t + P(a),
|
|
129
|
+
lon: n + P(w)
|
|
125
130
|
};
|
|
126
131
|
}
|
|
127
|
-
function
|
|
128
|
-
const o = R(t), s = R(n), r = R(
|
|
129
|
-
return { easting:
|
|
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
|
|
132
|
-
const o = t -
|
|
133
|
-
return { lat:
|
|
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
|
|
140
|
+
function $(t) {
|
|
136
141
|
const n = m, o = n * n, s = o * n;
|
|
137
|
-
return
|
|
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
|
|
140
|
-
const o =
|
|
141
|
-
return
|
|
144
|
+
function J(t, n) {
|
|
145
|
+
const o = St(t, n);
|
|
146
|
+
return Ut(o.lat, o.lon);
|
|
142
147
|
}
|
|
143
|
-
function
|
|
144
|
-
const o =
|
|
145
|
-
return
|
|
148
|
+
function ot(t, n) {
|
|
149
|
+
const o = At(t, n);
|
|
150
|
+
return Ot(o.lat, o.lon);
|
|
146
151
|
}
|
|
147
|
-
const
|
|
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 =
|
|
156
|
+
bgLayer: s = Gt,
|
|
152
157
|
markerMode: r = "none",
|
|
153
158
|
markerPosition: e,
|
|
154
159
|
onMarkerPlace: f,
|
|
155
|
-
className:
|
|
156
|
-
style:
|
|
160
|
+
className: g,
|
|
161
|
+
style: i,
|
|
157
162
|
layers: l
|
|
158
163
|
}, u) {
|
|
159
|
-
const
|
|
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
|
|
162
|
-
return
|
|
163
|
-
var
|
|
164
|
-
if (
|
|
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 =
|
|
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: [
|
|
175
|
+
position: [S, y],
|
|
171
176
|
...l && l.length > 0 ? { layers: l, layerOpacities: l.map(() => 1) } : {}
|
|
172
177
|
});
|
|
173
|
-
return a.current =
|
|
174
|
-
E ||
|
|
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,
|
|
181
|
+
E = !0, a.current = null, w.current = null, h.current = null, M(!1);
|
|
177
182
|
};
|
|
178
|
-
}, [
|
|
183
|
+
}, [c.status]), x(() => {
|
|
179
184
|
const E = a.current;
|
|
180
|
-
if (!E ||
|
|
181
|
-
const v =
|
|
185
|
+
if (!E || c.status !== "ready" || !L) return;
|
|
186
|
+
const v = Bt(
|
|
182
187
|
r,
|
|
183
188
|
e,
|
|
184
|
-
n ??
|
|
189
|
+
n ?? rt
|
|
185
190
|
);
|
|
186
191
|
if (!v) {
|
|
187
|
-
|
|
192
|
+
Nt(w);
|
|
188
193
|
return;
|
|
189
194
|
}
|
|
190
|
-
|
|
195
|
+
Ft(E, v, w);
|
|
191
196
|
}, [
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
]),
|
|
204
|
+
]), x(() => {
|
|
200
205
|
const E = a.current;
|
|
201
|
-
if (!E ||
|
|
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 = (...
|
|
208
|
+
const v = (...S) => {
|
|
204
209
|
var N;
|
|
205
|
-
const
|
|
206
|
-
if (!
|
|
207
|
-
const
|
|
208
|
-
|
|
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
|
|
211
|
-
|
|
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
|
-
|
|
215
|
-
|
|
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:
|
|
227
|
+
const { easting: S, northing: y } = J(E.lat, E.lon);
|
|
223
228
|
if (v.setCenter) {
|
|
224
|
-
v.setCenter([
|
|
229
|
+
v.setCenter([S, y], void 0, Dt);
|
|
225
230
|
return;
|
|
226
231
|
}
|
|
227
|
-
v.getView().setCenter(
|
|
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
|
-
})),
|
|
238
|
+
})), c.status === "error" ? /* @__PURE__ */ A(
|
|
234
239
|
"div",
|
|
235
240
|
{
|
|
236
|
-
className:
|
|
237
|
-
style: { display: "flex", alignItems: "center", justifyContent: "center", background: "#f5f5f5", ...
|
|
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
|
-
|
|
245
|
+
c.error.message
|
|
241
246
|
] })
|
|
242
247
|
}
|
|
243
|
-
) : /* @__PURE__ */ Y("div", { style: { position: "relative", ...
|
|
244
|
-
|
|
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__ */
|
|
261
|
+
children: /* @__PURE__ */ A("span", { children: "Loading map…" })
|
|
257
262
|
}
|
|
258
263
|
),
|
|
259
|
-
/* @__PURE__ */
|
|
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
|
|
270
|
-
const s =
|
|
271
|
-
s && s.setPosition(
|
|
274
|
+
function Ft(t, n, o) {
|
|
275
|
+
const s = st(t, n, o);
|
|
276
|
+
s && s.setPosition(at(n));
|
|
272
277
|
}
|
|
273
|
-
function
|
|
274
|
-
const r =
|
|
278
|
+
function Xt(t, n, o, s) {
|
|
279
|
+
const r = st(t, o, s);
|
|
275
280
|
r && r.setPosition(n);
|
|
276
281
|
}
|
|
277
|
-
function
|
|
282
|
+
function Nt(t) {
|
|
278
283
|
t.current && t.current.setPosition(void 0);
|
|
279
284
|
}
|
|
280
|
-
function
|
|
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 =
|
|
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
|
|
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 } =
|
|
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,
|
|
306
|
+
return o([t.lon, t.lat], et, jt);
|
|
302
307
|
}
|
|
303
|
-
function
|
|
308
|
+
function Bt(t, n, o) {
|
|
304
309
|
if (t !== "none")
|
|
305
310
|
return n || (t === "fixed" ? o : void 0);
|
|
306
311
|
}
|
|
307
|
-
function
|
|
308
|
-
return o && n !== "none" ? o : t ??
|
|
312
|
+
function $t(t, n, o) {
|
|
313
|
+
return o && n !== "none" ? o : t ?? rt;
|
|
309
314
|
}
|
|
310
|
-
const
|
|
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
|
|
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 [
|
|
320
|
-
return
|
|
324
|
+
const [g, i] = n;
|
|
325
|
+
return ot(g, i);
|
|
321
326
|
}
|
|
322
|
-
const [r, e] = s(n,
|
|
327
|
+
const [r, e] = s(n, It, et);
|
|
323
328
|
return { lat: e, lon: r };
|
|
324
329
|
}
|
|
325
|
-
const
|
|
326
|
-
function
|
|
327
|
-
const [t, n] =
|
|
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 =
|
|
332
|
-
|
|
336
|
+
}), o = C(null);
|
|
337
|
+
x(() => () => {
|
|
333
338
|
var e;
|
|
334
339
|
(e = o.current) == null || e.abort();
|
|
335
340
|
}, []);
|
|
336
|
-
const s =
|
|
337
|
-
var
|
|
338
|
-
(
|
|
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(
|
|
347
|
+
const u = new URL(zt);
|
|
343
348
|
u.searchParams.set("lat", String(e.lat)), u.searchParams.set("lon", String(e.lon));
|
|
344
|
-
const
|
|
345
|
-
if (!
|
|
346
|
-
throw new Error(`Reverse geocode request failed: ${
|
|
347
|
-
const a = (
|
|
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
|
|
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(", "), [
|
|
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:
|
|
362
|
+
label: w,
|
|
358
363
|
distance: a.distance ?? 0,
|
|
359
|
-
easting:
|
|
360
|
-
northing:
|
|
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 =
|
|
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
|
|
379
|
-
function
|
|
380
|
-
|
|
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 =
|
|
385
|
-
|
|
396
|
+
}), o = C(null);
|
|
397
|
+
x(() => () => {
|
|
386
398
|
var e;
|
|
387
399
|
(e = o.current) == null || e.abort();
|
|
388
400
|
}, []);
|
|
389
|
-
const s =
|
|
390
|
-
var
|
|
391
|
-
(
|
|
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
|
|
396
|
-
e.queryString ?
|
|
397
|
-
const l = await fetch(
|
|
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
|
|
401
|
-
var a,
|
|
412
|
+
const c = ((await l.json()).results ?? []).map((p) => {
|
|
413
|
+
var a, w, h, L, M;
|
|
402
414
|
return {
|
|
403
|
-
latLon:
|
|
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: (
|
|
408
|
-
num: (
|
|
409
|
-
zip: (
|
|
410
|
-
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:
|
|
414
|
-
} catch (
|
|
415
|
-
if (
|
|
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:
|
|
431
|
+
error: i instanceof Error ? i : new Error(String(i))
|
|
420
432
|
});
|
|
421
433
|
}
|
|
422
|
-
}, []), r =
|
|
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
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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
|