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