Add NDW E7 (laden/lossen) sign layer to BAG map
New toggleable map layer showing E7 "Gelegenheid voor het laden en lossen" traffic signs from NDW's open Verkeersborden API v4, overlaid on the BAG-gebied map (shared across the Webapp and DMI Cockpit views). - New /api/ndw/signs route: reverse-geocodes the area centre to a gemeentecode (NDW filters by municipality), fetches E7 signs, bbox-filters, and returns lean GeoJSON (road name, onderbord time-window, photo URL, bearing, NDW sign id). - Signs are clipped client-side to the drawn polygon grown by a 6 m boundary tolerance, so only signs in the selected area show. - Markers use the official RVV E7 sign artwork; the toolbar legend uses a small E7 sign glyph and shows the live sign count. - Each sign popup deep-links into NDW's public "George" viewer (wegkenmerken.ndw.nu/kaart) centered on the sign, plus the onderbord text and sign photo. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
bf47f0fe5b
commit
f0842756a3
@@ -0,0 +1,184 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import type { Feature, FeatureCollection, Point } from 'geojson';
|
||||
|
||||
// NDW Verkeersborden REST API v4 — open data, no auth.
|
||||
// Returns GeoJSON points in EPSG:4326. Filterable by rvvCode + countyCode (gemeente).
|
||||
// Docs: https://docs.ndw.nu/data-uitwisseling/interface-beschrijvingen/verkeersborden-api/
|
||||
const NDW_URL =
|
||||
'https://data.ndw.nu/api/rest/static-road-data/traffic-signs/v4/current-state';
|
||||
const PDOK_REVERSE_URL =
|
||||
'https://api.pdok.nl/bzk/locatieserver/search/v3_1/reverse';
|
||||
|
||||
const RVV_CODE = 'E7'; // "Gelegenheid voor het onmiddellijk laden en lossen van goederen"
|
||||
const MAX_BBOX_DEG2 = 0.02; // E7 lookups are area-scoped; keep the request tight.
|
||||
const BBOX_PAD_DEG = 0.0004; // ~40 m padding so signs just outside the area still show.
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
export const maxDuration = 30;
|
||||
|
||||
export interface NdwTextSign {
|
||||
type?: string;
|
||||
text?: string;
|
||||
}
|
||||
|
||||
export interface NdwSignProperties {
|
||||
/** Stable NDW sign UUID (GeoJSON feature id). */
|
||||
ndwId: string | null;
|
||||
rvvCode: string;
|
||||
status: string | null;
|
||||
roadName: string | null;
|
||||
/** Onderbord text(s) joined — typically the time window, e.g. "ma t/m za 08.00-18.00". */
|
||||
restriction: string | null;
|
||||
bearing: number | null;
|
||||
placement: string | null;
|
||||
side: string | null;
|
||||
townName: string | null;
|
||||
imageUrl: string | null;
|
||||
validated: boolean;
|
||||
}
|
||||
|
||||
interface NdwRawProperties {
|
||||
rvvCode?: string;
|
||||
status?: string;
|
||||
roadName?: string;
|
||||
textSigns?: NdwTextSign[];
|
||||
bearing?: number;
|
||||
placement?: string;
|
||||
side?: string;
|
||||
townName?: string;
|
||||
imageUrl?: string;
|
||||
validated?: string;
|
||||
}
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const url = new URL(req.url);
|
||||
const minX = parseFloat(url.searchParams.get('minX') ?? '');
|
||||
const minY = parseFloat(url.searchParams.get('minY') ?? '');
|
||||
const maxX = parseFloat(url.searchParams.get('maxX') ?? '');
|
||||
const maxY = parseFloat(url.searchParams.get('maxY') ?? '');
|
||||
|
||||
if ([minX, minY, maxX, maxY].some((v) => Number.isNaN(v))) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Query params minX, minY, maxX, maxY (EPSG:4326) are required.' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
if (minX >= maxX || minY >= maxY) {
|
||||
return NextResponse.json({ error: 'Invalid bbox: min must be < max.' }, { status: 400 });
|
||||
}
|
||||
if ((maxX - minX) * (maxY - minY) > MAX_BBOX_DEG2) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Gebied te groot om laad/loszones op te halen. Zoom verder in.' },
|
||||
{ status: 413 }
|
||||
);
|
||||
}
|
||||
|
||||
// 1. Reverse-geocode the bbox centre to a gemeentecode (NDW filters by municipality).
|
||||
const centerLat = (minY + maxY) / 2;
|
||||
const centerLon = (minX + maxX) / 2;
|
||||
const gemeentecode = await reverseGemeentecode(centerLat, centerLon);
|
||||
if (!gemeentecode) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Geen gemeente gevonden voor dit gebied (alleen Nederland wordt ondersteund).' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
const countyCode = `GM${gemeentecode}`;
|
||||
|
||||
// 2. Fetch all E7 signs for that municipality (cached per gemeente for a day).
|
||||
const params = new URLSearchParams({ rvvCode: RVV_CODE, countyCode });
|
||||
let resp: Response;
|
||||
try {
|
||||
resp = await fetch(`${NDW_URL}?${params.toString()}`, {
|
||||
headers: { Accept: 'application/geo+json' },
|
||||
next: { revalidate: 86400 },
|
||||
});
|
||||
} catch (err) {
|
||||
return NextResponse.json(
|
||||
{ error: `NDW onbereikbaar: ${(err as Error).message}` },
|
||||
{ status: 502 }
|
||||
);
|
||||
}
|
||||
if (!resp.ok) {
|
||||
const text = await resp.text().catch(() => '');
|
||||
return NextResponse.json(
|
||||
{ error: `NDW gaf ${resp.status} terug`, detail: text.slice(0, 300) },
|
||||
{ status: 502 }
|
||||
);
|
||||
}
|
||||
|
||||
const raw = (await resp.json()) as FeatureCollection<Point, NdwRawProperties>;
|
||||
|
||||
// 3. Filter to the requested bbox (padded) and slim down the properties.
|
||||
const padMinX = minX - BBOX_PAD_DEG;
|
||||
const padMinY = minY - BBOX_PAD_DEG;
|
||||
const padMaxX = maxX + BBOX_PAD_DEG;
|
||||
const padMaxY = maxY + BBOX_PAD_DEG;
|
||||
|
||||
const features: Feature<Point, NdwSignProperties>[] = [];
|
||||
for (const f of raw.features ?? []) {
|
||||
if (f.geometry?.type !== 'Point') continue;
|
||||
const [lon, lat] = f.geometry.coordinates;
|
||||
if (lon < padMinX || lon > padMaxX || lat < padMinY || lat > padMaxY) continue;
|
||||
const p = f.properties ?? {};
|
||||
features.push({
|
||||
type: 'Feature',
|
||||
id: typeof f.id === 'string' || typeof f.id === 'number' ? f.id : undefined,
|
||||
geometry: f.geometry,
|
||||
properties: {
|
||||
ndwId: typeof f.id === 'string' ? f.id : null,
|
||||
rvvCode: p.rvvCode ?? RVV_CODE,
|
||||
status: p.status ?? null,
|
||||
roadName: p.roadName ?? null,
|
||||
restriction:
|
||||
(p.textSigns ?? [])
|
||||
.map((t) => t.text?.trim())
|
||||
.filter(Boolean)
|
||||
.join(' · ') || null,
|
||||
bearing: typeof p.bearing === 'number' ? p.bearing : null,
|
||||
placement: p.placement ?? null,
|
||||
side: p.side ?? null,
|
||||
townName: p.townName ?? null,
|
||||
imageUrl: p.imageUrl ?? null,
|
||||
validated: p.validated === 'j',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const out: FeatureCollection<Point, NdwSignProperties> & {
|
||||
countyCode: string;
|
||||
count: number;
|
||||
} = {
|
||||
type: 'FeatureCollection',
|
||||
features,
|
||||
countyCode,
|
||||
count: features.length,
|
||||
};
|
||||
|
||||
return NextResponse.json(out, {
|
||||
headers: { 'Cache-Control': 'public, s-maxage=3600, stale-while-revalidate=86400' },
|
||||
});
|
||||
}
|
||||
|
||||
async function reverseGemeentecode(lat: number, lon: number): Promise<string | null> {
|
||||
const params = new URLSearchParams({
|
||||
lat: lat.toString(),
|
||||
lon: lon.toString(),
|
||||
rows: '1',
|
||||
type: 'adres',
|
||||
fl: 'gemeentecode',
|
||||
});
|
||||
try {
|
||||
const resp = await fetch(`${PDOK_REVERSE_URL}?${params.toString()}`, {
|
||||
headers: { Accept: 'application/json' },
|
||||
next: { revalidate: 86400 },
|
||||
});
|
||||
if (!resp.ok) return null;
|
||||
const data = (await resp.json()) as {
|
||||
response?: { docs?: Array<{ gemeentecode?: string }> };
|
||||
};
|
||||
return data.response?.docs?.[0]?.gemeentecode ?? null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import type {
|
||||
} from 'geojson';
|
||||
import {
|
||||
bbox as turfBbox,
|
||||
booleanPointInPolygon,
|
||||
buffer as turfBuffer,
|
||||
lineString,
|
||||
nearestPointOnLine,
|
||||
@@ -41,6 +42,7 @@ import { DMI, labelMono, bodyText } from '@/lib/dmi-theme';
|
||||
import type { BagGebruiksdoel, BagQueryResult } from '@/lib/bag-types';
|
||||
import type { LocatieserverLookupResult } from '@/app/api/pdok/lookup/route';
|
||||
import type { PdokReverseResult } from '@/app/api/pdok/reverse/route';
|
||||
import type { NdwSignProperties } from '@/app/api/ndw/signs/route';
|
||||
import BagAddressSearch from './BagAddressSearch';
|
||||
import BagResultPanel from './BagResultPanel';
|
||||
|
||||
@@ -71,6 +73,11 @@ const MIN_BUFFER_METERS = 5;
|
||||
const MAX_BUFFER_METERS = 100;
|
||||
|
||||
const ICON_SIZE = 32;
|
||||
const E7_SIGN_BLUE = '#0e518d';
|
||||
// Extra tolerance (m) around the drawn area so E7 signs right on the curb/boundary are kept.
|
||||
const E7_BOUNDARY_PAD_METERS = 6;
|
||||
// Official RVV E7 sign artwork (200×300), © public domain — Wikimedia Commons.
|
||||
const E7_SIGN_INNER = `<rect width="200" height="300" rx="20" fill="#0e518d"/><path style="fill:none;stroke:#f7fbf5;stroke-width:6.72582531" d="M 175.62623,292.09141 C 184.58296,292.09141 191.86981,285.0188 191.86981,276.30711 L 191.86981,23.66005 C 191.86981,14.956562 184.58296,7.875758 175.62623,7.875758 L 24.34006,7.875758 C 15.38333,7.875758 8.10491,14.956562 8.10491,23.66005 L 8.10491,276.30711 C 8.10491,285.0188 15.38333,292.09141 24.34006,292.09141 L 175.62623,292.09141"/><path fill="#f7fbf5" d="M 77.47607,170.15749 L 53.05663,170.15749 L 53.05663,33.296274 L 108.82467,33.296274 C 135.33625,33.296274 150.57539,50.928494 150.57539,74.180604 C 150.57539,94.260854 137.92212,115.927 108.95856,115.927 L 77.47607,115.927 L 77.47607,170.15749 z M 101.50219,93.528884 C 123.53659,93.528884 127.98029,83.110564 127.98029,74.880034 C 127.98029,66.047654 124.42365,55.629344 101.50219,55.629344 L 77.18317,55.629344 L 77.18317,93.528884 L 101.50219,93.528884"/><path fill="#f7fbf5" d="M 42.86373,269.90809 C 47.56687,269.90809 51.39128,266.19132 51.39128,261.58807 C 51.39128,257.00923 47.56687,253.25994 42.86373,253.25994 C 38.11877,253.25994 34.26086,257.00923 34.26086,261.58807 C 34.26086,266.19132 38.11877,269.90809 42.86373,269.90809 z M 104.60692,269.90809 C 109.35189,269.90809 113.17632,266.19132 113.17632,261.58807 C 113.17632,257.00923 109.35189,253.25994 104.60692,253.25994 C 99.87031,253.25994 96.04589,257.00923 96.04589,261.58807 C 96.04589,266.19132 99.87031,269.90809 104.60692,269.90809 z M 125.17682,247.95726 L 140.95991,247.95726 L 140.95991,210.30985 L 125.17682,210.30985 L 125.17682,247.95726 z M 144.75087,266.57358 L 137.3698,258.57074 L 154.62575,243.35401 L 162.0152,251.35684 L 144.75087,266.57358 z M 150.99381,271.75427 C 152.75958,271.75427 154.19896,270.35539 154.19896,268.63934 C 154.19896,266.9233 152.75958,265.52442 150.99381,265.52442 C 149.23641,265.52442 147.79702,266.9233 147.79702,268.63934 C 147.79702,270.35539 149.23641,271.75427 150.99381,271.75427 z M 116.57395,264.92258 L 119.913,264.92258 L 124.9425,272.22598 L 140.73396,272.22598 L 140.73396,270.25779 L 126.02204,270.25779 L 120.99254,262.95441 L 117.15975,262.95441 L 116.57395,264.92258 z M 116.31453,257.87132 C 114.71613,253.10541 110.0716,249.64078 104.60692,249.64078 C 99.15061,249.64078 94.53955,253.07288 92.94115,257.83878 L 54.3956,257.83878 L 54.30355,257.20442 C 52.50431,252.78823 48.06061,249.64078 42.86373,249.64078 C 36.0601,249.64078 30.60381,254.37416 30.60381,260.98624 L 20.21007,260.98624 L 20.33558,257.35895 L 21.64109,257.13936 L 20.69544,237.63656 L 28.47819,219.9718 L 46.88065,219.9718 L 46.88065,210.30985 L 121.57835,210.30985 L 121.93818,257.83878 L 116.31453,257.83878 L 116.31453,257.87132 z M 46.88065,221.80984 L 29.6498,221.93997 L 23.21437,236.58742 L 46.88065,236.58742 L 46.88065,221.80984 z M 166.42542,236.67688 C 165.25383,236.67688 165.47978,238.32785 165.47978,239.37702 L 165.34588,250.62487 L 160.54234,250.97459 L 160.44191,252.24333 L 166.65973,252.02375 L 168.09075,245.07007 C 169.40462,247.03824 170.96954,249.83598 170.96954,249.83598 L 165.34588,260.15667 L 168.32509,270.60751 L 169.89001,270.85963 L 168.35855,261.55553 L 174.79396,253.90244 L 178.55145,259.96962 L 184.46801,269.90809 L 186.50158,269.90809 L 180.15821,256.65952 L 178.61841,250.27515 L 172.86921,241.3533 L 169.04478,236.93713 C 167.4715,235.69278 166.42542,236.67688 166.42542,236.67688 z M 164.5927,235.3756 C 166.35847,235.3756 167.79787,233.97673 167.79787,232.26067 C 167.79787,230.57715 166.35847,229.17828 164.5927,229.17828 C 162.86041,229.17828 161.42939,230.57715 161.42939,232.26067 C 161.42939,233.97673 162.86041,235.3756 164.5927,235.3756"/>`;
|
||||
|
||||
type SourceGeometry = LineString | MultiLineString | Polygon | MultiPolygon;
|
||||
|
||||
@@ -109,6 +116,10 @@ export default function BagPanel({ onApplied, panelHeight = 'calc(100vh - 180px)
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [source, setSource] = useState<SourceInfo | null>(null);
|
||||
const [bufferMeters, setBufferMeters] = useState(DEFAULT_STREET_BUFFER_METERS);
|
||||
const [e7On, setE7On] = useState(false);
|
||||
const [e7Loading, setE7Loading] = useState(false);
|
||||
const [e7Count, setE7Count] = useState<number | null>(null);
|
||||
const [e7Error, setE7Error] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!containerRef.current || mapRef.current) return;
|
||||
@@ -132,10 +143,13 @@ export default function BagPanel({ onApplied, panelHeight = 'calc(100vh - 180px)
|
||||
if (disposed || drawRef.current) return;
|
||||
|
||||
await registerBagIcons(map);
|
||||
await registerE7Icon(map);
|
||||
iconsReadyRef.current = true;
|
||||
ensurePolygonLayer(map);
|
||||
ensureMarkerLayer(map);
|
||||
ensureE7Layer(map);
|
||||
wireIconClickHandlers(map);
|
||||
wireE7ClickHandlers(map);
|
||||
|
||||
draw = new TerraDraw({
|
||||
adapter: new TerraDrawMapLibreGLAdapter({ map }),
|
||||
@@ -459,6 +473,67 @@ export default function BagPanel({ onApplied, panelHeight = 'calc(100vh - 180px)
|
||||
[simulation, onApplied]
|
||||
);
|
||||
|
||||
const loadE7 = useCallback(async () => {
|
||||
const map = mapRef.current;
|
||||
if (!map) return;
|
||||
let minX: number, minY: number, maxX: number, maxY: number;
|
||||
if (bag.polygon) {
|
||||
[minX, minY, maxX, maxY] = turfBbox(bag.polygon);
|
||||
} else {
|
||||
const b = map.getBounds();
|
||||
[minX, minY, maxX, maxY] = [b.getWest(), b.getSouth(), b.getEast(), b.getNorth()];
|
||||
}
|
||||
setE7Loading(true);
|
||||
setE7Error(null);
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
minX: String(minX),
|
||||
minY: String(minY),
|
||||
maxX: String(maxX),
|
||||
maxY: String(maxY),
|
||||
});
|
||||
const resp = await fetch(`/api/ndw/signs?${params.toString()}`);
|
||||
if (!resp.ok) {
|
||||
const { error: msg } = await resp
|
||||
.json()
|
||||
.catch(() => ({ error: `NDW ${resp.status}` }));
|
||||
setE7Error(msg ?? 'Laad/loszones konden niet worden geladen.');
|
||||
setE7Count(null);
|
||||
updateE7(map, { type: 'FeatureCollection', features: [] });
|
||||
return;
|
||||
}
|
||||
const fc = (await resp.json()) as FeatureCollection<GeoJSON.Point, NdwSignProperties>;
|
||||
const clipped = bag.polygon ? clipToPolygon(fc, bag.polygon) : fc;
|
||||
updateE7(map, clipped);
|
||||
setE7Count(clipped.features.length);
|
||||
} catch (err) {
|
||||
setE7Error(`NDW-query mislukt: ${(err as Error).message}`);
|
||||
setE7Count(null);
|
||||
} finally {
|
||||
setE7Loading(false);
|
||||
}
|
||||
}, [bag.polygon]);
|
||||
|
||||
const handleToggleE7 = useCallback(() => {
|
||||
const map = mapRef.current;
|
||||
if (!map) return;
|
||||
const next = !e7On;
|
||||
setE7On(next);
|
||||
setE7Visibility(map, next);
|
||||
if (next) {
|
||||
loadE7();
|
||||
} else {
|
||||
setE7Error(null);
|
||||
}
|
||||
}, [e7On, loadE7]);
|
||||
|
||||
// Refresh E7 signs when the selected area changes while the layer is on.
|
||||
useEffect(() => {
|
||||
if (!mapReady || !e7On) return;
|
||||
loadE7();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [bag.polygon, mapReady]);
|
||||
|
||||
const modeLabel =
|
||||
mode === 'polygon'
|
||||
? 'Klik punten, dubbelklik om te sluiten'
|
||||
@@ -621,6 +696,24 @@ export default function BagPanel({ onApplied, panelHeight = 'calc(100vh - 180px)
|
||||
icon={<Eraser size={14} />}
|
||||
label="Wissen"
|
||||
/>
|
||||
<div style={{ height: 1, backgroundColor: DMI.blueTint2, margin: '2px 0' }} />
|
||||
<ToolButton
|
||||
active={e7On}
|
||||
disabled={e7Loading}
|
||||
onClick={handleToggleE7}
|
||||
icon={
|
||||
e7Loading ? (
|
||||
<Loader2 size={14} className="animate-spin" />
|
||||
) : (
|
||||
<E7SignGlyph height={18} />
|
||||
)
|
||||
}
|
||||
label={
|
||||
e7On && e7Count !== null
|
||||
? `Laden/lossen · ${e7Count}`
|
||||
: 'Laden/lossen (E7)'
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
@@ -660,6 +753,27 @@ export default function BagPanel({ onApplied, panelHeight = 'calc(100vh - 180px)
|
||||
{info}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{e7Error && (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
bottom: info ? 70 : 38,
|
||||
left: 10,
|
||||
right: 10,
|
||||
backgroundColor: '#fdecec',
|
||||
color: '#a11',
|
||||
padding: '6px 10px',
|
||||
borderRadius: 4,
|
||||
fontSize: 12,
|
||||
...bodyText,
|
||||
boxShadow: '0 2px 6px rgba(0,0,0,0.12)',
|
||||
zIndex: 10,
|
||||
}}
|
||||
>
|
||||
{e7Error}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div
|
||||
@@ -686,6 +800,19 @@ export default function BagPanel({ onApplied, panelHeight = 'calc(100vh - 180px)
|
||||
);
|
||||
}
|
||||
|
||||
function E7SignGlyph({ height = 18 }: { height?: number }) {
|
||||
return (
|
||||
<svg
|
||||
width={(height * 2) / 3}
|
||||
height={height}
|
||||
viewBox="0 0 200 300"
|
||||
style={{ display: 'block', flexShrink: 0 }}
|
||||
aria-hidden
|
||||
dangerouslySetInnerHTML={{ __html: E7_SIGN_INNER }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function ToolButton({
|
||||
active,
|
||||
disabled,
|
||||
@@ -940,3 +1067,157 @@ function updatePolygonHighlight(map: MaplibreMap, polygon: BagPolygonFeature | n
|
||||
: { type: 'FeatureCollection', features: [] };
|
||||
(src as maplibregl.GeoJSONSource).setData(data);
|
||||
}
|
||||
|
||||
// ── NDW E7 (laden/lossen) sign layer ──────────────────────────────────────────
|
||||
|
||||
const E7_ICON_W = 40;
|
||||
const E7_ICON_H = 60; // RVV E7 is a 2:3 portrait sign.
|
||||
|
||||
async function registerE7Icon(map: MaplibreMap) {
|
||||
const imageName = 'ndw-e7';
|
||||
if (map.hasImage(imageName)) return;
|
||||
// Render at 2× for a crisp marker on retina.
|
||||
const scale = 2;
|
||||
const w = E7_ICON_W * scale;
|
||||
const h = E7_ICON_H * scale;
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 200 300">${E7_SIGN_INNER}</svg>`;
|
||||
const blob = new Blob([svg], { type: 'image/svg+xml' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
try {
|
||||
const img = await loadImage(url);
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
ctx.drawImage(img, 0, 0, w, h);
|
||||
map.addImage(imageName, ctx.getImageData(0, 0, w, h), { pixelRatio: scale });
|
||||
} finally {
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
}
|
||||
|
||||
function ensureE7Layer(map: MaplibreMap) {
|
||||
if (!map.getSource('ndw-e7')) {
|
||||
map.addSource('ndw-e7', {
|
||||
type: 'geojson',
|
||||
data: { type: 'FeatureCollection', features: [] },
|
||||
});
|
||||
}
|
||||
if (!map.getLayer('ndw-e7-icons')) {
|
||||
map.addLayer({
|
||||
id: 'ndw-e7-icons',
|
||||
source: 'ndw-e7',
|
||||
type: 'symbol',
|
||||
layout: {
|
||||
'icon-image': 'ndw-e7',
|
||||
'icon-size': 0.48,
|
||||
'icon-anchor': 'bottom',
|
||||
'icon-allow-overlap': true,
|
||||
'icon-ignore-placement': true,
|
||||
visibility: 'none',
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function updateE7(map: MaplibreMap, fc: FeatureCollection) {
|
||||
const src = map.getSource('ndw-e7');
|
||||
if (src && 'setData' in src) {
|
||||
(src as maplibregl.GeoJSONSource).setData(fc);
|
||||
}
|
||||
}
|
||||
|
||||
// Keep only signs inside the drawn polygon, grown by a small boundary tolerance.
|
||||
function clipToPolygon(
|
||||
fc: FeatureCollection<GeoJSON.Point, NdwSignProperties>,
|
||||
polygon: BagPolygonFeature
|
||||
): FeatureCollection<GeoJSON.Point, NdwSignProperties> {
|
||||
let area: Feature<Polygon | MultiPolygon> = polygon;
|
||||
try {
|
||||
const buffered = turfBuffer(polygon, E7_BOUNDARY_PAD_METERS, { units: 'meters' });
|
||||
if (buffered?.geometry) area = buffered as Feature<Polygon | MultiPolygon>;
|
||||
} catch {
|
||||
// fall back to the raw polygon
|
||||
}
|
||||
const features = fc.features.filter((f) => booleanPointInPolygon(f.geometry, area));
|
||||
return { type: 'FeatureCollection', features };
|
||||
}
|
||||
|
||||
function setE7Visibility(map: MaplibreMap, on: boolean) {
|
||||
if (map.getLayer('ndw-e7-icons')) {
|
||||
map.setLayoutProperty('ndw-e7-icons', 'visibility', on ? 'visible' : 'none');
|
||||
}
|
||||
}
|
||||
|
||||
function wireE7ClickHandlers(map: MaplibreMap) {
|
||||
let activePopup: maplibregl.Popup | null = null;
|
||||
map.on('click', 'ndw-e7-icons', (e) => {
|
||||
const feat = e.features?.[0];
|
||||
if (!feat || feat.geometry.type !== 'Point') return;
|
||||
const coords = feat.geometry.coordinates as [number, number];
|
||||
const p = feat.properties as Record<string, unknown>;
|
||||
if (activePopup) activePopup.remove();
|
||||
activePopup = new maplibregl.Popup({ closeButton: true, maxWidth: '280px', offset: 12 })
|
||||
.setLngLat(coords)
|
||||
.setHTML(buildE7PopupHtml(p, coords))
|
||||
.addTo(map);
|
||||
});
|
||||
map.on('mouseenter', 'ndw-e7-icons', () => {
|
||||
map.getCanvas().style.cursor = 'pointer';
|
||||
});
|
||||
map.on('mouseleave', 'ndw-e7-icons', () => {
|
||||
map.getCanvas().style.cursor = '';
|
||||
});
|
||||
}
|
||||
|
||||
// Deep-link into NDW's public "George" sign viewer, centered on a small bbox
|
||||
// around the sign (the viewer has no center/zoom or sign-id param — bbox only).
|
||||
function georgeViewerUrl(lon: number, lat: number): string {
|
||||
const dLon = 0.003;
|
||||
const dLat = 0.0015;
|
||||
const bbox = [lon - dLon, lat - dLat, lon + dLon, lat + dLat]
|
||||
.map((n) => n.toFixed(5))
|
||||
.join(',');
|
||||
return `https://wegkenmerken.ndw.nu/kaart?kaartlagen=BRT,TRAFFIC_SIGN&zichtbaar-gebied=${bbox}`;
|
||||
}
|
||||
|
||||
function buildE7PopupHtml(p: Record<string, unknown>, coords: [number, number]): string {
|
||||
const str = (v: unknown) => (typeof v === 'string' && v.trim() ? v : null);
|
||||
const roadName = str(p.roadName);
|
||||
const restriction = str(p.restriction);
|
||||
const status = str(p.status);
|
||||
const town = str(p.townName);
|
||||
const imageUrl = str(p.imageUrl);
|
||||
const validated = p.validated === true || p.validated === 'true';
|
||||
|
||||
const restrictionBlock = restriction
|
||||
? `<div style="margin-top:6px; padding:6px 8px; background:#eef3fe; border-left:2px solid ${E7_SIGN_BLUE}; border-radius:3px; font-size:11px; color:#0a3660;">${escapeHtml(restriction)}<div style="font-size:9px; color:#888; margin-top:2px;">onderbord</div></div>`
|
||||
: `<div style="margin-top:6px; font-size:11px; color:#888;"><em>Geen tijdvenster op onderbord — doorgaans permanent.</em></div>`;
|
||||
|
||||
const imageBlock = imageUrl
|
||||
? `<img src="${escapeHtml(imageUrl)}" alt="Bordfoto" style="margin-top:8px; width:100%; max-height:130px; object-fit:cover; border-radius:4px;" loading="lazy" />`
|
||||
: '';
|
||||
|
||||
const meta = [town, status ? status.toLowerCase() : null, validated ? 'gevalideerd' : null]
|
||||
.filter(Boolean)
|
||||
.join(' · ');
|
||||
|
||||
return `
|
||||
<div style="font-family: var(--font-ibm-plex-sans), system-ui, sans-serif; padding: 4px 2px;">
|
||||
<div style="display:flex; align-items:center; gap:8px; margin-bottom:4px; padding-bottom:6px; border-bottom:1px solid #daebfb;">
|
||||
<span style="display:inline-flex; align-items:center; justify-content:center; width:20px; height:20px; border-radius:3px; background:${E7_SIGN_BLUE}; color:#fff; font-size:10px; font-weight:700;">E7</span>
|
||||
<strong style="font-size:13px; color:${E7_SIGN_BLUE};">Laden en lossen</strong>
|
||||
</div>
|
||||
${roadName ? `<div style="font-size:12px; color:#0a3660;">${escapeHtml(roadName)}</div>` : ''}
|
||||
${meta ? `<div style="font-size:10px; color:#565656; margin-top:2px; font-family: var(--font-ibm-plex-mono), ui-monospace, monospace;">${escapeHtml(meta)}</div>` : ''}
|
||||
${restrictionBlock}
|
||||
${imageBlock}
|
||||
<a href="${georgeViewerUrl(coords[0], coords[1])}" target="_blank" rel="noopener noreferrer"
|
||||
style="display:inline-flex; align-items:center; gap:4px; margin-top:8px; padding:5px 9px; background:${E7_SIGN_BLUE}; color:#fff; border-radius:4px; font-size:11px; font-weight:600; text-decoration:none;">
|
||||
Bekijk in NDW George ↗
|
||||
</a>
|
||||
<div style="font-size:9px; color:#999; margin-top:6px;">via NDW Verkeersborden</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user