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