@dacostafilipe/react-geoportail 0.1.1 → 0.1.2
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/components/GeoportailMap.d.ts +58 -0
- package/dist/demo/main.d.ts +1 -0
- package/dist/hooks/useGeocode.d.ts +44 -0
- package/dist/hooks/useLuxApi.d.ts +20 -0
- package/dist/hooks/useReverseGeocode.d.ts +35 -0
- package/dist/index.d.ts +11 -0
- package/dist/react-geoportail.js +321 -0
- package/dist/react-geoportail.js.map +1 -0
- package/dist/react-geoportail.umd.cjs +6 -0
- package/dist/react-geoportail.umd.cjs.map +1 -0
- package/dist/types/index.d.ts +28 -0
- package/dist/utils/coordinates.d.ts +26 -0
- package/dist/utils/loader.d.ts +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { LatLon, MapClickHandler, MarkerMode } from '../types/index.ts';
|
|
3
|
+
import { LuxMapInstance } from '../types/lux.d.ts';
|
|
4
|
+
|
|
5
|
+
export interface GeoportailMapProps {
|
|
6
|
+
/**
|
|
7
|
+
* Initial center of the map.
|
|
8
|
+
* Defaults to Luxembourg City (lat: 49.6116, lon: 6.1319).
|
|
9
|
+
*/
|
|
10
|
+
center?: LatLon;
|
|
11
|
+
/** Initial zoom level (1–20). Default: 12 */
|
|
12
|
+
zoom?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Background layer identifier.
|
|
15
|
+
* Default: 'basemap_2015_global'
|
|
16
|
+
*/
|
|
17
|
+
bgLayer?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Controls pin/marker behaviour:
|
|
20
|
+
* - 'none' — no marker
|
|
21
|
+
* - 'fixed' — show a marker at `markerPosition` (does not move on click)
|
|
22
|
+
* - 'click' — user clicks map to place/move the pin; fires `onMarkerPlace`
|
|
23
|
+
*
|
|
24
|
+
* Default: 'none'
|
|
25
|
+
*/
|
|
26
|
+
markerMode?: MarkerMode;
|
|
27
|
+
/**
|
|
28
|
+
* Position of the marker when `markerMode` is 'fixed' or to pre-set an
|
|
29
|
+
* initial pin when `markerMode` is 'click'.
|
|
30
|
+
*/
|
|
31
|
+
markerPosition?: LatLon;
|
|
32
|
+
/**
|
|
33
|
+
* Called whenever the user places a pin (markerMode === 'click').
|
|
34
|
+
* Receives the WGS84 lat/lon of the clicked point.
|
|
35
|
+
*/
|
|
36
|
+
onMarkerPlace?: MapClickHandler;
|
|
37
|
+
/** CSS class applied to the map container div */
|
|
38
|
+
className?: string;
|
|
39
|
+
/** Inline styles for the map container div */
|
|
40
|
+
style?: React.CSSProperties;
|
|
41
|
+
/** Additional numeric layer IDs to add on top of the background */
|
|
42
|
+
layers?: number[];
|
|
43
|
+
}
|
|
44
|
+
export interface GeoportailMapHandle {
|
|
45
|
+
/** Returns the underlying lux.Map instance (or null before ready) */
|
|
46
|
+
getLuxMap(): LuxMapInstance | null;
|
|
47
|
+
/** Programmatically move the map center */
|
|
48
|
+
setCenter(coords: LatLon): void;
|
|
49
|
+
/** Programmatically set zoom */
|
|
50
|
+
setZoom(zoom: number): void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Renders a Geoportail Luxembourg map inside a React component.
|
|
54
|
+
*
|
|
55
|
+
* Expose a ref (`GeoportailMapHandle`) to access the underlying lux.Map instance
|
|
56
|
+
* or imperatively control the view.
|
|
57
|
+
*/
|
|
58
|
+
export declare const GeoportailMap: React.ForwardRefExoticComponent<GeoportailMapProps & React.RefAttributes<GeoportailMapHandle>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { GeocodeQuery, LatLon } from '../types/index.ts';
|
|
2
|
+
|
|
3
|
+
export interface GeocodeResultItem {
|
|
4
|
+
latLon: LatLon;
|
|
5
|
+
easting: number;
|
|
6
|
+
northing: number;
|
|
7
|
+
accuracy: number;
|
|
8
|
+
street?: string;
|
|
9
|
+
num?: string;
|
|
10
|
+
zip?: string;
|
|
11
|
+
locality?: string;
|
|
12
|
+
}
|
|
13
|
+
export type GeocodeState = {
|
|
14
|
+
status: 'idle';
|
|
15
|
+
results: null;
|
|
16
|
+
error: null;
|
|
17
|
+
} | {
|
|
18
|
+
status: 'loading';
|
|
19
|
+
results: null;
|
|
20
|
+
error: null;
|
|
21
|
+
} | {
|
|
22
|
+
status: 'success';
|
|
23
|
+
results: GeocodeResultItem[];
|
|
24
|
+
error: null;
|
|
25
|
+
} | {
|
|
26
|
+
status: 'error';
|
|
27
|
+
results: null;
|
|
28
|
+
error: Error;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Hook for forward geocoding: search for a Luxembourg address and get coordinates.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const { state, search } = useGeocode();
|
|
35
|
+
* search({ queryString: '1 rue du Fort Thüngen, Luxembourg' });
|
|
36
|
+
* if (state.status === 'success') {
|
|
37
|
+
* const { lat, lon } = state.results[0].latLon;
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
export declare function useGeocode(): {
|
|
41
|
+
state: GeocodeState;
|
|
42
|
+
search: (query: GeocodeQuery) => Promise<void>;
|
|
43
|
+
reset: () => void;
|
|
44
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LuxNamespace } from '../types/lux.d.ts';
|
|
2
|
+
|
|
3
|
+
export type LuxApiState = {
|
|
4
|
+
status: 'loading';
|
|
5
|
+
lux: null;
|
|
6
|
+
error: null;
|
|
7
|
+
} | {
|
|
8
|
+
status: 'ready';
|
|
9
|
+
lux: LuxNamespace;
|
|
10
|
+
error: null;
|
|
11
|
+
} | {
|
|
12
|
+
status: 'error';
|
|
13
|
+
lux: null;
|
|
14
|
+
error: Error;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Loads the Geoportail apiv3 script and returns the `lux` namespace once ready.
|
|
18
|
+
* Deduplicates the script load — safe to call from multiple components.
|
|
19
|
+
*/
|
|
20
|
+
export declare function useLuxApi(): LuxApiState;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { LatLon, Address } from '../types/index.ts';
|
|
2
|
+
|
|
3
|
+
export type ReverseGeocodeState = {
|
|
4
|
+
status: 'idle';
|
|
5
|
+
address: null;
|
|
6
|
+
error: null;
|
|
7
|
+
} | {
|
|
8
|
+
status: 'loading';
|
|
9
|
+
address: null;
|
|
10
|
+
error: null;
|
|
11
|
+
} | {
|
|
12
|
+
status: 'success';
|
|
13
|
+
address: Address;
|
|
14
|
+
error: null;
|
|
15
|
+
} | {
|
|
16
|
+
status: 'error';
|
|
17
|
+
address: null;
|
|
18
|
+
error: Error;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Hook for reverse geocoding: convert a WGS84 lat/lon to a Luxembourg address.
|
|
22
|
+
*
|
|
23
|
+
* Uses the Geoportail REST reverse geocode endpoint — no API key required.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const { state, lookup } = useReverseGeocode();
|
|
27
|
+
* // ...
|
|
28
|
+
* lookup({ lat: 49.6116, lon: 6.1319 });
|
|
29
|
+
* if (state.status === 'success') console.log(state.address.label);
|
|
30
|
+
*/
|
|
31
|
+
export declare function useReverseGeocode(): {
|
|
32
|
+
state: ReverseGeocodeState;
|
|
33
|
+
lookup: (position: LatLon) => Promise<void>;
|
|
34
|
+
reset: () => void;
|
|
35
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { GeoportailMap } from './components/GeoportailMap.tsx';
|
|
2
|
+
export type { GeoportailMapProps, GeoportailMapHandle } from './components/GeoportailMap.tsx';
|
|
3
|
+
export { useLuxApi } from './hooks/useLuxApi.ts';
|
|
4
|
+
export type { LuxApiState } from './hooks/useLuxApi.ts';
|
|
5
|
+
export { useReverseGeocode } from './hooks/useReverseGeocode.ts';
|
|
6
|
+
export type { ReverseGeocodeState } from './hooks/useReverseGeocode.ts';
|
|
7
|
+
export { useGeocode } from './hooks/useGeocode.ts';
|
|
8
|
+
export type { GeocodeState, GeocodeResultItem } from './hooks/useGeocode.ts';
|
|
9
|
+
export { latLonToLuref, lurefToLatLon } from './utils/coordinates.ts';
|
|
10
|
+
export { loadLuxApi } from './utils/loader.ts';
|
|
11
|
+
export type { LatLon, Address, GeocodeQuery, MapClickHandler, MarkerMode, } from './types/index.ts';
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { jsx as S, jsxs as $ } from "react/jsx-runtime";
|
|
2
|
+
import { useState as F, useEffect as O, forwardRef as nt, useId as st, useRef as y, useImperativeHandle as ot, useCallback as T } from "react";
|
|
3
|
+
const B = "//apiv3.geoportail.lu/apiv3loader.js", j = "geoportail-apiv3-loader";
|
|
4
|
+
let R = null;
|
|
5
|
+
function et() {
|
|
6
|
+
return R || (R = new Promise((c, t) => {
|
|
7
|
+
if (typeof window < "u" && window.lux) {
|
|
8
|
+
c();
|
|
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(j)) {
|
|
16
|
+
V(c, t);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const n = document.createElement("script");
|
|
20
|
+
n.id = j, n.src = B, n.async = !0, n.onload = () => V(c, t), n.onerror = () => {
|
|
21
|
+
R = null, t(new Error(`Failed to load Geoportail API from ${B}`));
|
|
22
|
+
}, document.head.appendChild(n);
|
|
23
|
+
}), R);
|
|
24
|
+
}
|
|
25
|
+
function V(c, t) {
|
|
26
|
+
let l = 0;
|
|
27
|
+
const a = () => {
|
|
28
|
+
if (window.lux) {
|
|
29
|
+
c();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (l++ >= 100) {
|
|
33
|
+
R = null, t(new Error("Timed out waiting for window.lux to be defined"));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
setTimeout(a, 50);
|
|
37
|
+
};
|
|
38
|
+
a();
|
|
39
|
+
}
|
|
40
|
+
function rt() {
|
|
41
|
+
const [c, t] = F({
|
|
42
|
+
status: "loading",
|
|
43
|
+
lux: null,
|
|
44
|
+
error: null
|
|
45
|
+
});
|
|
46
|
+
return O(() => {
|
|
47
|
+
let n = !1;
|
|
48
|
+
return et().then(() => {
|
|
49
|
+
n || t({ status: "ready", lux: window.lux, error: null });
|
|
50
|
+
}).catch((l) => {
|
|
51
|
+
n || t({
|
|
52
|
+
status: "error",
|
|
53
|
+
lux: null,
|
|
54
|
+
error: l instanceof Error ? l : new Error(String(l))
|
|
55
|
+
});
|
|
56
|
+
}), () => {
|
|
57
|
+
n = !0;
|
|
58
|
+
};
|
|
59
|
+
}, []), c;
|
|
60
|
+
}
|
|
61
|
+
const Z = 8e4, q = 1e5, H = 6.16666666666667, k = 49.8333333333333, C = 1, L = 6378388, z = 1 / 297, P = L * (1 - z), m = 1 - P * P / (L * L), D = -87, _ = -98, J = -121;
|
|
62
|
+
function v(c) {
|
|
63
|
+
return c * Math.PI / 180;
|
|
64
|
+
}
|
|
65
|
+
function A(c) {
|
|
66
|
+
return c * 180 / Math.PI;
|
|
67
|
+
}
|
|
68
|
+
function ct(c, t) {
|
|
69
|
+
const n = v(c), l = v(t), a = Math.sin(n), s = Math.cos(n), p = Math.sin(l), g = Math.cos(l), o = 6378137, r = 1 / 298.257223563, h = o * (1 - r), f = 1 - h * h / (o * o), u = L - o, e = z - r, d = o / Math.sqrt(1 - f * a * a), w = 1 / (o * (1 - f) / Math.pow(1 - f * a * a, 1.5)) * (d * (f / (1 - f)) * a * s * (u / o) + (d / o + 1) * a * s * e * (o / h) - (D * a * g + _ * a * p - J * s)), x = 1 / (d * s) * (-D * p + _ * g);
|
|
70
|
+
return {
|
|
71
|
+
lat: c + A(w),
|
|
72
|
+
lon: t + A(x)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function at(c, t) {
|
|
76
|
+
const n = v(c), l = v(t), a = Math.sin(n), s = Math.cos(n), p = Math.sin(l), g = Math.cos(l), o = L / Math.sqrt(1 - m * a * a), r = L * (1 - m) / Math.pow(1 - m * a * a, 1.5), h = 6378137 - L, u = 1 / 298.257223563 - z, e = 1 / r * (o * (m / (1 - m)) * a * s * (h / L) + (o / L + 1) * a * s * u * (L / P) + (D * a * g + _ * a * p - J * s)), d = 1 / (o * s) * (D * p - _ * g);
|
|
77
|
+
return {
|
|
78
|
+
lat: c + A(e),
|
|
79
|
+
lon: t + A(d)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function it(c, t) {
|
|
83
|
+
const n = v(c), l = v(t), a = v(H), s = v(k), p = Math.sin(n), g = Math.cos(n), o = Math.tan(n), r = L / Math.sqrt(1 - m * p * p), h = o * o, f = m / (1 - m) * g * g, u = l - a, e = g * u, d = U(n), M = U(s), w = Z + C * r * (e + e * e * e * (1 - h + f) / 6 + e * e * e * e * e * (5 - 18 * h + h * h + 72 * f) / 120), x = q + C * (d - M + r * o * (e * e / 2 + e * e * e * e * (5 - h + 9 * f + 4 * f * f) / 24 + e * e * e * e * e * e * (61 - 58 * h + h * h + 600 * f) / 720));
|
|
84
|
+
return { easting: w, northing: x };
|
|
85
|
+
}
|
|
86
|
+
function lt(c, t) {
|
|
87
|
+
const n = c - Z, l = t - q, a = v(k), s = v(H), o = (U(a) + l / C) / (L * (1 - m / 4 - 3 * m * m / 64)), r = (1 - Math.sqrt(1 - m)) / (1 + Math.sqrt(1 - m)), h = o + (3 * r / 2 - 27 * r * r * r / 32) * Math.sin(2 * o) + (21 * r * r / 16 - 55 * r * r * r * r / 32) * Math.sin(4 * o) + 151 * r * r * r / 96 * Math.sin(6 * o), f = Math.sin(h), u = Math.cos(h), e = Math.tan(h), d = L / Math.sqrt(1 - m * f * f), M = e * e, w = m / (1 - m) * u * u, x = L * (1 - m) / Math.pow(1 - m * f * f, 1.5), i = n / (d * C), E = h - d * e / x * (i * i / 2 - i * i * i * i * (5 + 3 * M + 10 * w - 4 * w * w) / 24 + i * i * i * i * i * i * (61 + 90 * M + 298 * w + 45 * M * M) / 720), b = s + (i - i * i * i * (1 + 2 * M + w) / 6 + i * i * i * i * i * (5 - 2 * w + 28 * M - 3 * w * w) / 120) / u;
|
|
88
|
+
return { lat: A(E), lon: A(b) };
|
|
89
|
+
}
|
|
90
|
+
function U(c) {
|
|
91
|
+
const t = m, n = t * t, l = n * t;
|
|
92
|
+
return L * ((1 - t / 4 - 3 * n / 64 - 5 * l / 256) * c - (3 * t / 8 + 3 * n / 32 + 45 * l / 1024) * Math.sin(2 * c) + (15 * n / 256 + 45 * l / 1024) * Math.sin(4 * c) - 35 * l / 3072 * Math.sin(6 * c));
|
|
93
|
+
}
|
|
94
|
+
function G(c, t) {
|
|
95
|
+
const n = ct(c, t);
|
|
96
|
+
return it(n.lat, n.lon);
|
|
97
|
+
}
|
|
98
|
+
function K(c, t) {
|
|
99
|
+
const n = lt(c, t);
|
|
100
|
+
return at(n.lat, n.lon);
|
|
101
|
+
}
|
|
102
|
+
const ut = { lat: 49.6116, lon: 6.1319 }, dt = "basemap_2015_global", Mt = nt(
|
|
103
|
+
function({
|
|
104
|
+
center: t = ut,
|
|
105
|
+
zoom: n = 12,
|
|
106
|
+
bgLayer: l = dt,
|
|
107
|
+
markerMode: a = "none",
|
|
108
|
+
markerPosition: s,
|
|
109
|
+
onMarkerPlace: p,
|
|
110
|
+
className: g,
|
|
111
|
+
style: o,
|
|
112
|
+
layers: r
|
|
113
|
+
}, h) {
|
|
114
|
+
const u = `gp-map-${st().replace(/:/g, "")}`, e = rt(), d = y(null), M = y(null), w = y(null), x = y(p);
|
|
115
|
+
return x.current = p, O(() => {
|
|
116
|
+
if (e.status !== "ready") return;
|
|
117
|
+
const i = e.lux, { easting: E, northing: b } = G(t.lat, t.lon), I = new i.Map({
|
|
118
|
+
target: u,
|
|
119
|
+
bgLayer: l,
|
|
120
|
+
zoom: n,
|
|
121
|
+
position: [E, b],
|
|
122
|
+
...r && r.length > 0 ? { layers: r, layerOpacities: r.map(() => 1) } : {}
|
|
123
|
+
});
|
|
124
|
+
return d.current = I, () => {
|
|
125
|
+
d.current = null, M.current = null, w.current = null;
|
|
126
|
+
};
|
|
127
|
+
}, [e.status, u]), O(() => {
|
|
128
|
+
const i = d.current;
|
|
129
|
+
if (!i || e.status !== "ready") return;
|
|
130
|
+
if (w.current && (i.un("singleclick", w.current), w.current = null), a === "none") {
|
|
131
|
+
ft(i, M);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const E = s ?? (a === "fixed" ? t : void 0);
|
|
135
|
+
if (E && Y(i, E, M), a === "click") {
|
|
136
|
+
const b = (...I) => {
|
|
137
|
+
var X;
|
|
138
|
+
const N = I[0];
|
|
139
|
+
if (!N.coordinate) return;
|
|
140
|
+
const [Q, tt] = N.coordinate, W = K(Q, tt);
|
|
141
|
+
Y(i, W, M), (X = x.current) == null || X.call(x, W);
|
|
142
|
+
};
|
|
143
|
+
w.current = b, i.on("singleclick", b);
|
|
144
|
+
}
|
|
145
|
+
}, [
|
|
146
|
+
e.status,
|
|
147
|
+
a,
|
|
148
|
+
s == null ? void 0 : s.lat,
|
|
149
|
+
s == null ? void 0 : s.lon,
|
|
150
|
+
t
|
|
151
|
+
]), ot(h, () => ({
|
|
152
|
+
getLuxMap: () => d.current,
|
|
153
|
+
setCenter(i) {
|
|
154
|
+
const E = d.current;
|
|
155
|
+
if (!E) return;
|
|
156
|
+
const { easting: b, northing: I } = G(i.lat, i.lon);
|
|
157
|
+
E.getView().setCenter([b, I]);
|
|
158
|
+
},
|
|
159
|
+
setZoom(i) {
|
|
160
|
+
var E;
|
|
161
|
+
(E = d.current) == null || E.getView().setZoom(i);
|
|
162
|
+
}
|
|
163
|
+
})), e.status === "error" ? /* @__PURE__ */ S(
|
|
164
|
+
"div",
|
|
165
|
+
{
|
|
166
|
+
className: g,
|
|
167
|
+
style: { display: "flex", alignItems: "center", justifyContent: "center", background: "#f5f5f5", ...o },
|
|
168
|
+
children: /* @__PURE__ */ $("span", { style: { color: "#c00" }, children: [
|
|
169
|
+
"Failed to load Geoportail API: ",
|
|
170
|
+
e.error.message
|
|
171
|
+
] })
|
|
172
|
+
}
|
|
173
|
+
) : /* @__PURE__ */ $("div", { style: { position: "relative", ...o }, className: g, children: [
|
|
174
|
+
e.status === "loading" && /* @__PURE__ */ S(
|
|
175
|
+
"div",
|
|
176
|
+
{
|
|
177
|
+
style: {
|
|
178
|
+
position: "absolute",
|
|
179
|
+
inset: 0,
|
|
180
|
+
display: "flex",
|
|
181
|
+
alignItems: "center",
|
|
182
|
+
justifyContent: "center",
|
|
183
|
+
background: "rgba(255,255,255,0.7)",
|
|
184
|
+
zIndex: 10
|
|
185
|
+
},
|
|
186
|
+
children: /* @__PURE__ */ S("span", { children: "Loading map…" })
|
|
187
|
+
}
|
|
188
|
+
),
|
|
189
|
+
/* @__PURE__ */ S(
|
|
190
|
+
"div",
|
|
191
|
+
{
|
|
192
|
+
id: u,
|
|
193
|
+
style: { width: "100%", height: "100%" }
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
] });
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
function Y(c, t, n) {
|
|
200
|
+
const l = window.ol;
|
|
201
|
+
if (!l) return;
|
|
202
|
+
const { easting: a, northing: s } = G(t.lat, t.lon);
|
|
203
|
+
if (n.current) {
|
|
204
|
+
n.current.setPosition([a, s]);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const p = document.createElement("div");
|
|
208
|
+
p.innerHTML = ht, p.style.cssText = "cursor:pointer;transform:translate(-50%,-100%);line-height:0;";
|
|
209
|
+
const g = new l.Overlay({
|
|
210
|
+
element: p,
|
|
211
|
+
positioning: "bottom-center",
|
|
212
|
+
stopEvent: !1
|
|
213
|
+
});
|
|
214
|
+
g.setPosition([a, s]), c.addOverlay(g), n.current = g;
|
|
215
|
+
}
|
|
216
|
+
function ft(c, t) {
|
|
217
|
+
!t.current || !window.ol || (t.current.setPosition(void 0), t.current = null);
|
|
218
|
+
}
|
|
219
|
+
const ht = `<svg xmlns="http://www.w3.org/2000/svg" width="30" height="40" viewBox="0 0 30 40">
|
|
220
|
+
<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"
|
|
221
|
+
fill="#e53935" stroke="#b71c1c" stroke-width="1.5"/>
|
|
222
|
+
<circle cx="15" cy="14" r="5" fill="white"/>
|
|
223
|
+
</svg>`, gt = "https://api.geoportail.lu/geocoder/reverseGeocode";
|
|
224
|
+
function Lt() {
|
|
225
|
+
const [c, t] = F({
|
|
226
|
+
status: "idle",
|
|
227
|
+
address: null,
|
|
228
|
+
error: null
|
|
229
|
+
}), n = y(null), l = T(async (s) => {
|
|
230
|
+
var g, o;
|
|
231
|
+
(g = n.current) == null || g.abort();
|
|
232
|
+
const p = new AbortController();
|
|
233
|
+
n.current = p, t({ status: "loading", address: null, error: null });
|
|
234
|
+
try {
|
|
235
|
+
const { easting: r, northing: h } = G(s.lat, s.lon), f = new URL(gt);
|
|
236
|
+
f.searchParams.set("easting", String(r)), f.searchParams.set("northing", String(h));
|
|
237
|
+
const u = await fetch(f.toString(), { signal: p.signal });
|
|
238
|
+
if (!u.ok)
|
|
239
|
+
throw new Error(`Reverse geocode request failed: ${u.status} ${u.statusText}`);
|
|
240
|
+
const d = (o = (await u.json()).results) == null ? void 0 : o[0];
|
|
241
|
+
if (!d)
|
|
242
|
+
throw new Error("No results returned for this position");
|
|
243
|
+
t({
|
|
244
|
+
status: "success",
|
|
245
|
+
address: {
|
|
246
|
+
label: d.name ?? "",
|
|
247
|
+
distance: d.distance ?? 0,
|
|
248
|
+
easting: d.easting,
|
|
249
|
+
northing: d.northing
|
|
250
|
+
},
|
|
251
|
+
error: null
|
|
252
|
+
});
|
|
253
|
+
} catch (r) {
|
|
254
|
+
if (r instanceof DOMException && r.name === "AbortError") return;
|
|
255
|
+
t({
|
|
256
|
+
status: "error",
|
|
257
|
+
address: null,
|
|
258
|
+
error: r instanceof Error ? r : new Error(String(r))
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}, []), a = T(() => {
|
|
262
|
+
var s;
|
|
263
|
+
(s = n.current) == null || s.abort(), t({ status: "idle", address: null, error: null });
|
|
264
|
+
}, []);
|
|
265
|
+
return { state: c, lookup: l, reset: a };
|
|
266
|
+
}
|
|
267
|
+
const pt = "https://apiv3.geoportail.lu/geocode/search";
|
|
268
|
+
function Et() {
|
|
269
|
+
const [c, t] = F({
|
|
270
|
+
status: "idle",
|
|
271
|
+
results: null,
|
|
272
|
+
error: null
|
|
273
|
+
}), n = y(null), l = T(async (s) => {
|
|
274
|
+
var g;
|
|
275
|
+
(g = n.current) == null || g.abort();
|
|
276
|
+
const p = new AbortController();
|
|
277
|
+
n.current = p, t({ status: "loading", results: null, error: null });
|
|
278
|
+
try {
|
|
279
|
+
const o = new URL(pt);
|
|
280
|
+
s.queryString ? o.searchParams.set("queryString", s.queryString) : (s.num && o.searchParams.set("num", s.num), s.street && o.searchParams.set("street", s.street), s.zip && o.searchParams.set("zip", s.zip), s.locality && o.searchParams.set("locality", s.locality));
|
|
281
|
+
const r = await fetch(o.toString(), { signal: p.signal });
|
|
282
|
+
if (!r.ok)
|
|
283
|
+
throw new Error(`Geocode request failed: ${r.status} ${r.statusText}`);
|
|
284
|
+
const f = ((await r.json()).results ?? []).map((u) => {
|
|
285
|
+
var e, d, M, w;
|
|
286
|
+
return {
|
|
287
|
+
latLon: K(u.easting, u.northing),
|
|
288
|
+
easting: u.easting,
|
|
289
|
+
northing: u.northing,
|
|
290
|
+
accuracy: u.accuracy ?? 0,
|
|
291
|
+
street: (e = u.AddressDetails) == null ? void 0 : e.street,
|
|
292
|
+
num: (d = u.AddressDetails) == null ? void 0 : d.number,
|
|
293
|
+
zip: (M = u.AddressDetails) == null ? void 0 : M.zip,
|
|
294
|
+
locality: (w = u.AddressDetails) == null ? void 0 : w.locality
|
|
295
|
+
};
|
|
296
|
+
});
|
|
297
|
+
t({ status: "success", results: f, error: null });
|
|
298
|
+
} catch (o) {
|
|
299
|
+
if (o instanceof DOMException && o.name === "AbortError") return;
|
|
300
|
+
t({
|
|
301
|
+
status: "error",
|
|
302
|
+
results: null,
|
|
303
|
+
error: o instanceof Error ? o : new Error(String(o))
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
}, []), a = T(() => {
|
|
307
|
+
var s;
|
|
308
|
+
(s = n.current) == null || s.abort(), t({ status: "idle", results: null, error: null });
|
|
309
|
+
}, []);
|
|
310
|
+
return { state: c, search: l, reset: a };
|
|
311
|
+
}
|
|
312
|
+
export {
|
|
313
|
+
Mt as GeoportailMap,
|
|
314
|
+
G as latLonToLuref,
|
|
315
|
+
et as loadLuxApi,
|
|
316
|
+
K as lurefToLatLon,
|
|
317
|
+
Et as useGeocode,
|
|
318
|
+
rt as useLuxApi,
|
|
319
|
+
Lt as useReverseGeocode
|
|
320
|
+
};
|
|
321
|
+
//# sourceMappingURL=react-geoportail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-geoportail.js","sources":["../src/utils/loader.ts","../src/hooks/useLuxApi.ts","../src/utils/coordinates.ts","../src/components/GeoportailMap.tsx","../src/hooks/useReverseGeocode.ts","../src/hooks/useGeocode.ts"],"sourcesContent":["/**\n * Dynamically injects the Geoportail v3 API script and resolves when\n * the global `lux` namespace is available.\n */\n\nconst LUX_SCRIPT_URL = '//apiv3.geoportail.lu/apiv3loader.js';\nconst LUX_SCRIPT_ID = 'geoportail-apiv3-loader';\n\nlet loadPromise: Promise<void> | null = null;\n\n/**\n * Loads the Geoportail apiv3loader.js script exactly once.\n * Safe to call multiple times — subsequent calls return the same promise.\n */\nexport function loadLuxApi(): Promise<void> {\n if (loadPromise) return loadPromise;\n\n loadPromise = new Promise<void>((resolve, reject) => {\n // Already loaded (e.g. added manually in HTML)\n if (typeof window !== 'undefined' && window.lux) {\n resolve();\n return;\n }\n\n if (typeof document === 'undefined') {\n reject(new Error('loadLuxApi must run in a browser environment'));\n return;\n }\n\n // Avoid duplicate script tags\n if (document.getElementById(LUX_SCRIPT_ID)) {\n pollForLux(resolve, reject);\n return;\n }\n\n const script = document.createElement('script');\n script.id = LUX_SCRIPT_ID;\n script.src = LUX_SCRIPT_URL;\n script.async = true;\n\n script.onload = () => pollForLux(resolve, reject);\n script.onerror = () => {\n loadPromise = null; // allow retry\n reject(new Error(`Failed to load Geoportail API from ${LUX_SCRIPT_URL}`));\n };\n\n document.head.appendChild(script);\n });\n\n return loadPromise;\n}\n\n/**\n * The lux API may initialise asynchronously after the script loads.\n * Poll until window.lux is defined (max ~5 s).\n */\nfunction pollForLux(resolve: () => void, reject: (err: Error) => void): void {\n const maxAttempts = 100;\n let attempts = 0;\n\n const check = () => {\n if (window.lux) {\n resolve();\n return;\n }\n if (attempts++ >= maxAttempts) {\n loadPromise = null;\n reject(new Error('Timed out waiting for window.lux to be defined'));\n return;\n }\n setTimeout(check, 50);\n };\n\n check();\n}\n","import { useState, useEffect } from 'react';\nimport { loadLuxApi } from '../utils/loader.ts';\nimport type { LuxNamespace } from '../types/lux.d.ts';\n\nexport type LuxApiState =\n | { status: 'loading'; lux: null; error: null }\n | { status: 'ready'; lux: LuxNamespace; error: null }\n | { status: 'error'; lux: null; error: Error };\n\n/**\n * Loads the Geoportail apiv3 script and returns the `lux` namespace once ready.\n * Deduplicates the script load — safe to call from multiple components.\n */\nexport function useLuxApi(): LuxApiState {\n const [state, setState] = useState<LuxApiState>({\n status: 'loading',\n lux: null,\n error: null,\n });\n\n useEffect(() => {\n let cancelled = false;\n\n loadLuxApi()\n .then(() => {\n if (!cancelled) {\n setState({ status: 'ready', lux: window.lux!, error: null });\n }\n })\n .catch((err: unknown) => {\n if (!cancelled) {\n setState({\n status: 'error',\n lux: null,\n error: err instanceof Error ? err : new Error(String(err)),\n });\n }\n });\n\n return () => {\n cancelled = true;\n };\n }, []);\n\n return state;\n}\n","/**\n * Coordinate conversion between EPSG:2169 (Luxembourg TM) and EPSG:4326 (WGS84).\n *\n * The Geoportail API operates internally in EPSG:2169 but also accepts\n * position arrays in EPSG:4326 via `lux.Map` constructor options.\n *\n * For precise server-side conversion the REST API itself is authoritative.\n * The formulas below use a 6-parameter Helmert + transverse Mercator approach\n * sufficient for Luxembourg's territory (~50 km radius).\n *\n * Reference: IGN-L / ACT official parameters for LUREF (EPSG:2169).\n */\n\n// LUREF / Luxembourg TM projection constants (EPSG:2169)\nconst FE = 80000; // False Easting (m)\nconst FN = 100000; // False Northing (m)\nconst LON0 = 6.16666666666667; // Central meridian (6°10') in degrees\nconst LAT0 = 49.8333333333333; // Latitude of origin (49°50') in degrees\nconst SCALE = 1.0; // Scale factor at central meridian\nconst A = 6378388.0; // Semi-major axis (Hayford / International 1924)\nconst F = 1 / 297.0; // Flattening\nconst B = A * (1 - F); // Semi-minor axis\n\nconst E2 = 1 - (B * B) / (A * A); // First eccentricity squared\n\n// Helmert 7-parameter shift: ETRS89 -> ED50 (approximate for Luxembourg)\n// These values transform WGS84 (≈ETRS89) to ED50 used by LUREF\nconst DX = -87.0;\nconst DY = -98.0;\nconst DZ = -121.0;\n\nfunction degToRad(d: number): number {\n return (d * Math.PI) / 180;\n}\n\nfunction radToDeg(r: number): number {\n return (r * 180) / Math.PI;\n}\n\n/**\n * Molodensky transformation: WGS84 -> ED50 (approximate, <1 m accuracy).\n */\nfunction wgs84ToEd50(\n lat: number,\n lon: number\n): { lat: number; lon: number } {\n const latR = degToRad(lat);\n const lonR = degToRad(lon);\n\n const sinLat = Math.sin(latR);\n const cosLat = Math.cos(latR);\n const sinLon = Math.sin(lonR);\n const cosLon = Math.cos(lonR);\n\n const aWgs = 6378137.0;\n const fWgs = 1 / 298.257223563;\n const bWgs = aWgs * (1 - fWgs);\n const e2Wgs = 1 - (bWgs * bWgs) / (aWgs * aWgs);\n\n const da = A - aWgs;\n const df = F - fWgs;\n\n const N = aWgs / Math.sqrt(1 - e2Wgs * sinLat * sinLat);\n const M =\n (aWgs * (1 - e2Wgs)) /\n Math.pow(1 - e2Wgs * sinLat * sinLat, 1.5);\n\n const dLat =\n (1 / M) *\n (N * (e2Wgs / (1 - e2Wgs)) * sinLat * cosLat * (da / aWgs) +\n (N / aWgs + 1) * sinLat * cosLat * df * (aWgs / bWgs) -\n (DX * sinLat * cosLon + DY * sinLat * sinLon - DZ * cosLat));\n\n const dLon =\n (1 / (N * cosLat)) * (-DX * sinLon + DY * cosLon);\n\n return {\n lat: lat + radToDeg(dLat),\n lon: lon + radToDeg(dLon),\n };\n}\n\n/**\n * ED50 -> WGS84 (inverse Molodensky, approximate).\n */\nfunction ed50ToWgs84(\n lat: number,\n lon: number\n): { lat: number; lon: number } {\n const latR = degToRad(lat);\n const lonR = degToRad(lon);\n\n const sinLat = Math.sin(latR);\n const cosLat = Math.cos(latR);\n const sinLon = Math.sin(lonR);\n const cosLon = Math.cos(lonR);\n\n const N = A / Math.sqrt(1 - E2 * sinLat * sinLat);\n const M = (A * (1 - E2)) / Math.pow(1 - E2 * sinLat * sinLat, 1.5);\n\n const da = 6378137.0 - A;\n const fWgs = 1 / 298.257223563;\n const df = fWgs - F;\n\n const dLat =\n (1 / M) *\n (N * (E2 / (1 - E2)) * sinLat * cosLat * (da / A) +\n (N / A + 1) * sinLat * cosLat * df * (A / B) +\n (DX * sinLat * cosLon + DY * sinLat * sinLon - DZ * cosLat));\n\n const dLon =\n (1 / (N * cosLat)) * (DX * sinLon - DY * cosLon);\n\n return {\n lat: lat + radToDeg(dLat),\n lon: lon + radToDeg(dLon),\n };\n}\n\n/**\n * Transverse Mercator forward projection (ED50 lat/lon -> LUREF easting/northing).\n */\nfunction tmForward(lat: number, lon: number): { easting: number; northing: number } {\n const latR = degToRad(lat);\n const lonR = degToRad(lon);\n const lon0R = degToRad(LON0);\n const lat0R = degToRad(LAT0);\n\n const sinLat = Math.sin(latR);\n const cosLat = Math.cos(latR);\n const tanLat = Math.tan(latR);\n\n const N = A / Math.sqrt(1 - E2 * sinLat * sinLat);\n const T = tanLat * tanLat;\n const C = (E2 / (1 - E2)) * cosLat * cosLat;\n const dl = lonR - lon0R;\n const XX = cosLat * dl;\n\n // Meridian arc from equator to lat\n const M = meridianArc(latR);\n const M0 = meridianArc(lat0R);\n\n const easting =\n FE +\n SCALE *\n N *\n (XX +\n (XX * XX * XX * (1 - T + C)) / 6 +\n (XX * XX * XX * XX * XX * (5 - 18 * T + T * T + 72 * C)) / 120);\n\n const northing =\n FN +\n SCALE *\n (M -\n M0 +\n N *\n tanLat *\n (XX * XX / 2 +\n (XX * XX * XX * XX * (5 - T + 9 * C + 4 * C * C)) / 24 +\n (XX * XX * XX * XX * XX * XX *\n (61 - 58 * T + T * T + 600 * C)) /\n 720));\n\n return { easting, northing };\n}\n\n/**\n * Transverse Mercator inverse projection (LUREF easting/northing -> ED50 lat/lon).\n */\nfunction tmInverse(easting: number, northing: number): { lat: number; lon: number } {\n const x = easting - FE;\n const y = northing - FN;\n const lat0R = degToRad(LAT0);\n const lon0R = degToRad(LON0);\n const M0 = meridianArc(lat0R);\n\n // Footpoint latitude\n const M1 = M0 + y / SCALE;\n const mu = M1 / (A * (1 - E2 / 4 - (3 * E2 * E2) / 64));\n\n const e1 = (1 - Math.sqrt(1 - E2)) / (1 + Math.sqrt(1 - E2));\n const phi1 =\n mu +\n ((3 * e1) / 2 - (27 * e1 * e1 * e1) / 32) * Math.sin(2 * mu) +\n ((21 * e1 * e1) / 16 - (55 * e1 * e1 * e1 * e1) / 32) *\n Math.sin(4 * mu) +\n ((151 * e1 * e1 * e1) / 96) * Math.sin(6 * mu);\n\n const sinPhi1 = Math.sin(phi1);\n const cosPhi1 = Math.cos(phi1);\n const tanPhi1 = Math.tan(phi1);\n\n const N1 = A / Math.sqrt(1 - E2 * sinPhi1 * sinPhi1);\n const T1 = tanPhi1 * tanPhi1;\n const C1 = (E2 / (1 - E2)) * cosPhi1 * cosPhi1;\n const R1 =\n (A * (1 - E2)) / Math.pow(1 - E2 * sinPhi1 * sinPhi1, 1.5);\n const D = x / (N1 * SCALE);\n\n const lat =\n phi1 -\n ((N1 * tanPhi1) / R1) *\n (D * D / 2 -\n (D * D * D * D * (5 + 3 * T1 + 10 * C1 - 4 * C1 * C1)) / 24 +\n (D * D * D * D * D * D *\n (61 + 90 * T1 + 298 * C1 + 45 * T1 * T1)) /\n 720);\n\n const lon =\n lon0R +\n (D -\n (D * D * D * (1 + 2 * T1 + C1)) / 6 +\n (D * D * D * D * D * (5 - 2 * C1 + 28 * T1 - 3 * C1 * C1)) / 120) /\n cosPhi1;\n\n return { lat: radToDeg(lat), lon: radToDeg(lon) };\n}\n\nfunction meridianArc(latR: number): number {\n const e2 = E2;\n const e4 = e2 * e2;\n const e6 = e4 * e2;\n return (\n A *\n ((1 - e2 / 4 - (3 * e4) / 64 - (5 * e6) / 256) * latR -\n ((3 * e2) / 8 + (3 * e4) / 32 + (45 * e6) / 1024) *\n Math.sin(2 * latR) +\n ((15 * e4) / 256 + (45 * e6) / 1024) * Math.sin(4 * latR) -\n ((35 * e6) / 3072) * Math.sin(6 * latR))\n );\n}\n\n/**\n * Convert WGS84 (lat/lon) to EPSG:2169 (easting/northing).\n */\nexport function latLonToLuref(\n lat: number,\n lon: number\n): { easting: number; northing: number } {\n const ed50 = wgs84ToEd50(lat, lon);\n return tmForward(ed50.lat, ed50.lon);\n}\n\n/**\n * Convert EPSG:2169 (easting/northing) to WGS84 (lat/lon).\n */\nexport function lurefToLatLon(\n easting: number,\n northing: number\n): { lat: number; lon: number } {\n const ed50 = tmInverse(easting, northing);\n return ed50ToWgs84(ed50.lat, ed50.lon);\n}\n","import React, {\n useEffect,\n useRef,\n useId,\n forwardRef,\n useImperativeHandle,\n} from 'react';\nimport { useLuxApi } from '../hooks/useLuxApi.ts';\nimport { lurefToLatLon, latLonToLuref } from '../utils/coordinates.ts';\nimport type { LatLon, MapClickHandler, MarkerMode } from '../types/index.ts';\nimport type { LuxMapInstance } from '../types/lux.d.ts';\n\nexport interface GeoportailMapProps {\n /**\n * Initial center of the map.\n * Defaults to Luxembourg City (lat: 49.6116, lon: 6.1319).\n */\n center?: LatLon;\n\n /** Initial zoom level (1–20). Default: 12 */\n zoom?: number;\n\n /**\n * Background layer identifier.\n * Default: 'basemap_2015_global'\n */\n bgLayer?: string;\n\n /**\n * Controls pin/marker behaviour:\n * - 'none' — no marker\n * - 'fixed' — show a marker at `markerPosition` (does not move on click)\n * - 'click' — user clicks map to place/move the pin; fires `onMarkerPlace`\n *\n * Default: 'none'\n */\n markerMode?: MarkerMode;\n\n /**\n * Position of the marker when `markerMode` is 'fixed' or to pre-set an\n * initial pin when `markerMode` is 'click'.\n */\n markerPosition?: LatLon;\n\n /**\n * Called whenever the user places a pin (markerMode === 'click').\n * Receives the WGS84 lat/lon of the clicked point.\n */\n onMarkerPlace?: MapClickHandler;\n\n /** CSS class applied to the map container div */\n className?: string;\n\n /** Inline styles for the map container div */\n style?: React.CSSProperties;\n\n /** Additional numeric layer IDs to add on top of the background */\n layers?: number[];\n}\n\nexport interface GeoportailMapHandle {\n /** Returns the underlying lux.Map instance (or null before ready) */\n getLuxMap(): LuxMapInstance | null;\n /** Programmatically move the map center */\n setCenter(coords: LatLon): void;\n /** Programmatically set zoom */\n setZoom(zoom: number): void;\n}\n\nconst LUXEMBOURG_CITY: LatLon = { lat: 49.6116, lon: 6.1319 };\nconst DEFAULT_BG_LAYER = 'basemap_2015_global';\n\n/**\n * Renders a Geoportail Luxembourg map inside a React component.\n *\n * Expose a ref (`GeoportailMapHandle`) to access the underlying lux.Map instance\n * or imperatively control the view.\n */\nexport const GeoportailMap = forwardRef<GeoportailMapHandle, GeoportailMapProps>(\n function GeoportailMap(\n {\n center = LUXEMBOURG_CITY,\n zoom = 12,\n bgLayer = DEFAULT_BG_LAYER,\n markerMode = 'none',\n markerPosition,\n onMarkerPlace,\n className,\n style,\n layers,\n },\n ref\n ) {\n const generatedId = useId();\n // useId produces \":r0:\" style strings — strip colons for valid DOM id\n const mapId = `gp-map-${generatedId.replace(/:/g, '')}`;\n\n const luxApi = useLuxApi();\n const mapRef = useRef<LuxMapInstance | null>(null);\n const markerLayerRef = useRef<unknown>(null);\n const clickListenerRef = useRef<((...args: unknown[]) => void) | null>(null);\n\n // Keep stable refs to callbacks so effects don't re-run on every render\n const onMarkerPlaceRef = useRef(onMarkerPlace);\n onMarkerPlaceRef.current = onMarkerPlace;\n\n // ------------------------------------------------------------------ map init\n useEffect(() => {\n if (luxApi.status !== 'ready') return;\n\n const lux = luxApi.lux;\n const { easting, northing } = latLonToLuref(center.lat, center.lon);\n\n const mapInstance = new lux.Map({\n target: mapId,\n bgLayer,\n zoom,\n position: [easting, northing],\n ...(layers && layers.length > 0\n ? { layers, layerOpacities: layers.map(() => 1) }\n : {}),\n });\n\n mapRef.current = mapInstance;\n\n return () => {\n // lux.Map does not expose a destroy(); we clear our references\n mapRef.current = null;\n markerLayerRef.current = null;\n clickListenerRef.current = null;\n };\n // Only re-run when the API becomes ready or the map target changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [luxApi.status, mapId]);\n\n // ------------------------------------------------------------------ marker\n useEffect(() => {\n const map = mapRef.current;\n if (!map || luxApi.status !== 'ready') return;\n\n // Remove previous click listener\n if (clickListenerRef.current) {\n map.un('singleclick', clickListenerRef.current);\n clickListenerRef.current = null;\n }\n\n if (markerMode === 'none') {\n clearMarker(map, markerLayerRef);\n return;\n }\n\n const initialPos = markerPosition ?? (markerMode === 'fixed' ? center : undefined);\n if (initialPos) {\n placeMarker(map, initialPos, markerLayerRef);\n }\n\n if (markerMode === 'click') {\n const handler = (...args: unknown[]) => {\n // OpenLayers MapBrowserEvent — coordinate is in map projection (EPSG:2169)\n const evt = args[0] as { coordinate?: [number, number] };\n if (!evt.coordinate) return;\n\n const [e, n] = evt.coordinate;\n const latLon = lurefToLatLon(e, n);\n placeMarker(map, latLon, markerLayerRef);\n onMarkerPlaceRef.current?.(latLon);\n };\n\n clickListenerRef.current = handler;\n map.on('singleclick', handler);\n }\n }, [\n luxApi.status,\n markerMode,\n markerPosition?.lat,\n markerPosition?.lon,\n center,\n ]);\n\n // ------------------------------------------------------------------ imperative handle\n useImperativeHandle(ref, () => ({\n getLuxMap: () => mapRef.current,\n setCenter(coords: LatLon) {\n const map = mapRef.current;\n if (!map) return;\n const { easting, northing } = latLonToLuref(coords.lat, coords.lon);\n map.getView().setCenter([easting, northing]);\n },\n setZoom(z: number) {\n mapRef.current?.getView().setZoom(z);\n },\n }));\n\n // ------------------------------------------------------------------ render\n if (luxApi.status === 'error') {\n return (\n <div\n className={className}\n style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', background: '#f5f5f5', ...style }}\n >\n <span style={{ color: '#c00' }}>\n Failed to load Geoportail API: {luxApi.error.message}\n </span>\n </div>\n );\n }\n\n return (\n <div style={{ position: 'relative', ...style }} className={className}>\n {luxApi.status === 'loading' && (\n <div\n style={{\n position: 'absolute',\n inset: 0,\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n background: 'rgba(255,255,255,0.7)',\n zIndex: 10,\n }}\n >\n <span>Loading map…</span>\n </div>\n )}\n <div\n id={mapId}\n style={{ width: '100%', height: '100%' }}\n />\n </div>\n );\n }\n);\n\n// ------------------------------------------------------------------ helpers\n\n/**\n * Place/move an SVG pin marker on the map.\n * lux.Map is built on OpenLayers 3 — we use ol.Overlay for the marker.\n */\nfunction placeMarker(\n map: LuxMapInstance,\n position: LatLon,\n layerRef: React.MutableRefObject<unknown>\n): void {\n // Prefer ol (OpenLayers global) if available\n const ol = (window as unknown as { ol?: OlLike }).ol;\n if (!ol) return;\n\n const { easting, northing } = latLonToLuref(position.lat, position.lon);\n\n // Reuse existing overlay or create a new one\n if (layerRef.current) {\n const overlay = layerRef.current as OlOverlay;\n overlay.setPosition([easting, northing]);\n return;\n }\n\n const el = document.createElement('div');\n el.innerHTML = PIN_SVG;\n el.style.cssText =\n 'cursor:pointer;transform:translate(-50%,-100%);line-height:0;';\n\n const overlay = new ol.Overlay({\n element: el,\n positioning: 'bottom-center',\n stopEvent: false,\n });\n\n overlay.setPosition([easting, northing]);\n (map as unknown as { addOverlay(o: OlOverlay): void }).addOverlay(overlay);\n layerRef.current = overlay;\n}\n\nfunction clearMarker(\n _map: LuxMapInstance,\n layerRef: React.MutableRefObject<unknown>\n): void {\n if (!layerRef.current) return;\n const ol = (window as unknown as { ol?: OlLike }).ol;\n if (!ol) return;\n // Overlay doesn't have a built-in remove on the overlay itself;\n // set position to undefined to hide it\n (layerRef.current as OlOverlay).setPosition(undefined);\n layerRef.current = null;\n}\n\n// Minimal pin SVG (red teardrop, 30×40)\nconst PIN_SVG = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"30\" height=\"40\" viewBox=\"0 0 30 40\">\n <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\"\n fill=\"#e53935\" stroke=\"#b71c1c\" stroke-width=\"1.5\"/>\n <circle cx=\"15\" cy=\"14\" r=\"5\" fill=\"white\"/>\n</svg>`;\n\n// Minimal OL type stubs used only within this file\ninterface OlOverlay {\n setPosition(pos: [number, number] | undefined): void;\n}\n\ninterface OlLike {\n Overlay: new (opts: { element: HTMLElement; positioning: string; stopEvent: boolean }) => OlOverlay;\n}\n","import { useState, useCallback, useRef } from 'react';\nimport { latLonToLuref } from '../utils/coordinates.ts';\nimport type { LatLon, Address } from '../types/index.ts';\n\nconst REVERSE_GEOCODE_URL = 'https://api.geoportail.lu/geocoder/reverseGeocode';\n\nexport type ReverseGeocodeState =\n | { status: 'idle'; address: null; error: null }\n | { status: 'loading'; address: null; error: null }\n | { status: 'success'; address: Address; error: null }\n | { status: 'error'; address: null; error: Error };\n\n/**\n * Hook for reverse geocoding: convert a WGS84 lat/lon to a Luxembourg address.\n *\n * Uses the Geoportail REST reverse geocode endpoint — no API key required.\n *\n * @example\n * const { state, lookup } = useReverseGeocode();\n * // ...\n * lookup({ lat: 49.6116, lon: 6.1319 });\n * if (state.status === 'success') console.log(state.address.label);\n */\nexport function useReverseGeocode() {\n const [state, setState] = useState<ReverseGeocodeState>({\n status: 'idle',\n address: null,\n error: null,\n });\n\n const abortRef = useRef<AbortController | null>(null);\n\n const lookup = useCallback(async (position: LatLon) => {\n // Cancel any in-flight request\n abortRef.current?.abort();\n const controller = new AbortController();\n abortRef.current = controller;\n\n setState({ status: 'loading', address: null, error: null });\n\n try {\n const { easting, northing } = latLonToLuref(position.lat, position.lon);\n\n const url = new URL(REVERSE_GEOCODE_URL);\n url.searchParams.set('easting', String(easting));\n url.searchParams.set('northing', String(northing));\n\n const res = await fetch(url.toString(), { signal: controller.signal });\n\n if (!res.ok) {\n throw new Error(`Reverse geocode request failed: ${res.status} ${res.statusText}`);\n }\n\n const data = (await res.json()) as {\n results?: Array<{\n easting: number;\n northing: number;\n name?: string;\n distance?: number;\n }>;\n };\n\n const first = data.results?.[0];\n if (!first) {\n throw new Error('No results returned for this position');\n }\n\n setState({\n status: 'success',\n address: {\n label: first.name ?? '',\n distance: first.distance ?? 0,\n easting: first.easting,\n northing: first.northing,\n },\n error: null,\n });\n } catch (err: unknown) {\n if (err instanceof DOMException && err.name === 'AbortError') return;\n setState({\n status: 'error',\n address: null,\n error: err instanceof Error ? err : new Error(String(err)),\n });\n }\n }, []);\n\n const reset = useCallback(() => {\n abortRef.current?.abort();\n setState({ status: 'idle', address: null, error: null });\n }, []);\n\n return { state, lookup, reset };\n}\n","import { useState, useCallback, useRef } from 'react';\nimport { lurefToLatLon } from '../utils/coordinates.ts';\nimport type { GeocodeQuery, LatLon } from '../types/index.ts';\n\nconst GEOCODE_URL = 'https://apiv3.geoportail.lu/geocode/search';\n\nexport interface GeocodeResultItem {\n latLon: LatLon;\n easting: number;\n northing: number;\n accuracy: number;\n street?: string;\n num?: string;\n zip?: string;\n locality?: string;\n}\n\nexport type GeocodeState =\n | { status: 'idle'; results: null; error: null }\n | { status: 'loading'; results: null; error: null }\n | { status: 'success'; results: GeocodeResultItem[]; error: null }\n | { status: 'error'; results: null; error: Error };\n\n/**\n * Hook for forward geocoding: search for a Luxembourg address and get coordinates.\n *\n * @example\n * const { state, search } = useGeocode();\n * search({ queryString: '1 rue du Fort Thüngen, Luxembourg' });\n * if (state.status === 'success') {\n * const { lat, lon } = state.results[0].latLon;\n * }\n */\nexport function useGeocode() {\n const [state, setState] = useState<GeocodeState>({\n status: 'idle',\n results: null,\n error: null,\n });\n\n const abortRef = useRef<AbortController | null>(null);\n\n const search = useCallback(async (query: GeocodeQuery) => {\n abortRef.current?.abort();\n const controller = new AbortController();\n abortRef.current = controller;\n\n setState({ status: 'loading', results: null, error: null });\n\n try {\n const url = new URL(GEOCODE_URL);\n\n if (query.queryString) {\n url.searchParams.set('queryString', query.queryString);\n } else {\n if (query.num) url.searchParams.set('num', query.num);\n if (query.street) url.searchParams.set('street', query.street);\n if (query.zip) url.searchParams.set('zip', query.zip);\n if (query.locality) url.searchParams.set('locality', query.locality);\n }\n\n const res = await fetch(url.toString(), { signal: controller.signal });\n\n if (!res.ok) {\n throw new Error(`Geocode request failed: ${res.status} ${res.statusText}`);\n }\n\n const data = (await res.json()) as {\n results?: Array<{\n easting: number;\n northing: number;\n accuracy?: number;\n AddressDetails?: {\n street?: string;\n number?: string;\n zip?: string;\n locality?: string;\n };\n }>;\n };\n\n const results: GeocodeResultItem[] = (data.results ?? []).map((r) => ({\n latLon: lurefToLatLon(r.easting, r.northing),\n easting: r.easting,\n northing: r.northing,\n accuracy: r.accuracy ?? 0,\n street: r.AddressDetails?.street,\n num: r.AddressDetails?.number,\n zip: r.AddressDetails?.zip,\n locality: r.AddressDetails?.locality,\n }));\n\n setState({ status: 'success', results, error: null });\n } catch (err: unknown) {\n if (err instanceof DOMException && err.name === 'AbortError') return;\n setState({\n status: 'error',\n results: null,\n error: err instanceof Error ? err : new Error(String(err)),\n });\n }\n }, []);\n\n const reset = useCallback(() => {\n abortRef.current?.abort();\n setState({ status: 'idle', results: null, error: null });\n }, []);\n\n return { state, search, reset };\n}\n"],"names":["LUX_SCRIPT_URL","LUX_SCRIPT_ID","loadPromise","loadLuxApi","resolve","reject","pollForLux","script","attempts","check","useLuxApi","state","setState","useState","useEffect","cancelled","err","FE","FN","LON0","LAT0","SCALE","A","F","B","E2","DX","DY","DZ","degToRad","d","radToDeg","r","wgs84ToEd50","lat","lon","latR","lonR","sinLat","cosLat","sinLon","cosLon","aWgs","fWgs","bWgs","e2Wgs","da","df","N","dLat","dLon","ed50ToWgs84","M","tmForward","lon0R","lat0R","tanLat","T","C","dl","XX","meridianArc","M0","easting","northing","tmInverse","x","y","mu","e1","phi1","sinPhi1","cosPhi1","tanPhi1","N1","T1","C1","R1","D","e2","e4","e6","latLonToLuref","ed50","lurefToLatLon","LUXEMBOURG_CITY","DEFAULT_BG_LAYER","GeoportailMap","forwardRef","center","zoom","bgLayer","markerMode","markerPosition","onMarkerPlace","className","style","layers","ref","mapId","useId","luxApi","mapRef","useRef","markerLayerRef","clickListenerRef","onMarkerPlaceRef","lux","mapInstance","map","clearMarker","initialPos","placeMarker","handler","args","evt","e","n","latLon","_a","useImperativeHandle","coords","z","jsx","jsxs","position","layerRef","ol","overlay","el","PIN_SVG","_map","REVERSE_GEOCODE_URL","useReverseGeocode","abortRef","lookup","useCallback","controller","url","res","first","_b","reset","GEOCODE_URL","useGeocode","search","query","results","_c","_d"],"mappings":";;AAKA,MAAMA,IAAiB,wCACjBC,IAAgB;AAEtB,IAAIC,IAAoC;AAMjC,SAASC,KAA4B;AAC1C,SAAID,MAEJA,IAAc,IAAI,QAAc,CAACE,GAASC,MAAW;AAEnD,QAAI,OAAO,SAAW,OAAe,OAAO,KAAK;AAC/C,MAAAD,EAAA;AACA;AAAA,IACF;AAEA,QAAI,OAAO,WAAa,KAAa;AACnC,MAAAC,EAAO,IAAI,MAAM,8CAA8C,CAAC;AAChE;AAAA,IACF;AAGA,QAAI,SAAS,eAAeJ,CAAa,GAAG;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AA,QACP,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,OAAOI,aAAe,QAAQA,IAAM,IAAI,MAAM,OAAOA,CAAG,CAAC;AAAA,MAAA,CAC1D;AAAA,IACH;AAAA,EACF,GAAG,CAAA,CAAE,GAEC8H,IAAQN,EAAY,MAAM;;AAC9B,KAAAjB,IAAAe,EAAS,YAAT,QAAAf,EAAkB,SAClB3G,EAAS,EAAE,QAAQ,QAAQ,SAAS,MAAM,OAAO,MAAM;AAAA,EACzD,GAAG,CAAA,CAAE;AAEL,SAAO,EAAE,OAAAD,GAAO,QAAAsI,GAAQ,OAAAH,EAAA;AAC1B;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
(function(x,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],b):(x=typeof globalThis<"u"?globalThis:x||self,b(x.ReactGeoportail={},x.jsxRuntime,x.React))})(this,function(x,b,L){"use strict";const F="//apiv3.geoportail.lu/apiv3loader.js",z="geoportail-apiv3-loader";let S=null;function N(){return S||(S=new Promise((c,t)=>{if(typeof window<"u"&&window.lux){c();return}if(typeof document>"u"){t(new Error("loadLuxApi must run in a browser environment"));return}if(document.getElementById(z)){W(c,t);return}const n=document.createElement("script");n.id=z,n.src=F,n.async=!0,n.onload=()=>W(c,t),n.onerror=()=>{S=null,t(new Error(`Failed to load Geoportail API from ${F}`))},document.head.appendChild(n)}),S)}function W(c,t){let l=0;const a=()=>{if(window.lux){c();return}if(l++>=100){S=null,t(new Error("Timed out waiting for window.lux to be defined"));return}setTimeout(a,50)};a()}function X(){const[c,t]=L.useState({status:"loading",lux:null,error:null});return L.useEffect(()=>{let n=!1;return N().then(()=>{n||t({status:"ready",lux:window.lux,error:null})}).catch(l=>{n||t({status:"error",lux:null,error:l instanceof Error?l:new Error(String(l))})}),()=>{n=!0}},[]),c}const $=8e4,B=1e5,k=6.16666666666667,q=49.8333333333333,G=1,E=6378388,O=1/297,P=E*(1-O),m=1-P*P/(E*E),D=-87,_=-98,V=-121;function R(c){return c*Math.PI/180}function T(c){return c*180/Math.PI}function K(c,t){const n=R(c),l=R(t),a=Math.sin(n),e=Math.cos(n),p=Math.sin(l),g=Math.cos(l),s=6378137,r=1/298.257223563,h=s*(1-r),f=1-h*h/(s*s),u=E-s,o=O-r,d=s/Math.sqrt(1-f*a*a),w=1/(s*(1-f)/Math.pow(1-f*a*a,1.5))*(d*(f/(1-f))*a*e*(u/s)+(d/s+1)*a*e*o*(s/h)-(D*a*g+_*a*p-V*e)),y=1/(d*e)*(-D*p+_*g);return{lat:c+T(w),lon:t+T(y)}}function Q(c,t){const n=R(c),l=R(t),a=Math.sin(n),e=Math.cos(n),p=Math.sin(l),g=Math.cos(l),s=E/Math.sqrt(1-m*a*a),r=E*(1-m)/Math.pow(1-m*a*a,1.5),h=6378137-E,u=1/298.257223563-O,o=1/r*(s*(m/(1-m))*a*e*(h/E)+(s/E+1)*a*e*u*(E/P)+(D*a*g+_*a*p-V*e)),d=1/(s*e)*(D*p-_*g);return{lat:c+T(o),lon:t+T(d)}}function tt(c,t){const n=R(c),l=R(t),a=R(k),e=R(q),p=Math.sin(n),g=Math.cos(n),s=Math.tan(n),r=E/Math.sqrt(1-m*p*p),h=s*s,f=m/(1-m)*g*g,u=l-a,o=g*u,d=U(n),M=U(e),w=$+G*r*(o+o*o*o*(1-h+f)/6+o*o*o*o*o*(5-18*h+h*h+72*f)/120),y=B+G*(d-M+r*s*(o*o/2+o*o*o*o*(5-h+9*f+4*f*f)/24+o*o*o*o*o*o*(61-58*h+h*h+600*f)/720));return{easting:w,northing:y}}function nt(c,t){const n=c-$,l=t-B,a=R(q),e=R(k),s=(U(a)+l/G)/(E*(1-m/4-3*m*m/64)),r=(1-Math.sqrt(1-m))/(1+Math.sqrt(1-m)),h=s+(3*r/2-27*r*r*r/32)*Math.sin(2*s)+(21*r*r/16-55*r*r*r*r/32)*Math.sin(4*s)+151*r*r*r/96*Math.sin(6*s),f=Math.sin(h),u=Math.cos(h),o=Math.tan(h),d=E/Math.sqrt(1-m*f*f),M=o*o,w=m/(1-m)*u*u,y=E*(1-m)/Math.pow(1-m*f*f,1.5),i=n/(d*G),v=h-d*o/y*(i*i/2-i*i*i*i*(5+3*M+10*w-4*w*w)/24+i*i*i*i*i*i*(61+90*M+298*w+45*M*M)/720),A=e+(i-i*i*i*(1+2*M+w)/6+i*i*i*i*i*(5-2*w+28*M-3*w*w)/120)/u;return{lat:T(v),lon:T(A)}}function U(c){const t=m,n=t*t,l=n*t;return E*((1-t/4-3*n/64-5*l/256)*c-(3*t/8+3*n/32+45*l/1024)*Math.sin(2*c)+(15*n/256+45*l/1024)*Math.sin(4*c)-35*l/3072*Math.sin(6*c))}function C(c,t){const n=K(c,t);return tt(n.lat,n.lon)}function j(c,t){const n=nt(c,t);return Q(n.lat,n.lon)}const et={lat:49.6116,lon:6.1319},st="basemap_2015_global",ot=L.forwardRef(function({center:t=et,zoom:n=12,bgLayer:l=st,markerMode:a="none",markerPosition:e,onMarkerPlace:p,className:g,style:s,layers:r},h){const u=`gp-map-${L.useId().replace(/:/g,"")}`,o=X(),d=L.useRef(null),M=L.useRef(null),w=L.useRef(null),y=L.useRef(p);return y.current=p,L.useEffect(()=>{if(o.status!=="ready")return;const i=o.lux,{easting:v,northing:A}=C(t.lat,t.lon),I=new i.Map({target:u,bgLayer:l,zoom:n,position:[v,A],...r&&r.length>0?{layers:r,layerOpacities:r.map(()=>1)}:{}});return d.current=I,()=>{d.current=null,M.current=null,w.current=null}},[o.status,u]),L.useEffect(()=>{const i=d.current;if(!i||o.status!=="ready")return;if(w.current&&(i.un("singleclick",w.current),w.current=null),a==="none"){rt(i,M);return}const v=e??(a==="fixed"?t:void 0);if(v&&Y(i,v,M),a==="click"){const A=(...I)=>{var J;const Z=I[0];if(!Z.coordinate)return;const[dt,ft]=Z.coordinate,H=j(dt,ft);Y(i,H,M),(J=y.current)==null||J.call(y,H)};w.current=A,i.on("singleclick",A)}},[o.status,a,e==null?void 0:e.lat,e==null?void 0:e.lon,t]),L.useImperativeHandle(h,()=>({getLuxMap:()=>d.current,setCenter(i){const v=d.current;if(!v)return;const{easting:A,northing:I}=C(i.lat,i.lon);v.getView().setCenter([A,I])},setZoom(i){var v;(v=d.current)==null||v.getView().setZoom(i)}})),o.status==="error"?b.jsx("div",{className:g,style:{display:"flex",alignItems:"center",justifyContent:"center",background:"#f5f5f5",...s},children:b.jsxs("span",{style:{color:"#c00"},children:["Failed to load Geoportail API: ",o.error.message]})}):b.jsxs("div",{style:{position:"relative",...s},className:g,children:[o.status==="loading"&&b.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(255,255,255,0.7)",zIndex:10},children:b.jsx("span",{children:"Loading map…"})}),b.jsx("div",{id:u,style:{width:"100%",height:"100%"}})]})});function Y(c,t,n){const l=window.ol;if(!l)return;const{easting:a,northing:e}=C(t.lat,t.lon);if(n.current){n.current.setPosition([a,e]);return}const p=document.createElement("div");p.innerHTML=ct,p.style.cssText="cursor:pointer;transform:translate(-50%,-100%);line-height:0;";const g=new l.Overlay({element:p,positioning:"bottom-center",stopEvent:!1});g.setPosition([a,e]),c.addOverlay(g),n.current=g}function rt(c,t){!t.current||!window.ol||(t.current.setPosition(void 0),t.current=null)}const ct=`<svg xmlns="http://www.w3.org/2000/svg" width="30" height="40" viewBox="0 0 30 40">
|
|
2
|
+
<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"
|
|
3
|
+
fill="#e53935" stroke="#b71c1c" stroke-width="1.5"/>
|
|
4
|
+
<circle cx="15" cy="14" r="5" fill="white"/>
|
|
5
|
+
</svg>`,at="https://api.geoportail.lu/geocoder/reverseGeocode";function it(){const[c,t]=L.useState({status:"idle",address:null,error:null}),n=L.useRef(null),l=L.useCallback(async e=>{var g,s;(g=n.current)==null||g.abort();const p=new AbortController;n.current=p,t({status:"loading",address:null,error:null});try{const{easting:r,northing:h}=C(e.lat,e.lon),f=new URL(at);f.searchParams.set("easting",String(r)),f.searchParams.set("northing",String(h));const u=await fetch(f.toString(),{signal:p.signal});if(!u.ok)throw new Error(`Reverse geocode request failed: ${u.status} ${u.statusText}`);const d=(s=(await u.json()).results)==null?void 0:s[0];if(!d)throw new Error("No results returned for this position");t({status:"success",address:{label:d.name??"",distance:d.distance??0,easting:d.easting,northing:d.northing},error:null})}catch(r){if(r instanceof DOMException&&r.name==="AbortError")return;t({status:"error",address:null,error:r instanceof Error?r:new Error(String(r))})}},[]),a=L.useCallback(()=>{var e;(e=n.current)==null||e.abort(),t({status:"idle",address:null,error:null})},[]);return{state:c,lookup:l,reset:a}}const lt="https://apiv3.geoportail.lu/geocode/search";function ut(){const[c,t]=L.useState({status:"idle",results:null,error:null}),n=L.useRef(null),l=L.useCallback(async e=>{var g;(g=n.current)==null||g.abort();const p=new AbortController;n.current=p,t({status:"loading",results:null,error:null});try{const s=new URL(lt);e.queryString?s.searchParams.set("queryString",e.queryString):(e.num&&s.searchParams.set("num",e.num),e.street&&s.searchParams.set("street",e.street),e.zip&&s.searchParams.set("zip",e.zip),e.locality&&s.searchParams.set("locality",e.locality));const r=await fetch(s.toString(),{signal:p.signal});if(!r.ok)throw new Error(`Geocode request failed: ${r.status} ${r.statusText}`);const f=((await r.json()).results??[]).map(u=>{var o,d,M,w;return{latLon:j(u.easting,u.northing),easting:u.easting,northing:u.northing,accuracy:u.accuracy??0,street:(o=u.AddressDetails)==null?void 0:o.street,num:(d=u.AddressDetails)==null?void 0:d.number,zip:(M=u.AddressDetails)==null?void 0:M.zip,locality:(w=u.AddressDetails)==null?void 0:w.locality}});t({status:"success",results:f,error:null})}catch(s){if(s instanceof DOMException&&s.name==="AbortError")return;t({status:"error",results:null,error:s instanceof Error?s:new Error(String(s))})}},[]),a=L.useCallback(()=>{var e;(e=n.current)==null||e.abort(),t({status:"idle",results:null,error:null})},[]);return{state:c,search:l,reset:a}}x.GeoportailMap=ot,x.latLonToLuref=C,x.loadLuxApi=N,x.lurefToLatLon=j,x.useGeocode=ut,x.useLuxApi=X,x.useReverseGeocode=it,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
|
|
6
|
+
//# sourceMappingURL=react-geoportail.umd.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-geoportail.umd.cjs","sources":["../src/utils/loader.ts","../src/hooks/useLuxApi.ts","../src/utils/coordinates.ts","../src/components/GeoportailMap.tsx","../src/hooks/useReverseGeocode.ts","../src/hooks/useGeocode.ts"],"sourcesContent":["/**\n * Dynamically injects the Geoportail v3 API script and resolves when\n * the global `lux` namespace is available.\n */\n\nconst LUX_SCRIPT_URL = '//apiv3.geoportail.lu/apiv3loader.js';\nconst LUX_SCRIPT_ID = 'geoportail-apiv3-loader';\n\nlet loadPromise: Promise<void> | null = null;\n\n/**\n * Loads the Geoportail apiv3loader.js script exactly once.\n * Safe to call multiple times — subsequent calls return the same promise.\n */\nexport function loadLuxApi(): Promise<void> {\n if (loadPromise) return loadPromise;\n\n loadPromise = new Promise<void>((resolve, reject) => {\n // Already loaded (e.g. added manually in HTML)\n if (typeof window !== 'undefined' && window.lux) {\n resolve();\n return;\n }\n\n if (typeof document === 'undefined') {\n reject(new Error('loadLuxApi must run in a browser environment'));\n return;\n }\n\n // Avoid duplicate script tags\n if (document.getElementById(LUX_SCRIPT_ID)) {\n pollForLux(resolve, reject);\n return;\n }\n\n const script = document.createElement('script');\n script.id = LUX_SCRIPT_ID;\n script.src = LUX_SCRIPT_URL;\n script.async = true;\n\n script.onload = () => pollForLux(resolve, reject);\n script.onerror = () => {\n loadPromise = null; // allow retry\n reject(new Error(`Failed to load Geoportail API from ${LUX_SCRIPT_URL}`));\n };\n\n document.head.appendChild(script);\n });\n\n return loadPromise;\n}\n\n/**\n * The lux API may initialise asynchronously after the script loads.\n * Poll until window.lux is defined (max ~5 s).\n */\nfunction pollForLux(resolve: () => void, reject: (err: Error) => void): void {\n const maxAttempts = 100;\n let attempts = 0;\n\n const check = () => {\n if (window.lux) {\n resolve();\n return;\n }\n if (attempts++ >= maxAttempts) {\n loadPromise = null;\n reject(new Error('Timed out waiting for window.lux to be defined'));\n return;\n }\n setTimeout(check, 50);\n };\n\n check();\n}\n","import { useState, useEffect } from 'react';\nimport { loadLuxApi } from '../utils/loader.ts';\nimport type { LuxNamespace } from '../types/lux.d.ts';\n\nexport type LuxApiState =\n | { status: 'loading'; lux: null; error: null }\n | { status: 'ready'; lux: LuxNamespace; error: null }\n | { status: 'error'; lux: null; error: Error };\n\n/**\n * Loads the Geoportail apiv3 script and returns the `lux` namespace once ready.\n * Deduplicates the script load — safe to call from multiple components.\n */\nexport function useLuxApi(): LuxApiState {\n const [state, setState] = useState<LuxApiState>({\n status: 'loading',\n lux: null,\n error: null,\n });\n\n useEffect(() => {\n let cancelled = false;\n\n loadLuxApi()\n .then(() => {\n if (!cancelled) {\n setState({ status: 'ready', lux: window.lux!, error: null });\n }\n })\n .catch((err: unknown) => {\n if (!cancelled) {\n setState({\n status: 'error',\n lux: null,\n error: err instanceof Error ? err : new Error(String(err)),\n });\n }\n });\n\n return () => {\n cancelled = true;\n };\n }, []);\n\n return state;\n}\n","/**\n * Coordinate conversion between EPSG:2169 (Luxembourg TM) and EPSG:4326 (WGS84).\n *\n * The Geoportail API operates internally in EPSG:2169 but also accepts\n * position arrays in EPSG:4326 via `lux.Map` constructor options.\n *\n * For precise server-side conversion the REST API itself is authoritative.\n * The formulas below use a 6-parameter Helmert + transverse Mercator approach\n * sufficient for Luxembourg's territory (~50 km radius).\n *\n * Reference: IGN-L / ACT official parameters for LUREF (EPSG:2169).\n */\n\n// LUREF / Luxembourg TM projection constants (EPSG:2169)\nconst FE = 80000; // False Easting (m)\nconst FN = 100000; // False Northing (m)\nconst LON0 = 6.16666666666667; // Central meridian (6°10') in degrees\nconst LAT0 = 49.8333333333333; // Latitude of origin (49°50') in degrees\nconst SCALE = 1.0; // Scale factor at central meridian\nconst A = 6378388.0; // Semi-major axis (Hayford / International 1924)\nconst F = 1 / 297.0; // Flattening\nconst B = A * (1 - F); // Semi-minor axis\n\nconst E2 = 1 - (B * B) / (A * A); // First eccentricity squared\n\n// Helmert 7-parameter shift: ETRS89 -> ED50 (approximate for Luxembourg)\n// These values transform WGS84 (≈ETRS89) to ED50 used by LUREF\nconst DX = -87.0;\nconst DY = -98.0;\nconst DZ = -121.0;\n\nfunction degToRad(d: number): number {\n return (d * Math.PI) / 180;\n}\n\nfunction radToDeg(r: number): number {\n return (r * 180) / Math.PI;\n}\n\n/**\n * Molodensky transformation: WGS84 -> ED50 (approximate, <1 m accuracy).\n */\nfunction wgs84ToEd50(\n lat: number,\n lon: number\n): { lat: number; lon: number } {\n const latR = degToRad(lat);\n const lonR = degToRad(lon);\n\n const sinLat = Math.sin(latR);\n const cosLat = Math.cos(latR);\n const sinLon = Math.sin(lonR);\n const cosLon = Math.cos(lonR);\n\n const aWgs = 6378137.0;\n const fWgs = 1 / 298.257223563;\n const bWgs = aWgs * (1 - fWgs);\n const e2Wgs = 1 - (bWgs * bWgs) / (aWgs * aWgs);\n\n const da = A - aWgs;\n const df = F - fWgs;\n\n const N = aWgs / Math.sqrt(1 - e2Wgs * sinLat * sinLat);\n const M =\n (aWgs * (1 - e2Wgs)) /\n Math.pow(1 - e2Wgs * sinLat * sinLat, 1.5);\n\n const dLat =\n (1 / M) *\n (N * (e2Wgs / (1 - e2Wgs)) * sinLat * cosLat * (da / aWgs) +\n (N / aWgs + 1) * sinLat * cosLat * df * (aWgs / bWgs) -\n (DX * sinLat * cosLon + DY * sinLat * sinLon - DZ * cosLat));\n\n const dLon =\n (1 / (N * cosLat)) * (-DX * sinLon + DY * cosLon);\n\n return {\n lat: lat + radToDeg(dLat),\n lon: lon + radToDeg(dLon),\n };\n}\n\n/**\n * ED50 -> WGS84 (inverse Molodensky, approximate).\n */\nfunction ed50ToWgs84(\n lat: number,\n lon: number\n): { lat: number; lon: number } {\n const latR = degToRad(lat);\n const lonR = degToRad(lon);\n\n const sinLat = Math.sin(latR);\n const cosLat = Math.cos(latR);\n const sinLon = Math.sin(lonR);\n const cosLon = Math.cos(lonR);\n\n const N = A / Math.sqrt(1 - E2 * sinLat * sinLat);\n const M = (A * (1 - E2)) / Math.pow(1 - E2 * sinLat * sinLat, 1.5);\n\n const da = 6378137.0 - A;\n const fWgs = 1 / 298.257223563;\n const df = fWgs - F;\n\n const dLat =\n (1 / M) *\n (N * (E2 / (1 - E2)) * sinLat * cosLat * (da / A) +\n (N / A + 1) * sinLat * cosLat * df * (A / B) +\n (DX * sinLat * cosLon + DY * sinLat * sinLon - DZ * cosLat));\n\n const dLon =\n (1 / (N * cosLat)) * (DX * sinLon - DY * cosLon);\n\n return {\n lat: lat + radToDeg(dLat),\n lon: lon + radToDeg(dLon),\n };\n}\n\n/**\n * Transverse Mercator forward projection (ED50 lat/lon -> LUREF easting/northing).\n */\nfunction tmForward(lat: number, lon: number): { easting: number; northing: number } {\n const latR = degToRad(lat);\n const lonR = degToRad(lon);\n const lon0R = degToRad(LON0);\n const lat0R = degToRad(LAT0);\n\n const sinLat = Math.sin(latR);\n const cosLat = Math.cos(latR);\n const tanLat = Math.tan(latR);\n\n const N = A / Math.sqrt(1 - E2 * sinLat * sinLat);\n const T = tanLat * tanLat;\n const C = (E2 / (1 - E2)) * cosLat * cosLat;\n const dl = lonR - lon0R;\n const XX = cosLat * dl;\n\n // Meridian arc from equator to lat\n const M = meridianArc(latR);\n const M0 = meridianArc(lat0R);\n\n const easting =\n FE +\n SCALE *\n N *\n (XX +\n (XX * XX * XX * (1 - T + C)) / 6 +\n (XX * XX * XX * XX * XX * (5 - 18 * T + T * T + 72 * C)) / 120);\n\n const northing =\n FN +\n SCALE *\n (M -\n M0 +\n N *\n tanLat *\n (XX * XX / 2 +\n (XX * XX * XX * XX * (5 - T + 9 * C + 4 * C * C)) / 24 +\n (XX * XX * XX * XX * XX * XX *\n (61 - 58 * T + T * T + 600 * C)) /\n 720));\n\n return { easting, northing };\n}\n\n/**\n * Transverse Mercator inverse projection (LUREF easting/northing -> ED50 lat/lon).\n */\nfunction tmInverse(easting: number, northing: number): { lat: number; lon: number } {\n const x = easting - FE;\n const y = northing - FN;\n const lat0R = degToRad(LAT0);\n const lon0R = degToRad(LON0);\n const M0 = meridianArc(lat0R);\n\n // Footpoint latitude\n const M1 = M0 + y / SCALE;\n const mu = M1 / (A * (1 - E2 / 4 - (3 * E2 * E2) / 64));\n\n const e1 = (1 - Math.sqrt(1 - E2)) / (1 + Math.sqrt(1 - E2));\n const phi1 =\n mu +\n ((3 * e1) / 2 - (27 * e1 * e1 * e1) / 32) * Math.sin(2 * mu) +\n ((21 * e1 * e1) / 16 - (55 * e1 * e1 * e1 * e1) / 32) *\n Math.sin(4 * mu) +\n ((151 * e1 * e1 * e1) / 96) * Math.sin(6 * mu);\n\n const sinPhi1 = Math.sin(phi1);\n const cosPhi1 = Math.cos(phi1);\n const tanPhi1 = Math.tan(phi1);\n\n const N1 = A / Math.sqrt(1 - E2 * sinPhi1 * sinPhi1);\n const T1 = tanPhi1 * tanPhi1;\n const C1 = (E2 / (1 - E2)) * cosPhi1 * cosPhi1;\n const R1 =\n (A * (1 - E2)) / Math.pow(1 - E2 * sinPhi1 * sinPhi1, 1.5);\n const D = x / (N1 * SCALE);\n\n const lat =\n phi1 -\n ((N1 * tanPhi1) / R1) *\n (D * D / 2 -\n (D * D * D * D * (5 + 3 * T1 + 10 * C1 - 4 * C1 * C1)) / 24 +\n (D * D * D * D * D * D *\n (61 + 90 * T1 + 298 * C1 + 45 * T1 * T1)) /\n 720);\n\n const lon =\n lon0R +\n (D -\n (D * D * D * (1 + 2 * T1 + C1)) / 6 +\n (D * D * D * D * D * (5 - 2 * C1 + 28 * T1 - 3 * C1 * C1)) / 120) /\n cosPhi1;\n\n return { lat: radToDeg(lat), lon: radToDeg(lon) };\n}\n\nfunction meridianArc(latR: number): number {\n const e2 = E2;\n const e4 = e2 * e2;\n const e6 = e4 * e2;\n return (\n A *\n ((1 - e2 / 4 - (3 * e4) / 64 - (5 * e6) / 256) * latR -\n ((3 * e2) / 8 + (3 * e4) / 32 + (45 * e6) / 1024) *\n Math.sin(2 * latR) +\n ((15 * e4) / 256 + (45 * e6) / 1024) * Math.sin(4 * latR) -\n ((35 * e6) / 3072) * Math.sin(6 * latR))\n );\n}\n\n/**\n * Convert WGS84 (lat/lon) to EPSG:2169 (easting/northing).\n */\nexport function latLonToLuref(\n lat: number,\n lon: number\n): { easting: number; northing: number } {\n const ed50 = wgs84ToEd50(lat, lon);\n return tmForward(ed50.lat, ed50.lon);\n}\n\n/**\n * Convert EPSG:2169 (easting/northing) to WGS84 (lat/lon).\n */\nexport function lurefToLatLon(\n easting: number,\n northing: number\n): { lat: number; lon: number } {\n const ed50 = tmInverse(easting, northing);\n return ed50ToWgs84(ed50.lat, ed50.lon);\n}\n","import React, {\n useEffect,\n useRef,\n useId,\n forwardRef,\n useImperativeHandle,\n} from 'react';\nimport { useLuxApi } from '../hooks/useLuxApi.ts';\nimport { lurefToLatLon, latLonToLuref } from '../utils/coordinates.ts';\nimport type { LatLon, MapClickHandler, MarkerMode } from '../types/index.ts';\nimport type { LuxMapInstance } from '../types/lux.d.ts';\n\nexport interface GeoportailMapProps {\n /**\n * Initial center of the map.\n * Defaults to Luxembourg City (lat: 49.6116, lon: 6.1319).\n */\n center?: LatLon;\n\n /** Initial zoom level (1–20). Default: 12 */\n zoom?: number;\n\n /**\n * Background layer identifier.\n * Default: 'basemap_2015_global'\n */\n bgLayer?: string;\n\n /**\n * Controls pin/marker behaviour:\n * - 'none' — no marker\n * - 'fixed' — show a marker at `markerPosition` (does not move on click)\n * - 'click' — user clicks map to place/move the pin; fires `onMarkerPlace`\n *\n * Default: 'none'\n */\n markerMode?: MarkerMode;\n\n /**\n * Position of the marker when `markerMode` is 'fixed' or to pre-set an\n * initial pin when `markerMode` is 'click'.\n */\n markerPosition?: LatLon;\n\n /**\n * Called whenever the user places a pin (markerMode === 'click').\n * Receives the WGS84 lat/lon of the clicked point.\n */\n onMarkerPlace?: MapClickHandler;\n\n /** CSS class applied to the map container div */\n className?: string;\n\n /** Inline styles for the map container div */\n style?: React.CSSProperties;\n\n /** Additional numeric layer IDs to add on top of the background */\n layers?: number[];\n}\n\nexport interface GeoportailMapHandle {\n /** Returns the underlying lux.Map instance (or null before ready) */\n getLuxMap(): LuxMapInstance | null;\n /** Programmatically move the map center */\n setCenter(coords: LatLon): void;\n /** Programmatically set zoom */\n setZoom(zoom: number): void;\n}\n\nconst LUXEMBOURG_CITY: LatLon = { lat: 49.6116, lon: 6.1319 };\nconst DEFAULT_BG_LAYER = 'basemap_2015_global';\n\n/**\n * Renders a Geoportail Luxembourg map inside a React component.\n *\n * Expose a ref (`GeoportailMapHandle`) to access the underlying lux.Map instance\n * or imperatively control the view.\n */\nexport const GeoportailMap = forwardRef<GeoportailMapHandle, GeoportailMapProps>(\n function GeoportailMap(\n {\n center = LUXEMBOURG_CITY,\n zoom = 12,\n bgLayer = DEFAULT_BG_LAYER,\n markerMode = 'none',\n markerPosition,\n onMarkerPlace,\n className,\n style,\n layers,\n },\n ref\n ) {\n const generatedId = useId();\n // useId produces \":r0:\" style strings — strip colons for valid DOM id\n const mapId = `gp-map-${generatedId.replace(/:/g, '')}`;\n\n const luxApi = useLuxApi();\n const mapRef = useRef<LuxMapInstance | null>(null);\n const markerLayerRef = useRef<unknown>(null);\n const clickListenerRef = useRef<((...args: unknown[]) => void) | null>(null);\n\n // Keep stable refs to callbacks so effects don't re-run on every render\n const onMarkerPlaceRef = useRef(onMarkerPlace);\n onMarkerPlaceRef.current = onMarkerPlace;\n\n // ------------------------------------------------------------------ map init\n useEffect(() => {\n if (luxApi.status !== 'ready') return;\n\n const lux = luxApi.lux;\n const { easting, northing } = latLonToLuref(center.lat, center.lon);\n\n const mapInstance = new lux.Map({\n target: mapId,\n bgLayer,\n zoom,\n position: [easting, northing],\n ...(layers && layers.length > 0\n ? { layers, layerOpacities: layers.map(() => 1) }\n : {}),\n });\n\n mapRef.current = mapInstance;\n\n return () => {\n // lux.Map does not expose a destroy(); we clear our references\n mapRef.current = null;\n markerLayerRef.current = null;\n clickListenerRef.current = null;\n };\n // Only re-run when the API becomes ready or the map target changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [luxApi.status, mapId]);\n\n // ------------------------------------------------------------------ marker\n useEffect(() => {\n const map = mapRef.current;\n if (!map || luxApi.status !== 'ready') return;\n\n // Remove previous click listener\n if (clickListenerRef.current) {\n map.un('singleclick', clickListenerRef.current);\n clickListenerRef.current = null;\n }\n\n if (markerMode === 'none') {\n clearMarker(map, markerLayerRef);\n return;\n }\n\n const initialPos = markerPosition ?? (markerMode === 'fixed' ? center : undefined);\n if (initialPos) {\n placeMarker(map, initialPos, markerLayerRef);\n }\n\n if (markerMode === 'click') {\n const handler = (...args: unknown[]) => {\n // OpenLayers MapBrowserEvent — coordinate is in map projection (EPSG:2169)\n const evt = args[0] as { coordinate?: [number, number] };\n if (!evt.coordinate) return;\n\n const [e, n] = evt.coordinate;\n const latLon = lurefToLatLon(e, n);\n placeMarker(map, latLon, markerLayerRef);\n onMarkerPlaceRef.current?.(latLon);\n };\n\n clickListenerRef.current = handler;\n map.on('singleclick', handler);\n }\n }, [\n luxApi.status,\n markerMode,\n markerPosition?.lat,\n markerPosition?.lon,\n center,\n ]);\n\n // ------------------------------------------------------------------ imperative handle\n useImperativeHandle(ref, () => ({\n getLuxMap: () => mapRef.current,\n setCenter(coords: LatLon) {\n const map = mapRef.current;\n if (!map) return;\n const { easting, northing } = latLonToLuref(coords.lat, coords.lon);\n map.getView().setCenter([easting, northing]);\n },\n setZoom(z: number) {\n mapRef.current?.getView().setZoom(z);\n },\n }));\n\n // ------------------------------------------------------------------ render\n if (luxApi.status === 'error') {\n return (\n <div\n className={className}\n style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', background: '#f5f5f5', ...style }}\n >\n <span style={{ color: '#c00' }}>\n Failed to load Geoportail API: {luxApi.error.message}\n </span>\n </div>\n );\n }\n\n return (\n <div style={{ position: 'relative', ...style }} className={className}>\n {luxApi.status === 'loading' && (\n <div\n style={{\n position: 'absolute',\n inset: 0,\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n background: 'rgba(255,255,255,0.7)',\n zIndex: 10,\n }}\n >\n <span>Loading map…</span>\n </div>\n )}\n <div\n id={mapId}\n style={{ width: '100%', height: '100%' }}\n />\n </div>\n );\n }\n);\n\n// ------------------------------------------------------------------ helpers\n\n/**\n * Place/move an SVG pin marker on the map.\n * lux.Map is built on OpenLayers 3 — we use ol.Overlay for the marker.\n */\nfunction placeMarker(\n map: LuxMapInstance,\n position: LatLon,\n layerRef: React.MutableRefObject<unknown>\n): void {\n // Prefer ol (OpenLayers global) if available\n const ol = (window as unknown as { ol?: OlLike }).ol;\n if (!ol) return;\n\n const { easting, northing } = latLonToLuref(position.lat, position.lon);\n\n // Reuse existing overlay or create a new one\n if (layerRef.current) {\n const overlay = layerRef.current as OlOverlay;\n overlay.setPosition([easting, northing]);\n return;\n }\n\n const el = document.createElement('div');\n el.innerHTML = PIN_SVG;\n el.style.cssText =\n 'cursor:pointer;transform:translate(-50%,-100%);line-height:0;';\n\n const overlay = new ol.Overlay({\n element: el,\n positioning: 'bottom-center',\n stopEvent: false,\n });\n\n overlay.setPosition([easting, northing]);\n (map as unknown as { addOverlay(o: OlOverlay): void }).addOverlay(overlay);\n layerRef.current = overlay;\n}\n\nfunction clearMarker(\n _map: LuxMapInstance,\n layerRef: React.MutableRefObject<unknown>\n): void {\n if (!layerRef.current) return;\n const ol = (window as unknown as { ol?: OlLike }).ol;\n if (!ol) return;\n // Overlay doesn't have a built-in remove on the overlay itself;\n // set position to undefined to hide it\n (layerRef.current as OlOverlay).setPosition(undefined);\n layerRef.current = null;\n}\n\n// Minimal pin SVG (red teardrop, 30×40)\nconst PIN_SVG = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"30\" height=\"40\" viewBox=\"0 0 30 40\">\n <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\"\n fill=\"#e53935\" stroke=\"#b71c1c\" stroke-width=\"1.5\"/>\n <circle cx=\"15\" cy=\"14\" r=\"5\" fill=\"white\"/>\n</svg>`;\n\n// Minimal OL type stubs used only within this file\ninterface OlOverlay {\n setPosition(pos: [number, number] | undefined): void;\n}\n\ninterface OlLike {\n Overlay: new (opts: { element: HTMLElement; positioning: string; stopEvent: boolean }) => OlOverlay;\n}\n","import { useState, useCallback, useRef } from 'react';\nimport { latLonToLuref } from '../utils/coordinates.ts';\nimport type { LatLon, Address } from '../types/index.ts';\n\nconst REVERSE_GEOCODE_URL = 'https://api.geoportail.lu/geocoder/reverseGeocode';\n\nexport type ReverseGeocodeState =\n | { status: 'idle'; address: null; error: null }\n | { status: 'loading'; address: null; error: null }\n | { status: 'success'; address: Address; error: null }\n | { status: 'error'; address: null; error: Error };\n\n/**\n * Hook for reverse geocoding: convert a WGS84 lat/lon to a Luxembourg address.\n *\n * Uses the Geoportail REST reverse geocode endpoint — no API key required.\n *\n * @example\n * const { state, lookup } = useReverseGeocode();\n * // ...\n * lookup({ lat: 49.6116, lon: 6.1319 });\n * if (state.status === 'success') console.log(state.address.label);\n */\nexport function useReverseGeocode() {\n const [state, setState] = useState<ReverseGeocodeState>({\n status: 'idle',\n address: null,\n error: null,\n });\n\n const abortRef = useRef<AbortController | null>(null);\n\n const lookup = useCallback(async (position: LatLon) => {\n // Cancel any in-flight request\n abortRef.current?.abort();\n const controller = new AbortController();\n abortRef.current = controller;\n\n setState({ status: 'loading', address: null, error: null });\n\n try {\n const { easting, northing } = latLonToLuref(position.lat, position.lon);\n\n const url = new URL(REVERSE_GEOCODE_URL);\n url.searchParams.set('easting', String(easting));\n url.searchParams.set('northing', String(northing));\n\n const res = await fetch(url.toString(), { signal: controller.signal });\n\n if (!res.ok) {\n throw new Error(`Reverse geocode request failed: ${res.status} ${res.statusText}`);\n }\n\n const data = (await res.json()) as {\n results?: Array<{\n easting: number;\n northing: number;\n name?: string;\n distance?: number;\n }>;\n };\n\n const first = data.results?.[0];\n if (!first) {\n throw new Error('No results returned for this position');\n }\n\n setState({\n status: 'success',\n address: {\n label: first.name ?? '',\n distance: first.distance ?? 0,\n easting: first.easting,\n northing: first.northing,\n },\n error: null,\n });\n } catch (err: unknown) {\n if (err instanceof DOMException && err.name === 'AbortError') return;\n setState({\n status: 'error',\n address: null,\n error: err instanceof Error ? err : new Error(String(err)),\n });\n }\n }, []);\n\n const reset = useCallback(() => {\n abortRef.current?.abort();\n setState({ status: 'idle', address: null, error: null });\n }, []);\n\n return { state, lookup, reset };\n}\n","import { useState, useCallback, useRef } from 'react';\nimport { lurefToLatLon } from '../utils/coordinates.ts';\nimport type { GeocodeQuery, LatLon } from '../types/index.ts';\n\nconst GEOCODE_URL = 'https://apiv3.geoportail.lu/geocode/search';\n\nexport interface GeocodeResultItem {\n latLon: LatLon;\n easting: number;\n northing: number;\n accuracy: number;\n street?: string;\n num?: string;\n zip?: string;\n locality?: string;\n}\n\nexport type GeocodeState =\n | { status: 'idle'; results: null; error: null }\n | { status: 'loading'; results: null; error: null }\n | { status: 'success'; results: GeocodeResultItem[]; error: null }\n | { status: 'error'; results: null; error: Error };\n\n/**\n * Hook for forward geocoding: search for a Luxembourg address and get coordinates.\n *\n * @example\n * const { state, search } = useGeocode();\n * search({ queryString: '1 rue du Fort Thüngen, Luxembourg' });\n * if (state.status === 'success') {\n * const { lat, lon } = state.results[0].latLon;\n * }\n */\nexport function useGeocode() {\n const [state, setState] = useState<GeocodeState>({\n status: 'idle',\n results: null,\n error: null,\n });\n\n const abortRef = useRef<AbortController | null>(null);\n\n const search = useCallback(async (query: GeocodeQuery) => {\n abortRef.current?.abort();\n const controller = new AbortController();\n abortRef.current = controller;\n\n setState({ status: 'loading', results: null, error: null });\n\n try {\n const url = new URL(GEOCODE_URL);\n\n if (query.queryString) {\n url.searchParams.set('queryString', query.queryString);\n } else {\n if (query.num) url.searchParams.set('num', query.num);\n if (query.street) url.searchParams.set('street', query.street);\n if (query.zip) url.searchParams.set('zip', query.zip);\n if (query.locality) url.searchParams.set('locality', query.locality);\n }\n\n const res = await fetch(url.toString(), { signal: controller.signal });\n\n if (!res.ok) {\n throw new Error(`Geocode request failed: ${res.status} ${res.statusText}`);\n }\n\n const data = (await res.json()) as {\n results?: Array<{\n easting: number;\n northing: number;\n accuracy?: number;\n AddressDetails?: {\n street?: string;\n number?: string;\n zip?: string;\n locality?: string;\n };\n }>;\n };\n\n const results: GeocodeResultItem[] = (data.results ?? []).map((r) => ({\n latLon: lurefToLatLon(r.easting, r.northing),\n easting: r.easting,\n northing: r.northing,\n accuracy: r.accuracy ?? 0,\n street: r.AddressDetails?.street,\n num: r.AddressDetails?.number,\n zip: r.AddressDetails?.zip,\n locality: r.AddressDetails?.locality,\n }));\n\n setState({ status: 'success', results, error: null });\n } catch (err: unknown) {\n if (err instanceof DOMException && err.name === 'AbortError') return;\n setState({\n status: 'error',\n results: null,\n error: err instanceof Error ? err : new Error(String(err)),\n });\n }\n }, []);\n\n const reset = useCallback(() => {\n abortRef.current?.abort();\n setState({ status: 'idle', results: null, error: null });\n }, []);\n\n return { state, search, reset };\n}\n"],"names":["LUX_SCRIPT_URL","LUX_SCRIPT_ID","loadPromise","loadLuxApi","resolve","reject","pollForLux","script","attempts","check","useLuxApi","state","setState","useState","useEffect","cancelled","err","FE","FN","LON0","LAT0","SCALE","A","F","B","E2","DX","DY","DZ","degToRad","d","radToDeg","r","wgs84ToEd50","lat","lon","latR","lonR","sinLat","cosLat","sinLon","cosLon","aWgs","fWgs","bWgs","e2Wgs","da","df","N","dLat","dLon","ed50ToWgs84","M","tmForward","lon0R","lat0R","tanLat","T","C","dl","XX","meridianArc","M0","easting","northing","tmInverse","x","y","mu","e1","phi1","sinPhi1","cosPhi1","tanPhi1","N1","T1","C1","R1","D","e2","e4","e6","latLonToLuref","ed50","lurefToLatLon","LUXEMBOURG_CITY","DEFAULT_BG_LAYER","GeoportailMap","forwardRef","center","zoom","bgLayer","markerMode","markerPosition","onMarkerPlace","className","style","layers","ref","mapId","useId","luxApi","mapRef","useRef","markerLayerRef","clickListenerRef","onMarkerPlaceRef","lux","mapInstance","map","clearMarker","initialPos","placeMarker","handler","args","evt","e","n","latLon","_a","useImperativeHandle","coords","z","jsx","jsxs","position","layerRef","ol","el","PIN_SVG","overlay","_map","REVERSE_GEOCODE_URL","useReverseGeocode","abortRef","lookup","useCallback","controller","url","res","first","_b","reset","GEOCODE_URL","useGeocode","search","query","results","_c","_d"],"mappings":"0UAKA,MAAMA,EAAiB,uCACjBC,EAAgB,0BAEtB,IAAIC,EAAoC,KAMjC,SAASC,GAA4B,CAC1C,OAAID,IAEJA,EAAc,IAAI,QAAc,CAACE,EAASC,IAAW,CAEnD,GAAI,OAAO,OAAW,KAAe,OAAO,IAAK,CAC/CD,EAAA,EACA,MACF,CAEA,GAAI,OAAO,SAAa,IAAa,CACnCC,EAAO,IAAI,MAAM,8CAA8C,CAAC,EAChE,MACF,CAGA,GAAI,SAAS,eAAeJ,CAAa,EAAG,CAC1CK,EAAWF,EAASC,CAAM,EAC1B,MACF,CAEA,MAAME,EAAS,SAAS,cAAc,QAAQ,EAC9CA,EAAO,GAAKN,EACZM,EAAO,IAAMP,EACbO,EAAO,MAAQ,GAEfA,EAAO,OAAS,IAAMD,EAAWF,EAASC,CAAM,EAChDE,EAAO,QAAU,IAAM,CACrBL,EAAc,KACdG,EAAO,IAAI,MAAM,sCAAsCL,CAAc,EAAE,CAAC,CAC1E,EAEA,SAAS,KAAK,YAAYO,CAAM,CAClC,CAAC,EAEML,EACT,CAMA,SAASI,EAAWF,EAAqBC,EAAoC,CAE3E,IAAIG,EAAW,EAEf,MAAMC,EAAQ,IAAM,CAClB,GAAI,OAAO,IAAK,CACdL,EAAA,EACA,MACF,CACA,GAAII,KAAc,IAAa,CAC7BN,EAAc,KACdG,EA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AAE,OAAQ,OAAQ,QAAS,KAAM,MAAO,KAAM,CACzD,EAAG,CAAA,CAAE,EAEL,MAAO,CAAE,MAAAD,EAAO,OAAAsI,EAAQ,MAAAH,CAAA,CAC1B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type { LuxCoordinate, LuxPosition, GeocodeResult, ReverseGeocodeResult, GeocodeResponse, ReverseGeocodeResponse, LuxMapOptions, LuxMapInstance, LuxGeocoderInstance, LuxNamespace, } from './lux.d.ts';
|
|
2
|
+
/** WGS84 lat/lon coordinate */
|
|
3
|
+
export interface LatLon {
|
|
4
|
+
lat: number;
|
|
5
|
+
lon: number;
|
|
6
|
+
}
|
|
7
|
+
/** Address returned by reverse geocoding */
|
|
8
|
+
export interface Address {
|
|
9
|
+
/** Full formatted address string */
|
|
10
|
+
label: string;
|
|
11
|
+
/** Raw distance from the queried point (meters) */
|
|
12
|
+
distance: number;
|
|
13
|
+
/** Easting in EPSG:2169 */
|
|
14
|
+
easting: number;
|
|
15
|
+
/** Northing in EPSG:2169 */
|
|
16
|
+
northing: number;
|
|
17
|
+
}
|
|
18
|
+
/** Search parameters for forward geocoding */
|
|
19
|
+
export interface GeocodeQuery {
|
|
20
|
+
/** Full address as a single string (use this OR individual fields) */
|
|
21
|
+
queryString?: string;
|
|
22
|
+
num?: string;
|
|
23
|
+
street?: string;
|
|
24
|
+
zip?: string;
|
|
25
|
+
locality?: string;
|
|
26
|
+
}
|
|
27
|
+
export type MapClickHandler = (coords: LatLon) => void;
|
|
28
|
+
export type MarkerMode = 'none' | 'fixed' | 'click';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coordinate conversion between EPSG:2169 (Luxembourg TM) and EPSG:4326 (WGS84).
|
|
3
|
+
*
|
|
4
|
+
* The Geoportail API operates internally in EPSG:2169 but also accepts
|
|
5
|
+
* position arrays in EPSG:4326 via `lux.Map` constructor options.
|
|
6
|
+
*
|
|
7
|
+
* For precise server-side conversion the REST API itself is authoritative.
|
|
8
|
+
* The formulas below use a 6-parameter Helmert + transverse Mercator approach
|
|
9
|
+
* sufficient for Luxembourg's territory (~50 km radius).
|
|
10
|
+
*
|
|
11
|
+
* Reference: IGN-L / ACT official parameters for LUREF (EPSG:2169).
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Convert WGS84 (lat/lon) to EPSG:2169 (easting/northing).
|
|
15
|
+
*/
|
|
16
|
+
export declare function latLonToLuref(lat: number, lon: number): {
|
|
17
|
+
easting: number;
|
|
18
|
+
northing: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Convert EPSG:2169 (easting/northing) to WGS84 (lat/lon).
|
|
22
|
+
*/
|
|
23
|
+
export declare function lurefToLatLon(easting: number, northing: number): {
|
|
24
|
+
lat: number;
|
|
25
|
+
lon: number;
|
|
26
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamically injects the Geoportail v3 API script and resolves when
|
|
3
|
+
* the global `lux` namespace is available.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Loads the Geoportail apiv3loader.js script exactly once.
|
|
7
|
+
* Safe to call multiple times — subsequent calls return the same promise.
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadLuxApi(): Promise<void>;
|